这是我正在创建散点图:
-(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];
}
像这样配置Y轴:
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];
你能找到截图吗? 我有以下问题。
谢谢...
由于
答案 0 :(得分:1)
NSString
有integerValue
方法,可将字符串内容解析为NSInteger
。使用doubleValue
方法获取浮点值。对于更复杂的数字解析任务,请使用NSScanner
。
例如,
label.tickLocation = CPTDecimalFromInteger(yAxisLabels[i].integerValue);
和
[yLocations addObject:@(yAxisLabels[i].integerValue)];