您好我正在寻找图表 我可以在条形图上绘制散点图(条形图上的线条),是否可以使用核心图在同一图形中绘制线条和条形图?
我试过以下但是我没有成功。
CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame: hostingView.bounds];
hostingView.hostedGraph = graph;
CPTBarPlot *cptBarPlot = [[CPTBarPlot alloc] init];
cptBarPlot.fill = [CPTFill fillWithColor:color];
cptBarPlot.lineStyle = nil;
cptBarPlot.identifier = [columnSeries objectForKey:@"id"];
cptBarPlot.name = [columnSeries objectForKey:@"displayName"];
cptBarPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(BarInitialX) length:CPTDecimalFromDouble(xAxisLength)];
cptBarPlot.barWidth = CPTDecimalFromDouble(BarWidth);
cptBarPlot.dataSource = self;
//cptBarPlot.opacity = 0.0f;
cptBarPlot.delegate = self;
[graph addPlot:cptBarPlot];
CPTXYPlotSpace * secondPlotSpace = [[CPTXYPlotSpace alloc]init];
secondPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(BarInitialX) length:CPTDecimalFromDouble(xAxisLength+1)];
secondPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromFloat(yAxisLength)];
//[graph addPlotSpace:secondPlotSpace];
CPTScatterPlot * linePlot = [[CPTScatterPlot alloc] init];
CPTMutableLineStyle * lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth = 1.f;
lineStyle.lineColor = color;
lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:3.0f],nil];
linePlot.dataLineStyle = lineStyle;
linePlot.identifier = [lineSeries objectForKey:@"id"];
linePlot.dataSource = self;
linePlot.name = [lineSeries objectForKey:@"displayName"];
//linePlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(BarInitialX) length:CPTDecimalFromDouble(xAxisLength)];
[graph addPlot: linePlot];
我在上面试过并试图在不同的地块空间中添加地块,即 [graph addPlot:linePlot toPlotSpace:secondPlotSpace]仍然没有成功。
我想我错过了一些东西,却无法找到它。
提前感谢您的帮助。
答案 0 :(得分:0)
您是否实施了以下方法来返回图表值?
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if ( [plot isKindOfClass:[CPTBarPlot class]] ) {
switch (fieldEnum) {
case CPTBarPlotFieldBarLocation:
return ...;
break;
case CPTBarPlotFieldBarTip:
return ...;
break;
case CPTBarPlotFieldBarBase:
return ...;
default:
return 0;
break;
}
} else {
switch (fieldEnum) {
case CPTScatterPlotFieldX:
return ...;
break;
case CPTScatterPlotFieldY:
return ...;
break;
default:
return 0;
break;
}
}
}