Creating an Aspose Program to Plot Dual Axis Combo Chart in PPT in Java

Hi team,
We have a requirement of creating a dualaxis combo chart in ppt
DualAxisComboChart.zip (38.7 KB)

.
1st series should be of stacked area chart on primary axis
2nd should of stacked bar on primary axis
3rd series of line with markers, on the secondary axis
I’m attaching the sample ppt here.

Thanks!

@VaradS,
Thank you for contacting support. I am working on the issue and will get back to you soon.

Thanks @andrey.potapov

@VaradS,
Thank you for your patience. Unfortunately, I was not able to create the exact same chart you provided.

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-39509

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.

@andrey.potapov ,
Thanks for looking into my query. Could you please describe the issue you get when you are trying to create same chart as I provided?

@VaradS,
I was unable to move the secondary vertical axis to the right, remove minor grid lines, and set a gap before the first and last columns. Our developers will investigate the case, and we will answer you soon.

Thanks for the reply @andrey.potapov .
To understand more and to confirm whether I’m also facing same issue due to aspose behavior. I have attached PPT file here where the first column is starting before Y axis. Also in few scenarios issue with last column, it ends beyond secondary Y axis.
DualAxisCombo.zip (39.1 KB)

@VaradS,
If this chart is created using Aspose.Slides, could you please show a code example that created it?

@VaradS,
Regarding your first message, please try using the following code snippet:

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

IChart chart = createStackedAreaChart(slide);
addStackedColumnChart(chart);
addLineChart(chart);
applyStyles(chart);

presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();
private static IChart createStackedAreaChart(ISlide slide)
{
    IChart chart = slide.getShapes().addChart(ChartType.StackedArea, 50, 50, 600, 400);
    chart.getChartData().getSeries().clear();
    chart.getChartData().getCategories().clear();

    chart.getLegend().setPosition(LegendPositionType.Bottom);

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

    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 1, 0, "Category 1"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 2, 0, "Category 2"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 3, 0, "Category 3"));
    chart.getChartData().getCategories().add(workbook.getCell(worksheetIndex, 4, 0, "Category 4"));

    IChartSeries series = chart.getChartData().getSeries().add(workbook.getCell(worksheetIndex, 0, 1, "Series 1"), chart.getType());

    series.getDataPoints().addDataPointForAreaSeries(workbook.getCell(worksheetIndex, 1, 1, 4.3));
    series.getDataPoints().addDataPointForAreaSeries(workbook.getCell(worksheetIndex, 2, 1, 2.5));
    series.getDataPoints().addDataPointForAreaSeries(workbook.getCell(worksheetIndex, 3, 1, 3.5));
    series.getDataPoints().addDataPointForAreaSeries(workbook.getCell(worksheetIndex, 4, 1, 4.5));

    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(21, 96, 130));

    return chart;
}

private static void addStackedColumnChart(IChart chart)
{
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;

    IChartSeries series = chart.getChartData().getSeries().add(workbook.getCell(worksheetIndex, 0, 2, "Series 2"), ChartType.StackedColumn);

    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 1, 2, 2.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 2, 2, 4.4));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 3, 2, 1.8));
    series.getDataPoints().addDataPointForBarSeries(workbook.getCell(worksheetIndex, 4, 2, 2.8));

    series.getParentSeriesGroup().setOverlap((byte)100);
    series.getParentSeriesGroup().setGapWidth(219);
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(233, 113, 50));
}

private static void addLineChart(IChart chart)
{
    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    final int worksheetIndex = 0;

    IChartSeries series = chart.getChartData().getSeries().add(workbook.getCell(worksheetIndex, 0, 3, "Series 3"), ChartType.Line);

    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 1, 3, 2));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 2, 3, 2));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 3, 3, 3));
    series.getDataPoints().addDataPointForLineSeries(workbook.getCell(worksheetIndex, 4, 3, 5));

    series.setPlotOnSecondAxis(true);
    series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(25, 107, 36));

    chart.getAxes().getSecondaryVerticalAxis().setTickLabelPosition(TickLabelPositionType.High);
}

private static void applyStyles(IChart chart)
{
    //Chart title
    chart.setTitle(true);
    chart.getChartTitle().setOverlay(false);
    ITextFrame chartTitle = chart.getChartTitle().addTextFrameForOverriding("Chart Title");
    IPortionFormat portionFormat = chartTitle.getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat();
    portionFormat.setFontHeight(18.6f);
    portionFormat.setFontBold(NullableBool.False);
    portionFormat.setLatinFont(new FontData("Aptos"));
    portionFormat.getFillFormat().setFillType(FillType.Solid);
    portionFormat.getFillFormat().getSolidFillColor().setColor(new Color(89, 89,89));

    //Axis styles
    chart.getAxes().getHorizontalAxis().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getHorizontalAxis().setMajorTickMark(TickMarkType.None);
    chart.getAxes().getHorizontalAxis().setAxisBetweenCategories(true);

    chart.getAxes().getSecondaryHorizontalAxis().setVisible(false);
    chart.getAxes().getSecondaryHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getSecondaryHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    chart.getAxes().getVerticalAxis().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getVerticalAxis().setMajorTickMark(TickMarkType.None);
    chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(new Color(217, 217, 217));

    chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getSecondaryVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
    chart.getAxes().getSecondaryVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);

    setTextFormatForAxis(chart.getAxes().getHorizontalAxis());
    setTextFormatForAxis(chart.getAxes().getVerticalAxis());
    setTextFormatForAxis(chart.getAxes().getSecondaryVerticalAxis());

    //Series styles
    chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(12);
    chart.getLegend().getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));
    chart.getLegend().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    chart.getLegend().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(89, 89,89));
}

private static void setTextFormatForAxis(IAxis value)
{
    value.getTextFormat().getPortionFormat().setFontHeight(12);
    value.getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));
    value.getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    value.getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(89, 89,89));
}

Create or Update PowerPoint Presentation Charts in Java|Aspose.Slides Documentation