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