Reputation: 2410
I am generating an excel Pie Chart from Delphi and all goes well except when I want the labels (with the values) to be sent to the exterior of the Pie
So my generated pie looks like this:
And I want to obtain this:
So my code looks like this:
if not CreateExcel then exit;
VisibleExcel(false);
if AddWorkBook then
begin
SelectSheet(1);
end;
AddChart(ChartName,xl3DPieExploded);//xl3DColumn);
SetSourceData(1{ChartName},2,'A1:B5',xlColumns);
randomize;
VisibleExcel(false);
E.ActiveWorkbook.Sheets.Item[2].Cells[1,1] :='Some text';
E.ActiveWorkbook.Sheets.Item[2].Cells[1,2] :='Chart title';
E.ActiveWorkbook.Sheets.Item[2].Cells[2,1] :='Mijloace de productie';
E.ActiveWorkbook.Sheets.Item[2].Cells[3,1] :='Mediul de munca';
E.ActiveWorkbook.Sheets.Item[2].Cells[4,1] :='Sarcina de munca';
E.ActiveWorkbook.Sheets.Item[2].Cells[5,1] :='Executant';
E.ActiveWorkbook.Sheets.Item[2].Cells[2,2] := FloatToStr(proc1)+'%';
E.ActiveWorkbook.Sheets.Item[2].Cells[3,2] := FloatToStr(proc2)+'%';
E.ActiveWorkbook.Sheets.Item[2].Cells[4,2] := FloatToStr(proc3)+'%';
E.ActiveWorkbook.Sheets.Item[2].Cells[5,2] := FloatToStr(proc4)+'%';
// remove the legend
E.ActiveWorkbook.Charts.Item['Chart1'].Select;
E.ActiveChart.Legend.Select;
E.Selection.Delete;
// apply labels
E.ActiveWorkbook.Charts.Item['Chart1'].Select;
E.ActiveChart.SeriesCollection(1).ApplyDataLabels;
// formatting chart labels.
E.ActiveChart.ApplyDataLabels(xlDataLabelsShowLabelAndPercent, false,true,
true{HasLeaderLines: OleVariant; }, false {ShowSeriesName: OleVariant;},
true {ShowCategoryName: OleVariant; }, true {ShowValue: OleVariant;},
false {ShowPercentage: OleVariant; }, false {ShowBubbleSize: OleVariant;},
'; '{Separator: OleVariant; } );
So it has LeaderLines, this far it works, but now I want to see the labels outside of the pie, distanced. How can I do this. I recorded a Macro in Excel but I cannot seem to be able to apply it to Delphi. The macro code that I want to use in Delphi is:
ActiveSheet.ChartObjects("Chart 1").Activate
Selection.Position = xlLabelPositionOutsideEnd
Upvotes: 2
Views: 1385
Reputation: 76693
The Series
object has the DataLabels
method which if you omit the optional index parameter can return a DataLabels
object which has the Position
property, that you might see in your recorded macro. So I believe you can add the following line to the end of your posted code:
E.ActiveChart.SeriesCollection(1).DataLabels.Position := xlLabelPositionOutsideEnd;
Upvotes: 4