繁体   English   中英

在coreplot iOS的同一Y轴上绘制负值和正值

[英]plot negative and positive values in same Y-axis in coreplot ios

这是我正在创建的散点图:

  -(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];

您能找到截图吗? 我有以下问题。

  1. 我可以设置y轴,但图形将-50设为0。
  2. 在屏幕截图中,y轴未正确对齐。
  3. 只有轴为粗体。 我该如何将其更改为正常状态。

您能帮我解决这些问题吗?

谢谢 ...

在此处输入图片说明

谢谢

NSString具有integerValue方法,该方法会将字符串内容解析为NSInteger 对浮点值使用doubleValue方法。 对于更复杂的数字解析任务,请使用NSScanner

例如,

label.tickLocation = CPTDecimalFromInteger(yAxisLabels[i].integerValue);

[yLocations addObject:@(yAxisLabels[i].integerValue)];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM