Need a Sample Code to Create a PowerPoint Combination Chart in Java

I have a combination chart of stacked column, line with markers on the primary axis and cluster column on the secondary axis.
Fact2LegendNotVisible.zip (37.8 KB)
please refer the attached ppt file and provide the code.

@VaradS,
Thank you for contacting free support. I am working on your request. I will get back to you when the code example is ready.

@VaradS,
Thank you for your patience. Please try using the following code example:

Presentation presentation = new Presentation();
presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.EnsureFit);

ISlide slide = presentation.getSlides().get_Item(0);

IChart chart = addStackedColumnChart(slide);
addLineWithMarkersChart(chart);
addClusteredColumnChart(chart);

configureHorizontalAxis(chart.getAxes().getHorizontalAxis());
configureVerticalAxis(chart.getAxes().getVerticalAxis());
configureSecondaryHorizontalAxis(chart.getAxes().getSecondaryHorizontalAxis());
configureSecondaryVerticalAxis(chart.getAxes().getSecondaryVerticalAxis());

configurePlotArea(chart.getPlotArea());
configureChartLegend(chart.getLegend());

chart.getChartData().setRange("Sheet1!$A$1:$D$18");
hideChartZeroValues(chart);

presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();
static IChart addStackedColumnChart(ISlide slide) {
    IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 28.5f, 101f, 902.5f, 355f);

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

    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 1;

    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 1, 0, "ABC"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 2, 0, "DEF"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 3, 0, "XYZ"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 4, 0, "RST"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 5, 0, "MNO"));

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 1"), ChartType.StackedColumn);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 16.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 6.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 2.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 2.3));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(103, 88, 149));

    series.getParentSeriesGroup().setOverlap((byte) 100);
    series.getParentSeriesGroup().setGapWidth(40);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    return chart;
}

static void addLineWithMarkersChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 2;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 2"), ChartType.LineWithMarkers);

    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 75.6));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 81.9));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 84.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 86.7));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getMarker().setSymbol(MarkerStyleType.Circle);
    series.getMarker().setSize(5);
    series.getMarker().getFormat().getFill().setFillType(FillType.Solid);
    series.getMarker().getFormat().getFill().getSolidFillColor().setColor(new Color(70, 151, 226));
    series.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getMarker().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
}

static void addClusteredColumnChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 3;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 3"), ChartType.ClusteredColumn);

    series.setPlotOnSecondAxis(true);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 52.8));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 41.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 29.0));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 24.6));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.NoFill);
    series.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    series.getParentSeriesGroup().setOverlap((byte) -100);
    series.getParentSeriesGroup().setGapWidth(320);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(211, 211, 211));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(19, 130, 56));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.InsideBase);

    series.getRelatedLegendEntry().setHide(true);
}

static void configureHorizontalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureVerticalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.setNumberFormatLinkedToSource(false);
    axis.setNumberFormat("#,##0.0\\%");

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureSecondaryHorizontalAxis(IAxis axis) {
    axis.setVisible(false);

    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}

static void configureSecondaryVerticalAxis(IAxis axis) {
    axis.setVisible(false);
    axis.setPlotOrderReversed(true);
    axis.setCrossType(CrossesType.Maximum);

    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}

static void configurePlotArea(IChartPlotArea plotArea) {
    plotArea.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    plotArea.getFormat().getLine().setDashStyle(LineDashStyle.Dot);
}

static void configureChartLegend(ILegend legend) {
    legend.setPosition(LegendPositionType.Bottom);

    legend.getTextFormat().getPortionFormat().setFontHeight(13);
    legend.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    legend.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    legend.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(102, 102, 102));
}

static void setSeriesDataFormat(IChartDataWorkbook workbook, int worksheetIndex, int columnIndex, int pointCount) {
    final String format = "#,##0.0\\%";

    for (int i = 0; i < pointCount; i++) {
        int rowIndex = 1 + i;
        workbook.getCell(worksheetIndex, rowIndex, columnIndex).setCustomNumberFormat(format);
    }
}

static void hideChartZeroValues(IChart chart) {
    for (IChartSeries series : chart.getChartData().getSeries()) {
        for (int i = 0; i < series.getDataPoints().size(); i++) {
            IChartDataPoint dataPoint = series.getDataPoints().get_Item(i);

            if (Double.isNaN(dataPoint.getValue().toDouble())) {
                dataPoint.getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                dataPoint.getMarker().getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                series.getLabels().get_Item(i).hide();
            }
        }
    }
}

output.zip (33.1 KB)

