Hi team, I’m using aspose.slides.via.java. I want to edit a doughnut chart. I’ve attached the image of current chart, what aspose output is and desired chart.
current chart that needs to be edited:
image.png (7.1 KB)
Aspsoe output:
image.png (22.5 KB)
desired poutput which comes once we click on edit chart type and in that doughnut chart is already selected. Once clicked on OK it gives this desired output:
image.png (27.7 KB)
Here is the code:
const shape = sld.getShapes().get_Item(i);
if(shape.getName() === "chart"){
// createChart(shape);
chart = shape;
defaultWorksheetIndex = 0;
// Gets the chart data worksheet
fact = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
const columnType = shape.getType();
['x1', 'x2', 'x3', 'x4'].forEach((label, index) =>
chart
.getChartData()
.getCategories()
.add(fact.getCell(0, index + 1, 0, label))
);
[{name: 'series1', values: [1, 2, 3, 4] }].forEach((ele, seriesIndex) => {
chart
.getChartData()
.getSeries()
.add(fact.getCell(0, 0, seriesIndex + 1, ele.name), asposeSlides.ChartType.Doughnut);
series = chart.getChartData().getSeries().get_Item(seriesIndex);
ele.values.forEach((value, valueIndex) => series.getDataPoints().addDataPointForDoughnutSeries(fact.getCell(0, valueIndex + 1, seriesIndex + 1, value)));
});
}
@karanmarsh,
Thank you for contacting support.
We need more details to investigate the case and help you. Please share the initial presentation file with the chart you used.
template.zip (3.7 MB)
out9.zip (3.7 MB)
I’ve attached the template file and output file.
@karanmarsh,
Thank you for the details. I reproduced the problem you described. We apologize for any inconvenience caused.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESNODEJS-57
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@karanmarsh,
Please try using the following code example:
var pres = new aspose.slides.Presentation("Plane Type Model Template v3.pptx");
sld = pres.getSlides().get_Item(4);
for (let i = 0; i < sld.getShapes().size(); i++) {
const shape = sld.getShapes().get_Item(i);
if(shape.getName() === "chart"){
// createChart(shape);
chart = shape;
defaultWorksheetIndex = 0;
// Gets the chart data worksheet
fact = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
const columnType = shape.getType();
['x1', 'x2', 'x3', 'x4'].forEach((label, index) =>
chart
.getChartData()
.getCategories()
.add(fact.getCell(0, index + 1, 0, label))
);
series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), columnType);
dataPoint = series.getDataPoints().addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 1));
dataPoint = series.getDataPoints().addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 2));
dataPoint.getFormat().getFill().setFillType(java.newByte(aspose.slides.FillType.Solid));
dataPoint.getFormat().getFill().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 0, 157, 224));
dataPoint = series.getDataPoints().addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 3));
dataPoint.getFormat().getFill().setFillType(java.newByte(aspose.slides.FillType.Solid));
dataPoint.getFormat().getFill().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 118, 211, 255));
dataPoint = series.getDataPoints().addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 4, 1, 4));
dataPoint.getFormat().getFill().setFillType(java.newByte(aspose.slides.FillType.Solid));
dataPoint.getFormat().getFill().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 0, 119, 160));
chart.getChartData().getSeriesGroups().get_Item(0).setDoughnutHoleSize(java.newByte(50));
}
};
pres.save("output.pptx", aspose.slides.SaveFormat.Pptx);
Hi @andrey.potapov
This works fine. Can you please let me know how this color coding you have done. How we can add color as per our requirment ?
@karanmarsh,
Please describe in more detail what difficulties you are currently facing.