简体   繁体   English

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

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

This is the 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: 像这样配置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];

Could you please find the screenshot. 您能找到截图吗? I have following issues. 我有以下问题。

  1. I am able to set the y axis but the graph is taking -50 as 0. 我可以设置y轴,但图形将-50设为0。
  2. In screenshot, y axis is not aligned properly. 在屏幕截图中,y轴未正确对齐。
  3. only axis are in bold color. 只有轴为粗体。 how can I change that to normal. 我该如何将其更改为正常状态。

could you please help me on these issues. 您能帮我解决这些问题吗?

Thanks ... 谢谢 ...

在此处输入图片说明

Thanks 谢谢

NSString has an integerValue method that will parse the string contents into an NSInteger . NSString具有integerValue方法,该方法会将字符串内容解析为NSInteger Use the doubleValue method for floating point values. 对浮点值使用doubleValue方法。 For more complex number parsing tasks, use NSScanner . 对于更复杂的数字解析任务,请使用NSScanner

For example, 例如,

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

and

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

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

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