How to get final Value in range Slider? - ios

I'm using TT range slider(Double Slider) for filtering price in my app everything is working perfect but when my final price is some(for example 20) with out selection slider I'm clicking on apply button final price is not coming and the slider option is coming to 0 value if any Answers it would be Appreciated. Thanks in Advance.
My code
float price = [_filterpriceStr floatValue];
NSLog(#"%f",price);
if ([[GlobalVariables appVars].Apply isEqualToString:#"Apply"]) {
float minimum = [[[NSUserDefaults standardUserDefaults]valueForKey:#"filtermin"] floatValue];
float maxmum = [[[NSUserDefaults standardUserDefaults]valueForKey:#"filtermax"] floatValue];
minValue = [[NSUserDefaults standardUserDefaults]valueForKey:#"filtermin"];
maxValue = [[NSUserDefaults standardUserDefaults]valueForKey:#"filtermax"];
//standard range slider
self.rangeSlider.delegate = self;
self.rangeSlider.minValue = 0;
self.rangeSlider.maxValue = price;
self.rangeSlider.step = price;
self.rangeSlider.selectedMinimum = minimum;
self.rangeSlider.selectedMaximum = maxmum;
NSNumberFormatter *customFormatter = [[NSNumberFormatter alloc] init];
customFormatter.positivePrefix = #"£";
self.rangeSlider.numberFormatterOverride = customFormatter;
self.rangeSlider.tintColorBetweenHandles = [UIColor colorWithRed:15.0f/255.0f green:201.0f/255.0f blue:218.0f/255.0f alpha:1.0f];
}
else
{
float price = [_filterpriceStr floatValue];
//standard rsnge slider
self.rangeSlider.delegate = self;
self.rangeSlider.minValue = 0;
self.rangeSlider.maxValue = price;
self.rangeSlider.selectedMinimum = 0;
self.rangeSlider.selectedMaximum = price;
NSNumberFormatter *customFormatter = [[NSNumberFormatter alloc] init];
customFormatter.positivePrefix = #"£";
self.rangeSlider.numberFormatterOverride = customFormatter;
self.rangeSlider.tintColorBetweenHandles = [UIColor colorWithRed:15.0f/255.0f green:201.0f/255.0f blue:218.0f/255.0f alpha:1.0f];
}
when Apply Button Click
[GlobalVariables appVars].PriceRange = #"PriceRange";
[[NSUserDefaults standardUserDefaults]setValue:minValue forKey:#"filtermin"];
[[NSUserDefaults standardUserDefaults]setValue:maxValue forKey:#"filtermax"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSLog(#"%#",maxValue);
[self.navigationController popViewControllerAnimated:NO];

Add this delegate method with which you will get your min and max slider value.
-(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum{
NSLog(#" Min Value: %.0f Max Value: %.0f", selectedMinimum, selectedMaximum);
[[NSUserDefaults standardUserDefaults]setValue:selectedMinimum forKey:#"filtermin"];
[[NSUserDefaults standardUserDefaults]setValue:selectedMaximum forKey:#"filtermax"];
}

Related

Showing duplicate labels on X-Axis

I am using the Charts framework (danielgindi/Charts). My line chart is showing duplicated labels on x-axis, if is there is only one value available on my labels array(xAxisLabels in this case). See image below.
how can I ensure that the labels won't be duplicated? So if there is only one entry available on the labels array then it should display only one label on the left most side. other labels would be blank, which will be gradually filled upon availability on the labels array.
Here is the code that I have tried so far. Thank you very much for your help.
#property (nonatomic) LineChartView* chartView;
#property (strong, nonatomic) NSArray<NSString *> *xAxisLabels;
- (void)configureChartViewIfNeeded {
self.chartView.drawGridBackgroundEnabled = NO;
self.chartView.legend.enabled = NO;
self.chartView.minOffset = 28;
self.chartView.xAxis.enabled = YES;
self.chartView.xAxis.labelPosition = XAxisLabelPositionBottom;
self.chartView.xAxis.labelTextColor = [UIColor colorWithWhite:1 alpha:0.79];
self.chartView.xAxis.gridColor = [UIColor colorWithWhite:1 alpha:0.79];
self.chartView.xAxis.drawAxisLineEnabled = NO;
self.chartView.xAxis.drawGridLinesEnabled = NO;
self.chartView.leftAxis.labelTextColor = [UIColor colorWithWhite:1 alpha:0.79];
self.chartView.leftAxis.gridColor = [UIColor colorWithWhite:1 alpha:0.3];
self.chartView.leftAxis.gridLineWidth = 1.0f;
self.chartView.leftAxis.drawZeroLineEnabled = NO;
self.chartView.leftAxis.drawAxisLineEnabled = NO;
[self.chartView.leftAxis setLabelCount:leftAxisLabelCount force:NO];
self.chartView.leftAxis.drawTopYLabelEntryEnabled = YES;
self.chartView.leftAxis.axisMinimum = 0;
JVNImpactMetricsFormatter *numberFormatter = [[JVNImpactMetricsFormatter alloc] init]; //My custom formatter
[numberFormatter setUsesGroupingSeparator:YES];
[numberFormatter setGroupingSeparator:#","];
[numberFormatter setGroupingSize:3];
numberFormatter.maximumFractionDigits = 1;
self.chartView.xAxis.valueFormatter = numberFormatter; //Will present integer values
self.chartView.rightAxis.enabled = NO;
self.chartView.dragEnabled = NO;
self.chartView.scaleXEnabled = self.chartView.scaleYEnabled = NO;
self.chartView.drawBordersEnabled = NO;
self.chartView.doubleTapToZoomEnabled = NO;
self.chartView.delegate = self;
self.chartView.descriptionText = #"";
[self.chartView animateWithXAxisDuration:0.3 yAxisDuration:0.3];
}
#pragma mark - IChartAxisValueFormatter
- (NSString * _Nonnull)stringForValue:(double)value axis:(ChartAxisBase * _Nullable)axis {
return self.xAxisLabels[[#(value) intValue]];
}
Try using :
self.chartView.xAxis.granularityEnabled = true

IOS charts with different X,Y values in iOS?

I had an iPhone application in which i have to calculate the values for x axis and y axis with some intervals as xaxis array and Yaxis array
I had fixed values.
Then i need to draw 3 line graph with their on x values and Y
values.then i need to plot scatter points on that graph itself with
different (x,y) coordinates.
I am using IOs charts library.But when giving different x values to
the line graph the X axis values are also changing, I am trying in
this way
` chartview.descriptionText = #"";
chartview.noDataTextDescription = #"You need to provide data for the chart.";
chartview.drawGridBackgroundEnabled = NO;
chartview.drawBarShadowEnabled = NO;
chartview.highlightFullBarEnabled = NO;
chartview.rightAxis.enabled=NO;
chartview.drawOrder = #[#(CombinedChartDrawOrderLine),
#(CombinedChartDrawOrderScatter),
];
ChartLegend *l = chartview.legend;
l.enabled = false;
//chartview.xAxisRenderer
ChartYAxis *leftAxis = chartview.leftAxis;
leftAxis.axisLineWidth=2.0f;
leftAxis.axisLineColor =[UIColor whiteColor];
leftAxis.drawGridLinesEnabled = YES;
leftAxis.gridColor=[UIColor whiteColor];
leftAxis.gridLineDashLengths = #[#5.f, #5.f];
NSLog(#"%#",yaxispoints);
NSLog(#"%f",[[yaxispoints firstObject] floatValue]);
NSLog(#"%f",[[yaxispoints lastObject] floatValue]);
leftAxis.axisMinimum = [[yaxispoints firstObject] floatValue]; // this replaces startAtZero = YES
leftAxis.axisMaximum = [[yaxispoints lastObject] floatValue];
leftAxis.labelCount = [yaxispoints count];
leftAxis.spaceTop = 40.0;
leftAxis.labelTextColor=[UIColor whiteColor];
ChartXAxis *xAxis = chartview.xAxis;
[xAxis setDrawAxisLineEnabled:YES];
xAxis.axisLineWidth=2.0f;
xAxis.granularityEnabled=YES;
xAxis.axisLineColor =[UIColor whiteColor];
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.axisMinimum = [[months firstObject] floatValue]; // this replaces startAtZero = YES
xAxis.axisMaximum = [[months lastObject] floatValue];
xAxis.labelCount = [months count];
xAxis.forceLabelsEnabled=YES;
xAxis.drawGridLinesEnabled = YES;
xAxis.gridColor=[UIColor whiteColor];
xAxis.gridLineDashLengths = #[#5.f, #5.f];
xAxis.valueFormatter = self;
xAxis.labelTextColor=[UIColor whiteColor];
[self updateChartData];
[chartview animateWithXAxisDuration:1.5 yAxisDuration:1.5];`
- (void)updateChartData
{
[self setChartData];
}
- (void)setChartData
{
CombinedChartData *data = [[CombinedChartData alloc] init];
data.lineData = [self generateLineData];
data.scatterData = [self generateScatterData];
chartview.xAxis.axisMaximum = data.xMax + 5.0;
chartview.data = data;
}
- (LineChartData *)generateLineData
{
LineChartData *d = [[LineChartData alloc] init];
NSMutableArray *entries = [[NSMutableArray alloc] init];
NSArray *scxaxis = #[#"55.987", #"75.976", #"85.976"
];
NSArray *scyaxis = #[#"85.987", #"25.976", #"95.976"
];
for (int index = 0; index < [scxaxis count]; index++)
{
[entries addObject:[[ChartDataEntry alloc] initWithX:[[scxaxis objectAtIndex:index] doubleValue] y:[[scyaxis objectAtIndex:index] doubleValue]]];
}
LineChartDataSet *set = [[LineChartDataSet alloc] initWithValues:entries label:#"Line DataSet"];
[set setColor:[UIColor greenColor]];
set.lineWidth = 3.0;
// [set setCircleColor:[UIColor redColor]];
//set.circleRadius = 0.0;
// set.circleHoleRadius = 0.0;
set .drawCirclesEnabled=NO;
set.fillColor = [UIColor clearColor];
set.mode = LineChartModeLinear;
set.drawValuesEnabled = NO;
set.valueFont = [UIFont systemFontOfSize:14.f];
set.valueTextColor = [UIColor whiteColor];
set.axisDependency = AxisDependencyLeft;
[d addDataSet:set];
return d;
}
I am trying like this,But when giving different x values to each data set in line graph the x axis is completely going wrong according to it. i want the x axis to be fetched from different array and x,y points of line graph to be from different array, Can anybody help me on achieving this ?
Maybe the problem is
chartview.xAxis.axisMaximum = data.xMax + 5.0;
Cause you are using CombinedChartData,if the you should call calcMinMax() at first.
And accord to your code ,the x axis should be in [0,90.976].What your graph shows?

Objective C - Convert DMS to LAT LONG (South and East)

Heads up, I'm an absolute newb when it comes to OBJ-C!
I'm currently putting together and IOS app and utilising pre-loaded data listings/locations from my client. The coordinates to each listing/location has are in DMS, eg
S:35 00.065
E:148 06.660
There are thousands of listings and I can't go and change this over for each one. I'm currently importing that data via a WordPress JSON API (WP REST API Plugin). The app I'm making pulls that JSON data in and populates accordingly.
The format is simply 'east' and south' from the JSON URL.
http://example.com/api/get_recent_posts/?custom_fields=name,east,south,image,address,type,Postend&page=%ld
I have no idea how to convert the east and south into lat and long for the code. Everything is ready to go except this predicament!
Everything I find on here leads to expired or dead links for their respective tutorials, in Javascript, PHP, or is reversing LAT LONG to DMS. :(
Thanks in advance!
--- EDIT WITH POSSIBLE ANSWER ---
Thanks to #ronak-chaniyara for the answer. Just having troubles implementing into current code. Existing code from template below:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *decodedText1 = [_restaurant.name stringByReplacingOccurrencesOfString:#"’" withString:#"'"];
NSString *decodedText = [decodedText1
stringByReplacingOccurrencesOfString:#"&" withString:#"&"];
self.title = _restaurant.type;
self.barname.text = decodedText;
self.address.text = _restaurant.location;
[[self navigationController] setNavigationBarHidden:NO animated:NO];
[self loadImageInNewThread];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"ht7" ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSString *htmlString2 = [NSString stringWithFormat:htmlString,_restaurant.description];
self.webView.delegate=self;
[self.webView loadHTMLString:htmlString2 baseURL:nil];
_webView.opaque = NO;
_webView.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.306 green:0.306 blue:0.306 alpha:1];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;
self.EntityPlot.delegate = self;
CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake(_restaurant.lattitude, _restaurant.longditude);
EntityPlot *coordinate2 = [[EntityPlot alloc] initWithTitle:decodedText Location:coordinate1];
[self.EntityPlot addAnnotation: coordinate2];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = _restaurant.lattitude;
annotationCoord.longitude = _restaurant.longditude;
UIImage *image = [UIImage imageNamed:#"cream_pixels_#2X.png"];
self.uiView.backgroundColor = [UIColor colorWithPatternImage:image];
[_barplot setRegion:MKCoordinateRegionMake(annotationCoord, MKCoordinateSpanMake(.005, .005)) animated:YES];
[_barplot selectAnnotation:coordinate2 animated:YES];
_barplot.showsUserLocation = YES;
Me trying to implement:
//Pass string DMS for Lat and Long
- (double)DMSStringToDecimal:(NSString*)strDMS
{
// split the string
NSArray *arrSplit = [strDMS componentsSeparatedByString:#":"];
//direction
NSString *direction = [arrSplit objectAtIndex:0];
//degree
NSString *degreesString = [[[arrSplit objectAtIndex:1] componentsSeparatedByString:#" "] objectAtIndex:0];
NSArray *arrMinuteandSeconds=[[[[arrSplit objectAtIndex:1] componentsSeparatedByString:#" "] objectAtIndex:1] componentsSeparatedByString:#"."];
//minutes
NSString *minutesString = [arrMinuteandSeconds objectAtIndex:0];
//seconds
NSString *secondsString = [arrMinuteandSeconds objectAtIndex:1];
// convert degrees
double degrees = [degreesString doubleValue];
// convert minutes
double minutes = [minutesString doubleValue] / 60; // 60 degrees in a minute
// convert seconds
double seconds = [secondsString doubleValue] / 3600; // 60 seconds in a minute, or 3600 in a degree
// add them all together
double decimal = degrees + minutes + seconds;
// determine if this is negative. south and west would be negative values
if ([direction.uppercaseString isEqualToString:#"W"] || [direction.uppercaseString isEqualToString:#"S"])
{
decimal = -decimal;
}
return decimal;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *decodedText1 = [_restaurant.name stringByReplacingOccurrencesOfString:#"’" withString:#"'"];
NSString *decodedText = [decodedText1
stringByReplacingOccurrencesOfString:#"&" withString:#"&"];
self.title = _restaurant.type;
self.barname.text = decodedText;
self.address.text = _restaurant.location;
[[self navigationController] setNavigationBarHidden:NO animated:NO];
[self loadImageInNewThread];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"ht7" ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSString *htmlString2 = [NSString stringWithFormat:htmlString,_restaurant.description];
self.webView.delegate=self;
[self.webView loadHTMLString:htmlString2 baseURL:nil];
_webView.opaque = NO;
_webView.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.306 green:0.306 blue:0.306 alpha:1];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;
self.EntityPlot.delegate = self;
// location crap
NSString *latStr = [NSString stringWithFormat:htmlString,_restaurant.lattitude];
NSString *lonStr = [NSString stringWithFormat:htmlString,_restaurant.longditude];
double lat = [self DMSStringToDecimal:latStr]; //which gives lat=-35.018055555555556
double lon = [self DMSStringToDecimal:lonStr]; //which gives lon=148.28333333333333
// CLLocation *loc = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake(lat, lon);
EntityPlot *coordinate2 = [[EntityPlot alloc] initWithTitle:decodedText Location:coordinate1];
// CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake(_restaurant.lattitude, _restaurant.longditude);
// EntityPlot *coordinate2 = [[EntityPlot alloc] initWithTitle:decodedText Location:coordinate1];
[self.EntityPlot addAnnotation: coordinate2];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = lat;
annotationCoord.longitude = lon;
// annotationCoord.latitude = _restaurant.lattitude;
// annotationCoord.longitude = _restaurant.longditude;
UIImage *image = [UIImage imageNamed:#"cream_pixels_#2X.png"];
self.uiView.backgroundColor = [UIColor colorWithPatternImage:image];
[_barplot setRegion:MKCoordinateRegionMake(annotationCoord, MKCoordinateSpanMake(.005, .005)) animated:YES];
[_barplot selectAnnotation:coordinate2 animated:YES];
_barplot.showsUserLocation = YES;
}
May be you can do something like below, (from answer: https://stackoverflow.com/a/28545279/5575752):
NSString *latStr=#"S:35 00.065";
NSString *lonStr=#"E:148 06.660";
double lat = [self DMSStringToDecimal:latStr]; //which gives lat=-35.018055555555556
double lon = [self DMSStringToDecimal:lonStr]; //which gives lon=148.28333333333333
// Now create Location object
CLLocation *loc = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
//Pass string DMS for Lat and Long
- (double)DMSStringToDecimal:(NSString*)strDMS
{
// split the string
NSArray *arrSplit = [strDMS componentsSeparatedByString:#":"];
//direction
NSString *direction = [arrSplit objectAtIndex:0];
//degree
NSString *degreesString = [[[arrSplit objectAtIndex:1] componentsSeparatedByString:#" "] objectAtIndex:0];
NSArray *arrMinuteandSeconds=[[[[arrSplit objectAtIndex:1] componentsSeparatedByString:#" "] objectAtIndex:1] componentsSeparatedByString:#"."];
//minutes
NSString *minutesString = [arrMinuteandSeconds objectAtIndex:0];
//seconds
NSString *secondsString = [arrMinuteandSeconds objectAtIndex:1];
// convert degrees
double degrees = [degreesString doubleValue];
// convert minutes
double minutes = [minutesString doubleValue] / 60; // 60 degrees in a minute
// convert seconds
double seconds = [secondsString doubleValue] / 3600; // 60 seconds in a minute, or 3600 in a degree
// add them all together
double decimal = degrees + minutes + seconds;
// determine if this is negative. south and west would be negative values
if ([direction.uppercaseString isEqualToString:#"W"] || [direction.uppercaseString isEqualToString:#"S"])
{
decimal = -decimal;
}
return decimal;
}
Do modifications as per your requirement.
Hope it will help:)

ios-charts radar chart turn auto scaling OFF

These two radar charts have the same data points for the orange bit, but different for the gray. However, as you can see it is autoscaling, and the orange bit ends up bigger on the second chart, even though they are the same exact data points. Is there a way to turn autoscaling off? I would like 100% to go right to the edge of the chart also.
-(void)setupRadarChart
{
self.radarChart.descriptionText = #"";
self.radarChart.webLineWidth = .75;
self.radarChart.innerWebLineWidth = 0.375;
self.radarChart.webAlpha = 1.0;
self.radarChart.userInteractionEnabled = NO;
self.radarChart.xAxis.enabled = YES;
ChartYAxis *yAxis = self.radarChart.yAxis;
yAxis.enabled = NO;
ChartLegend *l = self.radarChart.legend;
l.position = ChartLegendPositionBelowChartLeft;
l.font = [UIFont systemFontOfSize:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 12 : (headerWidth/40)];
[self setRadarData];
}
- (void)setRadarData
{
NSMutableArray *parties = [[NSMutableArray alloc] init];
for (PillarModel *m in [DataManager sharedData].pillars)
{
[parties addObject:m.abbreviation];
}
NSMutableArray *yVals2 = [[NSMutableArray alloc] init];
NSMutableArray *benchMark = [[NSMutableArray alloc] init];
BOOL shouldAdd = YES;
for (PillarModel *pillar in [DataManager sharedData].pillars)
{ int totalPillarScore = (int)[[DataManager sharedData] getTotalScorePossible:[[DataManager sharedData] getIndividualQuestionResultsForPillar:pillar.pillarId]];
if ((isCompany ? [[DataManager sharedData] getCompanyScoresForCategory:pillar] : [[DataManager sharedData] getIndividualScoreForCategory:pillar.pillarId]) != 0)
{
shouldAdd = NO;
}
if (pillar.pillarId == numberOfPillars -1 && shouldAdd) {
[yVals2 addObject:[[ChartDataEntry alloc] initWithValue:0.01 xIndex:pillar.pillarId]];
}
else{
double val = (isCompany ? (double)[[DataManager sharedData] getCompanyScoresForCategory:pillar]/totalPillarScore : (double)[[DataManager sharedData] getIndividualScoreForCategory:pillar.pillarId] / totalPillarScore);
[yVals2 addObject:[[ChartDataEntry alloc] initWithValue:val xIndex:pillar.pillarId]];
}
float pillarBenchMark = [[[[[DataManager sharedData].benchmarkJSONDict objectForKey:hightlightedView.lowercaseString] objectForKey:pillar.title] objectForKey:#"pillar"] intValue];
float ifNoBenchMarkThanCompanyScore = (pillarBenchMark ? pillarBenchMark : (isCompany ? [[DataManager sharedData] getIndividualScoreForCategory:pillar.pillarId]: [[DataManager sharedData] getCompanyScoresForCategory:pillar]));
[benchMark addObject:[[ChartDataEntry alloc] initWithValue:ifNoBenchMarkThanCompanyScore/totalPillarScore xIndex:pillar.pillarId]];
}
NSMutableArray *xVals = [[NSMutableArray alloc] init];
for (int i = 0; i < numberOfPillars; i++)
{
[xVals addObject:parties[i % parties.count]];
}
NSString *label = (isCompany ? #"Company score" : #"Your score");
RadarChartDataSet *set2 = [[RadarChartDataSet alloc] initWithYVals:yVals2 label:label];
[set2 setColor:[DataManager sharedData].mainColor];
set2.drawFilledEnabled = YES;
set2.fillAlpha = 1.0f;
set2.lineWidth = 2.0;
RadarChartDataSet *benchMarkSet = [[RadarChartDataSet alloc] initWithYVals:benchMark label:#"Benchmark"];
[benchMarkSet setColor:[UIColor colorWithRed:125/255.0f green:125/255.0f blue:125/255.0f alpha:0.6f]];
benchMarkSet.drawFilledEnabled = YES;
benchMarkSet.fillAlpha = 0.0f;
benchMarkSet.lineWidth = 2.0;
benchMarkSet.highlightLineDashLengths = #[[NSNumber numberWithInt:2]];
benchMarkSet.highlightLineDashPhase = 2;
RadarChartData *data = [[RadarChartData alloc] initWithXVals:xVals dataSets:#[set2, benchMarkSet]];
[data setValueFont:[UIFont fontWithName:#"HelveticaNeue-Light" size:8.f]];
[data setDrawValues:NO];
self.radarChart.data = data;
}
The answer that was posted by 孙博弘 wasn't correct, but it led me to realise how easy this was to solve. This solves both the autoscaling problem and also now reaches the edge.
self.radarChart.yAxis.customAxisMin = 0;
self.radarChart.yAxis.customAxisMax = 1;
i'm afraid that you shouln't use customAxisMax directly as it use a Internal Access Levels.https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html
/// Flag indicating that the axis-max value has been customized
internal var _customAxisMax: Bool = false
Instead, you can use axisMaxValue to control it.
/// The maximum value for this axis.
/// If set, this value will not be calculated automatically depending on the provided data.
/// Use `resetCustomAxisMin()` to undo this.
public var axisMaxValue: Double
{
get
{
return _axisMaximum
}
set
{
_customAxisMax = true
_axisMaximum = newValue
}
}
//2016-06-12 update
public var factor: CGFloat
{
let content = _viewPortHandler.contentRect
return min(content.width / 2.0, content.height / 2.0)
/ CGFloat(_yAxis.axisRange)
}
RadarChartView will calculator a factor to transform values into pixels.
Maybe,you can use axisMinValue and axisMaxValue to control autoscale.

String to NSDecimalNumber Not Working

Can someone confirm for me this is the correct way to convert a NSString to an NSDecimalNumber? I have a label where when you click the button the price shows up, which is called totalPriceCalculated and then I also have all the strings where the calculations are made. Thanks in advance!
- (IBAction)calculateTotalPrice:(id)sender {
NSString *priceStringOne = [hiddenPriceOneTF text];
float priceFloatOne = [priceStringOne NSNumberFormatter];
NSString *priceStringTwo = [hiddenPriceTwoTF text];
float priceFloatTwo = [priceStringTwo floatValue];
NSString *priceStringThree = [hiddenPriceThreeTF text];
float priceFloatThree = [priceStringThree floatValue];
NSString *priceStringFour = [hiddenPriceFourTF text];
float priceFloatFour = [priceStringFour floatValue];
NSString *quanityStringOne = [quanityFirstTF text];
float quanityFloatOne = [quanityStringOne floatValue];
NSString *quanityStringTwo = [quanitySecondTF text];
float quanityFloatTwo = [quanityStringTwo floatValue];
NSString *quanityStringThree = [quanityThirdTF text];
float quanityFloatThree = [quanityStringThree floatValue];
NSString *quanityStringFour = [quanityFourthTF text];
float quanityFloatFour = [quanityStringFour floatValue];
float totalAmount = priceFloatOne * quanityFloatOne + priceFloatTwo * quanityFloatTwo + priceFloatThree * quanityFloatThree + priceFloatFour * quanityFloatFour ;
NSString *result = [NSString stringWithFormat:#" $ %0.2f", totalAmount];
[totalPriceCalculated setText:result];
NSString *totalPrice = totalPriceCalculated.text;
NSDecimalNumber *totalPriceNumber = (NSDecimalNumber *)totalPrice;
}
NSString *priceStringOne = [hiddenPriceOneTF text];
float priceFloatOne = [priceStringOne NSNumberFormatter];
UPDATED*
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [NSDecimalNumber decimalNumberWithString:totalPriceNumber];
payment.currencyCode = #"USD";
payment.shortDescription = #"Hipster t-shirt";
Another option is to create the decimal number from the float:
NSDecimalNumber *totalPriceNumber = [NSDecimalNumber decimalNumberWithDecimal:[#(totalAmount) decimalValue]];
According to the Apple docs, the prefered way is to use +decimalNumberWithString:; hope that helps.
Try:
totalPriceNumber = [[NSDecimalNumber alloc] initWithFloat:totalAmount];

Resources