核心图中的图例问题(pieChart) [英] Problems with legend in Core-Plot (pieChart)
本文介绍了核心图中的图例问题(pieChart)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用Core-Plot绘制pieChart的图例时遇到问题,因为图例中图表的每个元素的名称始终是CPTPieChart的标识符。有人能帮我吗?谢谢。
I have a problem drawing the legend of a pieChart with Core-Plot, because the name of each element of the chart in the legend is always the identifier of the CPTPieChart. Can someone help me? Thanks.
这是源代码:
-(void)constructPieChart {
// Create pieChart from theme
//[pieGraph applyTheme:theme];
pieChartView.hostedGraph = pieGraph;
pieGraph.plotAreaFrame.masksToBorder = YES;
pieGraph.paddingLeft = 0;
pieGraph.paddingTop = 20.0;
pieGraph.paddingRight = 0;
pieGraph.paddingBottom = 60.0;
pieGraph.axisSet = nil;
// Prepare a radial overlay gradient for shading/gloss
CPTGradient *overlayGradient = [[[CPTGradient alloc] init] autorelease];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.3] atPosition:0.9];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.7] atPosition:1.0];
// Add pie chart
piePlot = [[CPTPieChart alloc] init];
piePlot.dataSource = self;
piePlot.delegate = self;
piePlot.pieRadius = 80.0;
piePlot.identifier = @"Pie Chart 2";
piePlot.startAngle = M_PI_2;
piePlot.sliceDirection = CPTPieDirectionClockwise;
piePlot.borderLineStyle = [CPTLineStyle lineStyle];
//piePlot.sliceLabelOffset = 5.0;
piePlot.overlayFill = [CPTFill fillWithGradient:overlayGradient];
[pieGraph addPlot:piePlot];
pieGraph.title=@"GRAFICA SECTORES";
[piePlot release];
// Add some initial data
NSMutableArray *contentArray = [NSMutableArray arrayWithObjects:
[NSNumber numberWithDouble:20.0],
[NSNumber numberWithDouble:40.0],
[NSNumber numberWithDouble:30.0],
[NSNumber numberWithDouble:23],
[NSNumber numberWithDouble:60.0],
nil];
self.dataForChart = contentArray;
// Add legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:pieGraph];
theLegend.numberOfColumns = 2;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;
pieGraph.legend = theLegend;
pieGraph.legendAnchor = CPTRectAnchorBottom;
pieGraph.legendDisplacement = CGPointMake(0.0, 30.0);
}
因此在图例中我总是饼图2。
So in the legend I have always "Pie Chart 2".
PS:很抱歉,因为我英语不好。
PS: Sorry because of my poor english.
推荐答案
你需要添加这个方法对你的数据源:
You need to add this method to your datasource:
-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart
recordIndex:(NSUInteger)index;
将为每个索引(对应于每个饼图切片)调用它。只需为每个字符串返回正确的标题字符串。
It will be called for each index (corresponding to each pie slice). Simply return the correct title string for each one.
这篇关于核心图中的图例问题(pieChart)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文