@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