0

円グラフの位置を変更できません(凡例が円グラフに重ならないように、凡例に対してもっと左にしたいです)。基本的に、凡例を表示できるように左にシフトしたいと思います。

次のプロパティを変更してみました(ただし、円グラフの位置に明らかな影響はありません)。

   // 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);
4

1 に答える 1