Pet*_*erK 2 objective-c core-plot
我是Core Plot的新手,我无法在我的视图中添加一个Legend.我一直在尝试各种教程并阅读大量信息,但我不明白如何显示图例.
我真的很感激一些帮助,因为我花了很多时间试图让它发挥作用.
请注意,我在这一点上的目标是显示如下传奇:

这是我得到的:

唯一出现的是右边的粗线.我可以移动,但不能得到传说.
代码:
// Create pieChart from theme
pieChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[pieChart applyTheme:theme];
//Create host view
self.hostingView = [[CPTGraphHostingView alloc]
initWithFrame:[[UIScreen mainScreen]bounds]];
[self.view addSubview:self.hostingView];
hostingView_.hostedGraph = pieChart;
pieChart.axisSet = nil;
pieChart.plotAreaFrame.borderLineStyle = nil;
pieChart.paddingLeft = 10.0;
pieChart.paddingTop = 120.0;
pieChart.paddingRight = 10.0;
pieChart.paddingBottom = 80.0;
pieChart.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
pieChart.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
CPTMutableTextStyle *whiteText = [CPTMutableTextStyle textStyle];
whiteText.color = [CPTColor whiteColor];
whiteText.fontSize = 14;
whiteText.fontName = @"Helvetica";
pieChart.titleTextStyle = whiteText;
//==================================================//
// LEGENDS //
// 1 - Get graph instance
CPTGraph *graph = self.hostingView.hostedGraph;
// 2 - Create legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
// 3 - Configure legen
theLegend.numberOfColumns = 1;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;
// 4 - Add legend to graph
graph.legend = theLegend;
graph.legendAnchor = CPTRectAnchorRight;
CGFloat legendPadding = -(self.view.bounds.size.width / 8);
graph.legendDisplacement = CGPointMake(legendPadding, 0.0);
//==================================================//
// Add pie chart
CPTPieChart *piePlot = [[CPTPieChart alloc] init];
piePlot.dataSource = self;
piePlot.pieRadius = 70.0; //140.0; //131.0;
piePlot.identifier = @"Pie Chart 1";
piePlot.startAngle = M_PI_4;
piePlot.sliceDirection = CPTPieDirectionCounterClockwise; //CPTPieDirectionCounterClockwise;
piePlot.centerAnchor = CGPointMake(0.5, 0.5); //(0.5, 0.38);
piePlot.borderLineStyle = [CPTLineStyle lineStyle];
piePlot.delegate = self;
[pieChart addPlot:piePlot];
Run Code Online (Sandbox Code Playgroud)
XX
-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
return [NSString stringWithFormat:@"Pie Slice %lu", (unsigned long)index];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
884 次 |
| 最近记录: |