Hi there,
I am creating a pptx file that contains a single chart using Aspose.Slides for .Net 15.9.0.0.
Chart is a combination of Line and Column Series where Line series is plotted on primary Y and Column series are plotted on Secondary Y.
Issue:
Chart series are displayed upside down and series are not filled with colours too. (Please see attached “UpsidedownChartSeries.png”).
Please check the below code:
private void CreatePPTXChartLinePlusColumn()
{
//Instantiate Presentation class that represents PPTX file//Instantiate Presentation class that represents PPTX file
Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation();
//Access first slide
Aspose.Slides.ISlide sld = pres.Slides[0];
// Add chart with default data
Aspose.Slides.Charts.IChart chart = sld.Shapes.AddChart(Aspose.Slides.Charts.ChartType.ClusteredColumn, 0, 0, 500, 500);
//Set first series to Show Values
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
Aspose.Slides.Charts.IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, “Series 1”), Slides.Charts.ChartType.LineWithMarkers);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “Series 2”), Slides.Charts.ChartType.ClusteredColumn);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, “Series 3”), Slides.Charts.ChartType.ClusteredColumn);
//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));
//Take first chart series
Aspose.Slides.Charts.IChartSeries series = chart.ChartData.Series[0];
//Now populating series data
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
//Setting fill color for series
series.Format.Fill.FillType = Aspose.Slides.FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.YellowGreen;
//Take second chart series
series = chart.ChartData.Series[1];
//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 200));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 500));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 300));
//Setting fill color for series
series.Format.Fill.FillType = Aspose.Slides.FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Red;
series.PlotOnSecondAxis = true;
//Take third chart series
series = chart.ChartData.Series[2];
//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 3, 450));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 320));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 700));
//Setting fill color for series
series.Format.Fill.FillType = Aspose.Slides.FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;
series.PlotOnSecondAxis = true;
//create custom labels for each of categories for new series
//first label will be show Category name
Aspose.Slides.Charts.IDataLabel lbl = series.DataPoints[0].Label;
lbl.DataLabelFormat.ShowCategoryName = true;
lbl = series.DataPoints[1].Label;
lbl.DataLabelFormat.ShowSeriesName = true;
//Show value for third label
lbl = series.DataPoints[2].Label;
lbl.DataLabelFormat.ShowValue = true;
lbl.DataLabelFormat.ShowSeriesName = true;
lbl.DataLabelFormat.Separator = "/";
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.SecondaryVerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.HorizontalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.SecondaryVerticalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.SecondaryHorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.SecondaryHorizontalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
//Save presentation with chart
pres.Save("AsposeChartLinePlusColumn.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}