在coreplot ios的同一Y轴上绘制负值和正值
这是我正在创建的散点图:在coreplot ios的同一Y轴上绘制负值和正值,ios,core-plot,Ios,Core Plot,这是我正在创建的散点图: -(void)createScatterPlotsWithIdentifier:(NSString *)identifier color:(CPTColor *)color forGraph:(CPTGraph *)graph forXYPlotSpace:(CPTXYPlotSpace *)plotSpace{ CPTScatterPlot *scatterPlot = [[CPTScatterPlot alloc] init]; scatterPlot.da
-(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];
NSMutableSet*yLabels=[NSMutableSet setWithCapacity:4];
NSMutableSet*yLocations=[NSMutableSet-setWithCapacity:4];
NSArray*yAxisLabels=[NSArray阵列,其对象为:@“-50”,“33”,“117”,“200”,无];
NSArray*customTickLocations=[NSArray Array WithObjects:[NSDecimalNumber WithUnsignedint:-50],[NSDecimalNumber Withint:33],[NSDecimalNumber Withint:117],[NSDecimalNumber Withint:200],无];
对于(整数i=0;i<[yAxisLabels计数];i++){
NSLog(@“%@,[yAxisLabels objectAtIndex:i]);
CPTAxisLabel*label=[[CPTAxisLabel alloc]initWithText:[NSString stringWithFormat:@“%@,[yAxisLabels对象索引:i]]textStyle:axisTextStyle];
label.tickLocation=CPTDecimalFromInteger([[customTickLocations objectAtIndex:i]integerValue]);
label.offset=y.majorTickLength;
如果(标签){
[yLabels addObject:label];
[Y位置添加对象:[NSString stringWithFormat:@“%d”,[[customTickLocations objectAtIndex:i]整数值]];
}
标签=零;
}
y、 axisLabels=Ylabel;
y、 majorTickLocations=[NSSet setWithArray:customTickLocations];
你能找到截图吗。
我有以下问题
谢谢
NSString
有一个integerValue
方法,可以将字符串内容解析为NSInteger
。对浮点值使用doubleValue
方法。对于更复杂的数字解析任务,请使用NSScanner
比如说,
label.tickLocation = CPTDecimalFromInteger(yAxisLabels[i].integerValue);
及
谢谢你,埃里克。但我可以显示轴像-50,33117200。但我无法绘制图表。因为在Y轴上,标签值取0,1,2,3,4。但是数值有50、60、40等等。我能画些什么图形呢。请检查更新的答案。图上没有Y轴标签。请不要介意在这方面帮助我。
yRange
在0和4之间扩展,而刻度和标签在-50和200之间。将yRange
更改为位置-50和长度250(200-(-50))。在转换“-50”位置的两个位置上,您首先将其转换为无符号数字。不要那样做CPTDecimalFromUnsignedInteger(-50)
->CPTDecimalFromInteger(-50)
和[NSDecimalNumber numberWithUnsignedInt:-50]
->@-50
必须将-50视为有符号整数。在轴范围和记号位置将其强制转换为无符号会导致值更改。
[yLocations addObject:@(yAxisLabels[i].integerValue)];