PowerPoint Charts|Aspose.Slides Documentation

Hi @andrey.potapov ,

Thanks for sharing the code snippet.

As per the code, you have tried to hide the fact 3 which is clustered Column chart

But when I try to generate the ppt file out of the code, I see Fact3 legend is visible but without the legend symbol. Also Fact2 is missing in the legend.

image.png (57.6 KB)

image.png (69.3 KB)

Could you please check and update why Fact 2 legend is hidden instead of Fact 3 ?

cc @VaradS

Thanks,
Thilak Babu

@VaradS,
Thank you for the note. I’ve reproduced the problem of hiding the wrong chart legend entry.

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): SLIDESJAVA-39651

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.

@Thilakbabu,
Our developers have investigated the case. This issue is related to PowerPoint and how it handles legend entries when each series creates its own chart. I triggered this behavior indirectly by adding new series of different types and using setPlotOnSecondAxis(true).

If you need precise control over the display, it’s better not to use the setPlotOnSecondAxis method in a combo chart. Doing so causes PowerPoint to split the combo chart into multiple individual charts, which in turn leads to display issues—such as those we’re currently observing.

To resolve this problem, you can first add all column series (which effectively groups them), then add the line series, and set the series order accordingly. In most cases, this approach resolves the issue.

Presentation presentation = new Presentation();
presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.EnsureFit);

ISlide slide = presentation.getSlides().get_Item(0);

IChart chart = addStackedColumnChart(slide);
addClusteredColumnChart(chart);
addLineWithMarkersChart(chart);

configureHorizontalAxis(chart.getAxes().getHorizontalAxis());
configureVerticalAxis(chart.getAxes().getVerticalAxis());
configureSecondaryHorizontalAxis(chart.getAxes().getSecondaryHorizontalAxis());
configureSecondaryVerticalAxis(chart.getAxes().getSecondaryVerticalAxis());

configurePlotArea(chart.getPlotArea());
configureChartLegend(chart.getLegend());

chart.getChartData().setRange("Sheet1!$A$1:$D$18");
hideChartZeroValues(chart);

presentation.save("output_new.pptx", SaveFormat.Pptx);
presentation.dispose();
static IChart addStackedColumnChart(ISlide slide) {
    IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 28.5f, 101f, 902.5f, 355f);

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

    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 1;

    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 1, 0, "ABC"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 2, 0, "DEF"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 3, 0, "XYZ"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 4, 0, "RST"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 5, 0, "MNO"));

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 1"), ChartType.StackedColumn);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 16.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 6.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 2.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 2.3));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(103, 88, 149));

    series.getParentSeriesGroup().setOverlap((byte) 100);
    series.getParentSeriesGroup().setGapWidth(40);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    series.setOrder(0);

    return chart;
}

static void addLineWithMarkersChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 3;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 2"), ChartType.LineWithMarkers);

    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 75.6));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 81.9));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 84.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 86.7));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getMarker().setSymbol(MarkerStyleType.Circle);
    series.getMarker().setSize(5);
    series.getMarker().getFormat().getFill().setFillType(FillType.Solid);
    series.getMarker().getFormat().getFill().getSolidFillColor().setColor(new Color(70, 151, 226));
    series.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getMarker().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    series.setOrder(1);
}

static void addClusteredColumnChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 2;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 3"), ChartType.ClusteredColumn);

    series.setPlotOnSecondAxis(true);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 52.8));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 41.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 29.0));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 24.6));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.NoFill);
    series.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    series.getParentSeriesGroup().setOverlap((byte) -100);
    series.getParentSeriesGroup().setGapWidth(320);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(211, 211, 211));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(19, 130, 56));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.InsideBase);

    series.getRelatedLegendEntry().setHide(true);

    series.setOrder(2);
}

static void configureHorizontalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureVerticalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.setNumberFormatLinkedToSource(false);
    axis.setNumberFormat("#,##0.0\\%");

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureSecondaryHorizontalAxis(IAxis axis) {
    axis.setVisible(false);

    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}

static void configureSecondaryVerticalAxis(IAxis axis) {
    axis.setVisible(false);
    axis.setPlotOrderReversed(true);
    axis.setCrossType(CrossesType.Maximum);

    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}

static void configurePlotArea(IChartPlotArea plotArea) {
    plotArea.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    plotArea.getFormat().getLine().setDashStyle(LineDashStyle.Dot);
}

static void configureChartLegend(ILegend legend) {
    legend.setPosition(LegendPositionType.Bottom);

    legend.getTextFormat().getPortionFormat().setFontHeight(13);
    legend.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    legend.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    legend.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(102, 102, 102));
}

