左侧的图是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 her e中称为CorePlot的类)。
我究竟做错了什么?为什么我的图是正方形而不是圆形?
最佳答案
尝试编辑图表的半径。这就是使它成为一个圆圈的原因。要从正方形视图获得一个圆,通常需要执行以下操作:
squareView.radius = view.frame.size.width/2;
您可以在pieChart上尝试以下操作:
pieChart.pieRadius = pieChart.frame.size.width/2;
顺便说一下,您将设置2倍pieChart数据源
关于ios - 如何使用CorePlot创建外观像饼图的饼图?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32097481/