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

Free Support Forum - aspose.com

Unable to insert Doughnut chart

Hi,

When i am inserting Doughnut chart with following method parameters its working.

1>IChart iChart = iSlide.getShapes().addChart(chart.getChartType(), xVal, yVal, width, height);

but When i am using below code its not working.

2>IChart iChart = iSlide.getShapes().addChart(chart.getChartType(), xVal, yVal, width, height,false);

In documentation i read that by setting last attribute of addChart method to false make chart generation faster so i want to use second approach for generating chart but i am unable to insert it.

Hi Ankit,

I have observed your requirements and like to share that I have tested the addChart() method that is failing on your end using Aspose.Slides for Java 16.12.0 on my end and it generated a presentation with empty chart series and categories as expected in accordance with set inItwithSample value to false. I have tested using following code and have also attached the generated presentation.

public static void TestChart2()
{
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);

IChart chart = slide.getShapes().addChart(ChartType.Doughnut, 100, 100, 400, 300,false);
pres.save(“C:\Aspose Data\Doughnut.pptx”, SaveFormat.Pptx);
}

Many Thanks,

Hi Mudassir,

Thank you for your reply.
I am using aspose 16.8.0 and below code is not generating proper doughnut chart.


Presentation pres = new Presentation();

ISlide islide = pres.getSlides().get_Item(0);
IChart ichart = islide.getShapes().addChart(ChartType.Doughnut, 10, 10, 500, 500, false);

// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

// Getting the chart data work sheet.
IChartDataWorkbook iChartDataWorkbook = ichart.getChartData().getChartDataWorkbook();
IChartSeries iChartSeries = ichart.getChartData().getSeries().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 0, 1, "test"),
ChartType.Doughnut);

IChartCategory iChartCategory1= ichart.getChartData().getCategories().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 1, 0, "category1"));
IChartCategory iChartCategory2= ichart.getChartData().getCategories().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 2, 0, "category2"));
IChartCategory iChartCategory3= ichart.getChartData().getCategories().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 3, 0, "category3"));
iChartSeries.getDataPoints().addDataPointForDoughnutSeries(iChartDataWorkbook.getCell(defaultWorksheetIndex, 1, 1, 10));
iChartSeries.getDataPoints().addDataPointForDoughnutSeries(iChartDataWorkbook.getCell(defaultWorksheetIndex, 2, 1, 20));
iChartSeries.getDataPoints().addDataPointForDoughnutSeries(iChartDataWorkbook.getCell(defaultWorksheetIndex, 3, 1, 30));

pres.save("c:\\Users\\C-AnkitaB\\aspose\\doughnut.pptx", SaveFormat.Pptx);

Hi Ankit,


Can you please share generated result with us so that we can investigate issue.

Best Regards,

Hi Muhammad,


please find attached ppt.

Hi Ankit,

I have observed the presentation file shared by you and request you and have been able to observe the issue specified. An issue with ID SLIDESJAVA-35853 has been created in our issue tracking system to fuhrer investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be fixed.

We are sorry for your inconvenience,

Hi Ankit,

I have used following sample code and Aspose.Slides for Java 17.4 on my end to generate Doughnut chart successfully. Can you please try using the following sample code on your end to serve the purpose.

public static void TestDoughnut()
{
Presentation pres = new Presentation();

ISlide islide = pres.getSlides().get_Item(0);
IChart ichart = islide.getShapes().addChart(ChartType.Doughnut, 10, 10, 500, 500, false);

int defaultWorksheetIndex = 0;
// Getting the chart data work sheet.
IChartDataWorkbook iChartDataWorkbook = ichart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
ichart.getChartData().getSeries().clear();
ichart.getChartData().getCategories().clear();
IChartCategory iChartCategory1= ichart.getChartData().getCategories().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 1, 0, “category1”));
IChartCategory iChartCategory2= ichart.getChartData().getCategories().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 2, 0, “category2”));
IChartCategory iChartCategory3= ichart.getChartData().getCategories().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 3, 0, “category3”));
IChartSeries iChartSeries = ichart.getChartData().getSeries().add(iChartDataWorkbook.getCell(defaultWorksheetIndex, 0, 1, “test”), ichart.getType());

// Setting hole size and colors of the series
iChartSeries.getParentSeriesGroup().setDoughnutHoleSize((byte)50);
iChartSeries.getParentSeriesGroup().setColorVaried(true);

iChartSeries.getDataPoints().addDataPointForDoughnutSeries(iChartDataWorkbook.getCell(defaultWorksheetIndex, 1, 1, 10));
iChartSeries.getDataPoints().addDataPointForDoughnutSeries(iChartDataWorkbook.getCell(defaultWorksheetIndex, 2, 1, 20));
iChartSeries.getDataPoints().addDataPointForDoughnutSeries(iChartDataWorkbook.getCell(defaultWorksheetIndex, 3, 1, 30));
pres.save(“c:\Aspose Data\doughnut-new.pptx”, SaveFormat.Pptx);
}

Many Thanks,