static void setSeriesDataFormat(IChartDataWorkbook workbook, int worksheetIndex, int columnIndex, int pointCount) {
    final String format = "#,##0.0\\%";

    for (int i = 0; i < pointCount; i++) {
        int rowIndex = 1 + i;
        workbook.getCell(worksheetIndex, rowIndex, columnIndex).setCustomNumberFormat(format);
    }
}

static void hideChartZeroValues(IChart chart) {
    for (IChartSeries series : chart.getChartData().getSeries()) {
        for (int i = 0; i < series.getDataPoints().size(); i++) {
            IChartDataPoint dataPoint = series.getDataPoints().get_Item(i);

            if (Double.isNaN(dataPoint.getValue().toDouble())) {
                dataPoint.getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                dataPoint.getMarker().getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                series.getLabels().get_Item(i).hide();
            }
        }
    }
}

However, we suggest not using PlotOnSecondAxis in this case, as avoiding it will ensure the correct result. Please check the following code snippet:

Presentation presentation = new Presentation();
presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.EnsureFit);

ISlide slide = presentation.getSlides().get_Item(0);

IChart chart = addStackedColumnChart(slide);
addLineWithMarkersChart(chart);
addClusteredColumnChart(chart);

configureHorizontalAxis(chart.getAxes().getHorizontalAxis());
configureVerticalAxis(chart.getAxes().getVerticalAxis());

configurePlotArea(chart.getPlotArea());
configureChartLegend(chart.getLegend());

chart.getChartData().setRange("Sheet1!$A$1:$D$18");
hideChartZeroValues(chart);

presentation.save("output_new.pptx", SaveFormat.Pptx);
presentation.dispose();
static IChart addStackedColumnChart(ISlide slide) {
    IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 28.5f, 101f, 902.5f, 355f);

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

    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 1;

    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 1, 0, "ABC"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 2, 0, "DEF"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 3, 0, "XYZ"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 4, 0, "RST"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 5, 0, "MNO"));

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 1"), ChartType.StackedColumn);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 16.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 6.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 2.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 2.3));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(103, 88, 149));

    series.getParentSeriesGroup().setOverlap((byte) 100);
    series.getParentSeriesGroup().setGapWidth(40);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    return chart;
}

static void addLineWithMarkersChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 2;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 2"), ChartType.LineWithMarkers);

    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 75.6));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 81.9));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 84.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 86.7));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getMarker().setSymbol(MarkerStyleType.Circle);
    series.getMarker().setSize(5);
    series.getMarker().getFormat().getFill().setFillType(FillType.Solid);
    series.getMarker().getFormat().getFill().getSolidFillColor().setColor(new Color(70, 151, 226));
    series.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getMarker().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
}

static void addClusteredColumnChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 3;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 3"), ChartType.ClusteredColumn);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 52.8));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 41.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 29.0));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 24.6));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.NoFill);
    series.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    series.getParentSeriesGroup().setOverlap((byte) -100);
    series.getParentSeriesGroup().setGapWidth(320);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(211, 211, 211));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(19, 130, 56));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.InsideBase);

    series.getRelatedLegendEntry().setHide(true);

    chart.validateChartLayout();

    float pixDifference = series.getLabels().get_Item(0).getActualY() - chart.getFrame().getX();
    float fraction = pixDifference / chart.getHeight();

    for (IDataLabel label : series.getLabels()) {
        label.setX(0.0f);
        label.setY(-fraction);
    }
}

static void configureHorizontalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureVerticalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.setNumberFormatLinkedToSource(false);
    axis.setNumberFormat("#,##0.0\\%");

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configurePlotArea(IChartPlotArea plotArea) {
    plotArea.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    plotArea.getFormat().getLine().setDashStyle(LineDashStyle.Dot);
}

static void configureChartLegend(ILegend legend) {
    legend.setPosition(LegendPositionType.Bottom);

    legend.getTextFormat().getPortionFormat().setFontHeight(13);
    legend.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    legend.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    legend.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(102, 102, 102));
}

static void setSeriesDataFormat(IChartDataWorkbook workbook, int worksheetIndex, int columnIndex, int pointCount) {
    final String format = "#,##0.0\\%";

    for (int i = 0; i < pointCount; i++) {
        int rowIndex = 1 + i;
        workbook.getCell(worksheetIndex, rowIndex, columnIndex).setCustomNumberFormat(format);
    }
}

