【发布时间】:2015-08-19 13:50:54
【问题描述】:
左图是 CorePlot 库演示中的图,右图是我使用以下代码创建的图。我认为为了让它看起来像一个真正的圆形馅饼,我遗漏了一些东西:
-(void)configureChart {
// 1 - Get reference to graph
pieChartGraph = [[CPTXYGraph alloc] initWithFrame:self.pieChartgraphHostView.bounds];
self.pieChartgraphHostView.hostedGraph = pieChartGraph;
// 2 - Create chart
pieChart = [[CPTPieChart alloc] init];
pieChart.dataSource = self;
pieChart.delegate = self;
// pieChart.pieRadius = (self.pieChartgraphHostView.bounds.size.height * 0.7) / 2;
pieChart.pieRadius = (self.pieChartgraphHostView.bounds.size.height * 0.7) / 2;
pieChart.identifier = pieChartGraph.title;
pieChart.startAngle = CPTFloat(M_PI_4);
pieChart.sliceDirection = CPTPieDirectionClockwise;
pieChart.borderLineStyle = [CPTLineStyle lineStyle];
// 3 - Create gradient
CPTGradient *overlayGradient = [[CPTGradient alloc] init];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.9];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.4] atPosition:1.0];
pieChart.overlayFill = [CPTFill fillWithGradient:overlayGradient];
// 4 - Add chart to graph
[pieChartGraph addPlot:pieChart];
pieChart.dataSource = self;
self.dataForChart = [@[@20.0, @30.0, @60.0] mutableCopy];
//self.dataForChart = [@[@20.0, @30.0, @60.0]mutableCopy];
}
我尝试从演示库(CorePlot example project here 中名为 CorePlot 的类)复制代码。
我做错了什么?为什么我的图表是正方形而不是圆形?
【问题讨论】:
标签: ios graph core-plot pie-chart