Creating a StackedBar on aspose.slides

I would like to create a StackedBar on aspose.slides. Which should have 2 categories in a stacked bar chart. one category is benchmark value. other category should have 3 series together to benchmark.

category1: myTotalIncome bar, 1000$
category2: fixedIncome(200$), largecap( 500$), cash(300$) where as fixedIncome, largecap, cash are series1, series2, series3.

Can some one help me with sample code…

I wrote below and its not fitting the requirement.

// Creating the default chart
IChart chart = slide.getShapes().addChart(ChartType.StackedBar, 20, 20, 400, 400);

    int defaultWorksheetIndex = 0;

    // Getting the chart data WorkSheet
    IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

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



    //categories
    chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Income"));

    // Adding new series
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"),chart.getType());

    // Take first chart series
    IChartSeries series = chart.getChartData().getSeries().get_Item(0);

    //Now populating series data
   series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 25));

    // Setting fill color for series
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(158,143,108));


    //---------------
    // Adding new series
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 2, 1, "Series 2"),chart.getType());

    // Take first chart series
    series = chart.getChartData().getSeries().get_Item(1);

    //Now populating series data
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 20));

    // Setting fill color for series
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(150,143,108));

    //---------------
    // Adding new series
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 3, 1, "Series 3"),chart.getType());

    // Take first chart series
    series = chart.getChartData().getSeries().get_Item(2);

    //Now populating series data
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 25));

    // Setting fill color for series
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(new Color(140,123,118));


    presentation.save("C:\\\\git\\generic\\" + "BarChart.pptx", SaveFormat.Pptx);

@trishul14,

I have observed your comments. I like to inform that you need to fill all series data for each chart series. I have shared sample code with you. This will help you to achieve your requirements. Also please visit this linkChart.zip (571 Bytes). This will also help you out. Please share feedback with us if there is still an issue.

I have looked at that, but I am getting the char like attached image, but i am looking for the series in one liner. Series 2 should follow series 1 and series 3 should follow series 2. currentChart.PNG (3.1 KB)
expectedChart.PNG (539 Bytes)

I think I got the issue, I have to add overlap property…Is n’t it?

IChartSeriesCollection seriesColl = chart.getChartData().getSeries();
if (seriesColl.get_Item(0).getOverlap() == 0) {
// Setting series overlap
seriesColl.get_Item(0).getParentSeriesGroup().setOverlap((byte) 100);
}

@trishul14,

I have shared complete code snippet with you. Can you please check this and share your feedback with us if there is still an issue.code snippet.zip (753 Bytes)