static void hideChartZeroValues(IChart chart) {
    for (IChartSeries series : chart.getChartData().getSeries()) {
        for (int i = 0; i < series.getDataPoints().size(); i++) {
            IChartDataPoint dataPoint = series.getDataPoints().get_Item(i);

            if (Double.isNaN(dataPoint.getValue().toDouble())) {
                dataPoint.getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                dataPoint.getMarker().getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                series.getLabels().get_Item(i).hide();
            }
        }
    }
}

Hi @andrey.potapov ,

Thanks for your inputs.

But we have a requirement to have the clustered column chart in secondary axis.

We have a similar implementation using Aspose cells as well in Microsoft Excel.

image.png (64.8 KB)

Attaching the excel file for your reference

Labels-chart.zip (11.7 KB)

So what I mean here is, using Aspose Cell, we are able to see the legends symbol for Line chart properly but only for Aspose Slides, the line chart symbol is being missed.

Could you please help us resolve this issue in Aspose slides even with using the “plot on secondary axis” ?

Thanks,
Thilak

@Thilakbabu,
I need some time to answer your question. I will get back to you as soon as possible.

1 Like

@Thilakbabu,
Thank you for your patience.

In this case, you should use the first solution from the post above. You only need to remove the following line of code:

series.getRelatedLegendEntry().setHide(true);

@andrey.potapov ,
Thanks for your reply.
Removing this line causes the fact3 series to remain visible in the legend, which is not the desired behavior.
We expect it to function the same way as it does in Excel. (provided above by @Thilakbabu )

@VaradS,
If you want to hide the second series (Fact 2), you can add that code line to the addLineWithMarkersChart method.

Hi @andrey.potapov

Thanks for the reply!

The requirement is to have Stacked bar and Line chart in primary axis and invisible clustered column chart in the secondary axis.

Also, we want the invisible clustered column chart legend to be hidden.

While trying to do this, we are seeing Line chart’s legend symbol is missing. But this works perfectly fine in Excel… only in PPT, this does not work.

Please help us resolve this issue without altering our requirement.

cc @VaradS

Thanks,
Thilak Babu

@Thilakbabu,
Thank you for the clarification. I am working on the issue and will get back to you soon.

1 Like

@Thilakbabu,
I’ve carefully reviewed and executed the first code example from the post above, and the result aligns with your requirements:

  • The Stacked Column chart and Line chart are on the primary axis.
  • The Clustered Column chart is on the secondary axis.
  • The legend for the Clustered Column chart entry is invisible.

Code example:

Presentation presentation = new Presentation();
presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.EnsureFit);

ISlide slide = presentation.getSlides().get_Item(0);

IChart chart = addStackedColumnChart(slide);
addClusteredColumnChart(chart);
addLineWithMarkersChart(chart);

configureHorizontalAxis(chart.getAxes().getHorizontalAxis());
configureVerticalAxis(chart.getAxes().getVerticalAxis());
configureSecondaryHorizontalAxis(chart.getAxes().getSecondaryHorizontalAxis());
configureSecondaryVerticalAxis(chart.getAxes().getSecondaryVerticalAxis());

configurePlotArea(chart.getPlotArea());
configureChartLegend(chart.getLegend());

chart.getChartData().setRange("Sheet1!$A$1:$D$18");
hideChartZeroValues(chart);

presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();
static IChart addStackedColumnChart(ISlide slide) {
    IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 28.5f, 101f, 902.5f, 355f);

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

    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 1;

    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 1, 0, "ABC"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 2, 0, "DEF"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 3, 0, "XYZ"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 4, 0, "RST"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 5, 0, "MNO"));

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 1"), ChartType.StackedColumn);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 16.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 6.2));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 2.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 2.3));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(103, 88, 149));

    series.getParentSeriesGroup().setOverlap((byte) 100);
    series.getParentSeriesGroup().setGapWidth(40);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    series.setOrder(0);

    return chart;
}

static void addLineWithMarkersChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 3;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 2"), ChartType.LineWithMarkers);

    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 75.6));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 81.9));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 84.4));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 86.7));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getMarker().setSymbol(MarkerStyleType.Circle);
    series.getMarker().setSize(5);
    series.getMarker().getFormat().getFill().setFillType(FillType.Solid);
    series.getMarker().getFormat().getFill().getSolidFillColor().setColor(new Color(70, 151, 226));
    series.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getMarker().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(70, 151, 226));

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(89, 89, 89));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    series.setOrder(1);
}

