We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pie Chart Labels Overlapping

Hello Team,

I am using Aspose java slides 8.3.0 and generating pie charts, the labels are getting overlapped .I have attached the sample ppt for reference.Can you please assist on this issue ASAP?

Thanks.

Hi,

Thank you for considering Aspose.

Please share your sample code (with data) which you are using to generate the chart as per your attached PPTX file. We will check it and get back to you soon.

Thanks & Regards,

Thanks for the prompt revert. Below is the sample Code and data

ChartEx tChart;
ChartDataCellFactory fact = tChart.getChartData().getChartDataCellFactory();

tChart.getChartData().getCategories().add(fact.getCell(0, CounterRow, 0, strData));

tChart.getChartData().getSeries().get_Item(0).getValues().add(fact.getCell(0, CounterRow, 1, doubleData));

--Sample Data

Americas 85695
Asia 19448
Australia 2573
Clearstream 41
Euroclear 1340
Europe 16133

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the details.

To avoid overlapping of Data Labels, please use DataLabel Position to Best Fit (as mentioned in the bold lines in the below code). Please see the following sample code I used at my end using your sample data:

//Instantiate PresentationEx class that represents PPTX file

PresentationEx pres = new PresentationEx();

//Access first slide

SlideEx sld = pres.getSlides().get_Item(0);

// Add chart with default data

ChartEx chart = sld.getShapes().addChart(ChartTypeEx.Pie, 0, 0, 500, 500);

//Setting chart Title

chart.getChartTitle().getText().setText("Sample Title");

chart.getChartTitle().getText().setCenterText(true);

chart.getChartTitle().setHeight(20f);

chart.hasTitle(true);

//Set first series to Show Values

chart.getChartData().getSeries().get_Item(0).getLabels().setShowValue(true);

//Setting the index of chart data sheet

int defaultWorksheetIndex = 0;

//Getting the chart data worksheet

ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory();

//Delete default generated series and categories

chart.getChartData().getSeries().clear();

chart.getChartData().getCategories().clear();

int s = chart.getChartData().getSeries().getCapacity();

//Adding new series

chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Sales"), chart.getType());

//Adding new categories

chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Americas"));

chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Asia"));

chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Australia"));

chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 4, 0, "Clearstream"));

chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 5, 0, "Euroclear"));

chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 6, 0, "Europe"));

//Take first chart series

ChartSeriesEx series = chart.getChartData().getSeries().get_Item(0);

//Now populating series data

series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 1, 85695));

series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 1, 19448));

series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 1, 2573));

series.getValues().add(fact.getCell(defaultWorksheetIndex, 4, 1, 41));

series.getValues().add(fact.getCell(defaultWorksheetIndex, 5, 1, 1340));

series.getValues().add(fact.getCell(defaultWorksheetIndex, 6, 1, 16133));

//first label will be show Category name

DataLabelEx lbl = new DataLabelEx(series);

lbl.setShowCategoryName( true);

lbl.setShowValue(true);

lbl.setShowPercentage(true);

lbl.setSeparator(",");

lbl.setId (0);

lbl.setPosition(LegendDataLabelPositionEx.BestFit);

series.getLabels().add(lbl);

//first label will be show Category name

lbl = new DataLabelEx(series);

lbl.setShowCategoryName( true);

lbl.setShowValue(true);

lbl.setShowPercentage(true);

lbl.setSeparator(",");

lbl.setId (1);

lbl.setPosition(LegendDataLabelPositionEx.BestFit);

series.getLabels().add(lbl);

//first label will be show Category name

lbl = new DataLabelEx(series);

lbl.setShowCategoryName( true);

lbl.setShowValue(true);

lbl.setShowPercentage(true);

lbl.setSeparator(",");

lbl.setId (2);

lbl.setPosition(LegendDataLabelPositionEx.BestFit);

series.getLabels().add(lbl);

//first label will be show Category name

lbl = new DataLabelEx(series);

lbl.setShowCategoryName( true);

lbl.setShowValue(true);

lbl.setShowPercentage(true);

lbl.setSeparator(",");

lbl.setId (3);

lbl.setPosition(LegendDataLabelPositionEx.BestFit);

series.getLabels().add(lbl);

//first label will be show Category name

lbl = new DataLabelEx(series);

lbl.setShowCategoryName( true);

lbl.setShowValue(true);

lbl.setShowPercentage(true);

lbl.setSeparator(",");

lbl.setId (4);

lbl.setPosition(LegendDataLabelPositionEx.BestFit);

series.getLabels().add(lbl);

//first label will be show Category name

lbl = new DataLabelEx(series);

lbl.setShowCategoryName( true);

lbl.setShowValue(true);

lbl.setShowPercentage(true);

lbl.setSeparator(",");

lbl.setId (5);

lbl.setPosition(LegendDataLabelPositionEx.BestFit);

series.getLabels().add(lbl);

// Save presentation with chart

pres.write("C:\\Data\\PieChart.pptx");

In case you still face the issue or have any confusion, please share your complete code with us, we will check it and get back to you soon.

Thanks & Regards,