您好,我正在寻找一个图表,我可以绘制散点图的条形图(线上的条形图),可以绘制线条和条形图在同一图表使用核心图?
我试着追随,以获得相同的结果,但我没有成功。
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,但我仍然没有成功。
我想我遗漏了什么,但是找不到。
提前感谢您的帮助。
发布于 2013-08-16 02:32:05
您是否实现了以下方法来返回图表值?
-(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;
}
}
}https://stackoverflow.com/questions/14358645
复制相似问题