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

CorePlot: unable to change pie chart position (displacement)

我无法更改饼图位置(我希望它比图例更左以便图例不覆盖饼图)。基本上我想将它向左移动以允许显示图例。

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

   // 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 以在图表中定位饼图。是一个CGPoint。两个坐标的范围都在 0 和 1 之间,类似于 CALayer.

anchorPoint