Stacked Columns in the Chart Are Shifted to the Right Side on Each Series

Hi team, I’m using aspose.slides.via.java to edit a PPT. In stacked column chart the sections of each column are offset from each other. In powerpoint if I click “Change chart type” and just click “Ok”, it fixes my chart. Here I’ve added the images for current output and required output with a code snippet.

current output:
image.png (25.1 KB)

desired output:
image.png (23.6 KB)

   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] }, {name: 'series2', values: [1, 2, 3, 4]}, {name: 'series3', values: [1, 2, 3, 4]}].forEach((ele, seriesIndex) => {
        chart
            .getChartData()
            .getSeries()
            .add(fact.getCell(0, 0, seriesIndex + 1, ele.name), asposeSlides.ChartType.StackedColumn);
        series = chart.getChartData().getSeries().get_Item(seriesIndex);
        ele.values.forEach((value, valueIndex) => series.getDataPoints().addDataPointForBarSeries(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 following:

  • input presentation file
  • output presentation file
  • Aspose.Slides version you used

template.zip (3.7 MB)

out9.zip (3.7 MB)

I’ve attached the template file which is an input file and out9 file. Checkout the slide number 4 and 5. I’m using aspose version “^24.4.0”.
checkout this code file:
chart.zip (813 Bytes)

@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-56

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(3);

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 = aspose.slides.ChartType.StackedColumn;

        ['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] }, {name: 'series2', values: [1, 2, 3, 4]}, {name: 'series3', values: [1, 2, 3, 4]}].forEach((ele, seriesIndex) => {
        chart
            .getChartData()
            .getSeries()
            .add(fact.getCell(0, 0, seriesIndex + 1, ele.name), columnType);
        series = chart.getChartData().getSeries().get_Item(seriesIndex);
        ele.values.forEach((value, valueIndex) => series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, valueIndex + 1, seriesIndex + 1, value)));
    });

    chart.getChartData().getSeries().get_Item(0).getParentSeriesGroup().setOverlap(java.newByte(100));
    }
};

pres.save("output.pptx", aspose.slides.SaveFormat.Pptx);

Thank you. The issue has been resolved. This setOverlap method fixed the issue.

@karanmarsh,
We are glad to know that the issue has been resolved on your end. Thank you for using Aspose.Slides.