Я думаю, что это может помочь вам.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Core-Plot";
graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
CPTheme *theme = [CPTheme themeNamed:kCPDarkGradientTheme];
[graph applyTheme:theme];
CGAffineTransform verticalFlip = CGAffineTransformMakeScale(1,-1);
UILabel *lbl;
for( int i = 21; i <= 24; i++ ){
lbl = (UILabel *)[self.view viewWithTag:i];
lbl.transform = CGAffineTransformTranslate(verticalFlip, 0, -300);
}
CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
hostingView.hostedLayer = graph;
graph.plotArea.masksToBorder = NO;
graph.paddingLeft = 50.0;
graph.paddingTop = 60.0;
graph.paddingRight = 20.0;
graph.paddingBottom = 50.0;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(6)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(([[expectedCigArray objectAtIndex:0] floatValue]+5))];
plotSpace.allowsUserInteraction=YES;
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x = axisSet.xAxis;
x.axisLineStyle = nil;
x.majorTickLineStyle = nil;
x.minorTickLineStyle = nil;
x.majorIntervalLength = CPDecimalFromString(@"1");
x.constantCoordinateValue = CPDecimalFromString(@"0");
x.title = @"Days";
x.titleLocation = CPDecimalFromFloat(1.5f);
CPXYAxis *y = axisSet.yAxis;
y.axisLineStyle = nil;
y.majorTickLineStyle = nil;
y.minorTickLineStyle = nil;
y.majorIntervalLength = CPDecimalFromString(@"5");
y.constantCoordinateValue = CPDecimalFromString(@"0");
y.title = @"Money";
y.titleOffset = 30.0f;
y.titleLocation = CPDecimalFromFloat(10.0f);
CPBarPlot *expectedMoney = [CPBarPlot tubularBarPlotWithColor:[CPColor darkGrayColor] horizontalBars:NO];
expectedCigPlot.identifier = @"expectedCigPlot";
expectedCigPlot.cornerRadius = 2.0f;
expectedCigPlot.barWidth = 15.0f;
expectedCigPlot.dataSource = self;
[graph addPlot:expectedCigPlot toPlotSpace:plotSpace];
}
-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot{
return (moneyArray.count + 1);
}
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if(fieldEnum == CPScatterPlotFieldX)
{
return [NSNumber numberWithInt: index];
}
else
{
if(plot.identifier == @"money")
{
if(index == 0)
return [NSNumber numberWithDouble:0.0];
return [NSNumber numberWithDouble:[[moneyArray objectAtIndex:(index-1)] doubleValue]];
}
}
}
Обратите внимание, что в приведенном выше коде массив money имеет значение money, поэтому я думаю, что вашу цель можно решить, передав значение y в массив.