CorePlot:无法更改饼图位置(位移)

我无法改变饼图的位置 (我希望它相对于图例更加左侧,以便图例不覆盖饼图)。 基本上我想把它转移到左侧,让图例显示。

我尝试修改以下属性 (但对饼图位置没有明显的影响):

// pieChartGraph is a CPTPieChart object pieChartGraph.graph.position = CGPointMake(-100, 0); // I also tried: pieChart.position = CGPointMake(-100, 0); // and also playing with: pieChart.anchorPoint 

这是我得到的,也是我的代码 (顺便说一下,标题不显示):

在这里输入图像说明

 pieChartGraph = [[CPTXYGraph alloc] initWithFrame:self.pieChartgraphHostView.bounds]; self.pieChartgraphHostView.hostedGraph = pieChartGraph; pieChartGraph.plotAreaFrame.masksToBorder = NO; pieChartGraph.axisSet = nil; pieChart.title = @"title"; // <-- BTW, the title does not show either // 2 - Create chart pieChart = [[CPTPieChart alloc] init]; pieChart.dataSource = self; pieChart.delegate = self; pieChart.pieRadius = self.pieChartgraphHostView.bounds.size.width; pieChartGraph.delegate = self; 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 pieChart.pieRadius = pieChart.pieRadius / 2.3; [pieChartGraph addPlot:pieChart]; self.dataForChart = [@[@(self.displayedLastDataPoint.percentageUnder), @(self.displayedLastDataPoint.percentageOver), @(self.displayedLastDataPoint.percentageClean), @(self.displayedLastDataPoint.percentageRemaining)] mutableCopy]; // Add legend CPTLegend *theLegend = [CPTLegend legendWithGraph:pieChartGraph]; theLegend.numberOfColumns = 1; theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]]; theLegend.borderLineStyle = [CPTLineStyle lineStyle]; theLegend.entryFill = [CPTFill fillWithColor:[CPTColor lightGrayColor]]; theLegend.entryBorderLineStyle = [CPTLineStyle lineStyle]; theLegend.entryCornerRadius = CPTFloat(3.0); theLegend.entryPaddingLeft = CPTFloat(3.0); theLegend.entryPaddingTop = CPTFloat(3.0); theLegend.entryPaddingRight = CPTFloat(3.0); theLegend.entryPaddingBottom = CPTFloat(3.0); theLegend.cornerRadius = 5.0; theLegend.delegate = self; pieChartGraph.legend = theLegend; pieChartGraph.legendAnchor = CPTRectAnchorRight; CGFloat legendPadding = +(self.view.bounds.size.width / 16); pieChartGraph.legendDisplacement = CGPointMake(legendPadding, 0.0); pieChartGraph.graph.position = CGPointMake(-30, 0); 

设置centerAnchor将饼图放置在graphics中。 这是一个CGPoint 。 两个坐标的范围在0到1之间,类似于CALayeranchorPoint