plot negative and positive values in same Y-axis in coreplot ios
- by user3774439
I have an issue in converting axis labels to int or float values.
This is my Y-Axis. It contains temperature values contains -50, 33, 117, 200.
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(1);
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.minorTicksPerInterval = 0.0;
y.labelOffset = 0.0;
y.title = @"";
y.titleOffset = 0.0;
NSMutableSet *yLabels = [NSMutableSet setWithCapacity:4];
NSMutableSet *yLocations = [NSMutableSet setWithCapacity:4];
NSArray *yAxisLabels = [NSArray arrayWithObjects:@"-50", @"33", @"117", @"200", nil];
NSNumberFormatter * nFormatter = [[NSNumberFormatter alloc] init];
[nFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
for ( NSUInteger i = 0; i < [yAxisLabels count]; i++ ) {
NSLog(@"%@",[yAxisLabels objectAtIndex:i]);
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%@",[yAxisLabels objectAtIndex:i]] textStyle:axisTextStyle];
label.tickLocation = CPTDecimalFromUnsignedInteger(i);
label.offset = y.majorTickLength;
if (label) {
[yLabels addObject:label];
[yLocations addObject:[NSDecimalNumber numberWithUnsignedInteger:i]];
}
label = nil;
}
y.axisLabels = yLabels;
y.majorTickLocations = yLocations;
y.labelFormatter = nFormatter;
Now, my issue is.. I am getting data from the BLE device as temperature values as strings like 50, 60.3, etc...
Now I want plot these values from BLE device with the Y-axis values. i am unable convert these Y-axis labels to temperature values.
Could you please help me guys...I have tried many time still no luck. Please help me
UPDATE::
This is the way I am creating scatterplot:
-(void)createScatterPlotsWithIdentifier:(NSString *)identifier color:(CPTColor *)color forGraph:(CPTGraph *)graph forXYPlotSpace:(CPTXYPlotSpace *)plotSpace{
CPTScatterPlot *scatterPlot = [[CPTScatterPlot alloc] init];
scatterPlot.dataSource = self;
scatterPlot.identifier = identifier;
//Plot a graph with in the plotspace
[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:scatterPlot, nil]];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(30)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(-50) length:CPTDecimalFromUnsignedInteger(250)];
CPTMutablePlotRange *xRange = [[self getCoreplotSpace].xRange mutableCopy];
[xRange expandRangeByFactor:CPTDecimalFromCGFloat(-1)];
[self getCoreplotSpace].xRange = xRange;
CPTMutableLineStyle *scatterLineStyle = [scatterPlot.dataLineStyle mutableCopy];
scatterLineStyle.lineWidth = 1;
scatterLineStyle.lineColor = color;
scatterPlot.dataLineStyle = scatterLineStyle;
CPTMutableLineStyle *scatterSymbolLineStyle = [CPTMutableLineStyle lineStyle];
scatterSymbolLineStyle.lineColor = color;
CPTPlotSymbol *scatterSymbol = [CPTPlotSymbol ellipsePlotSymbol];
scatterSymbol.fill = [CPTFill fillWithColor:color];
scatterSymbol.lineStyle = scatterSymbolLineStyle;
scatterSymbol.size = CGSizeMake(2.0f, 2.0f);
scatterPlot.plotSymbol = scatterSymbol;
[graph addPlot:scatterPlot toPlotSpace:plotSpace];
}
Configuring the Y-axis like this:
NSMutableSet *yLabels = [NSMutableSet setWithCapacity:4];
NSMutableSet *yLocations = [NSMutableSet setWithCapacity:4];
NSArray *yAxisLabels = [NSArray arrayWithObjects:@"-50", @"33", @"117", @"200", nil];
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithUnsignedInt:-50], [NSDecimalNumber numberWithInt:33], [NSDecimalNumber numberWithInt:117], [NSDecimalNumber numberWithInt:200],nil];
for ( NSUInteger i = 0; i < [yAxisLabels count]; i++ ) {
NSLog(@"%@",[yAxisLabels objectAtIndex:i]);
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%@",[yAxisLabels objectAtIndex:i]] textStyle:axisTextStyle];
label.tickLocation = CPTDecimalFromInteger([[customTickLocations objectAtIndex:i] integerValue]);
label.offset = y.majorTickLength;
if (label) {
[yLabels addObject:label];
[yLocations addObject:[NSString stringWithFormat:@"%d",[[customTickLocations objectAtIndex:i] integerValue]]];
}
label = nil;
}
y.axisLabels = yLabels;
y.majorTickLocations = [NSSet setWithArray:customTickLocations];
Eric, I set the range as you said in CreateSctterPlot method. But In horizontal line on graph are not coming. Could you please help me what I am wrong.
Thanks