static void addClusteredColumnChart(IChart chart) {
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;
    final int seriesColumnIndex = 2;

    IChartSeries series = chart.getChartData().getSeries().add(
            workbook.getCell(worksheetIndex, 0, seriesColumnIndex, "Fact 3"), ChartType.ClusteredColumn);

    series.setPlotOnSecondAxis(true);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, seriesColumnIndex, 59.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, seriesColumnIndex, 52.8));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, seriesColumnIndex, 41.6));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, seriesColumnIndex, 29.0));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 5, seriesColumnIndex, 24.6));

    setSeriesDataFormat(workbook, worksheetIndex, seriesColumnIndex, series.getDataPoints().size());

    series.getFormat().getFill().setFillType(FillType.NoFill);
    series.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    series.getParentSeriesGroup().setOverlap((byte) -100);
    series.getParentSeriesGroup().setGapWidth(320);

    series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().setWidth(0.75);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(211, 211, 211));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(19, 130, 56));
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(10);
    series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.InsideBase);

    series.getRelatedLegendEntry().setHide(true);

    series.setOrder(2);
}

static void configureHorizontalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureVerticalAxis(IAxis axis) {
    axis.getFormat().getLine().setWidth(2);
    axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

    axis.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    axis.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(21, 25, 33));
    axis.getTextFormat().getPortionFormat().setFontHeight(10);
    axis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));

    axis.setMajorTickMark(TickMarkType.None);

    axis.setNumberFormatLinkedToSource(false);
    axis.setNumberFormat("#,##0.0\\%");

    axis.getMajorGridLinesFormat().getLine().setWidth(1);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    axis.getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(229, 229, 229));
}

static void configureSecondaryHorizontalAxis(IAxis axis) {
    axis.setVisible(false);

    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}

static void configureSecondaryVerticalAxis(IAxis axis) {
    axis.setVisible(false);
    axis.setPlotOrderReversed(true);
    axis.setCrossType(CrossesType.Maximum);

    axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}

static void configurePlotArea(IChartPlotArea plotArea) {
    plotArea.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    plotArea.getFormat().getLine().setDashStyle(LineDashStyle.Dot);
}

static void configureChartLegend(ILegend legend) {
    legend.setPosition(LegendPositionType.Bottom);

    legend.getTextFormat().getPortionFormat().setFontHeight(13);
    legend.getTextFormat().getPortionFormat().setLatinFont(new FontData("Arial"));
    legend.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    legend.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(102, 102, 102));
}

static void setSeriesDataFormat(IChartDataWorkbook workbook, int worksheetIndex, int columnIndex, int pointCount) {
    final String format = "#,##0.0\\%";

    for (int i = 0; i < pointCount; i++) {
        int rowIndex = 1 + i;
        workbook.getCell(worksheetIndex, rowIndex, columnIndex).setCustomNumberFormat(format);
    }
}

static void hideChartZeroValues(IChart chart) {
    for (IChartSeries series : chart.getChartData().getSeries()) {
        for (int i = 0; i < series.getDataPoints().size(); i++) {
            IChartDataPoint dataPoint = series.getDataPoints().get_Item(i);

            if (Double.isNaN(dataPoint.getValue().toDouble())) {
                dataPoint.getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                dataPoint.getMarker().getFormat().getFill().setFillType(FillType.NoFill);
                dataPoint.getMarker().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

                series.getLabels().get_Item(i).hide();
            }
        }
    }
}

files.zip (231.4 KB)

Could you please check the result and clarify what is wrong?

Hi @andrey.potapov

I was going over the code snippet shared by you.

I see you have changed the order of method invocation

image.png (10.6 KB)

We always have to render the charts which are in primary axis first followed by secondary axis charts, so the order of invocation should be
1 → addStackedColumnChart(slide);
2 → addLineWithMarkersChart(chart);
3 → addClusteredColumnChart(chart);

This way invocation works perfectly fine for Excel but for ppt only we are facing the issue of missing the line chart legend symbol

image.png (68.0 KB)

So , could you please help us resolve this issue without changing the order of method invocation ?

Thanks,
Thilak Babu

@Thilakbabu,
Thank you for the details. I need some time to answer your question. I will get back to you as soon as possible.

1 Like

Hi @andrey.potapov

Good day!

Just trying to follow up if you have any updates! Please keep us posted. Thanks.

@Thilakbabu,
We will keep you updated. Thank you for your patience.

Hi @andrey.potapov
If we could get an update on this it would be great. Please let us know if there are any updates from your side.

@devkapur,
The issue was scheduled to be investigated this week. Unfortunately, I don’t have any additional information yet. We will keep you updated.