PPTX Chart: Chart Series are displayed upside down when Chart Series is combination of Line + Column

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

Hi Pradeep,

Thank you for posting.

I have observed your comments and like to share with you that the chart is appearing upside down because the chart series are being plotted on secondary axis, do you want it the same or below code satisfies your requirements. I have also attached the generated presentation for your kind reference (see AsposeChartLinePlusColumn.pptx), in which the chart is not upside down, and the series are filled as well. I request you to please try using Aspose.Slides for .NET 15.10.0 and the code below, then share your kind feedback with us.

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

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

//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.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.HorizontalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = Aspose.Slides.FillType.NoFill;

//Save presentation with chart
pres.Save("AsposeChartLinePlusColumn.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

Please let us know if the issue persists. We will be happy to assist you further.

Best Regards,

Hi Adnan,

Thank you for quick reply.

As per my requirements, Line series has to be plotted on primary Y axis and column series has to be plotted on secondary Y axis and it has to be the same way.However the chart is not upside down and the series are filled as well when column series are being plotted on primary Y axis and Line series are being plotted on secondary Y axis.

So the issue still persists. Please look into this.

Hi Pradeep,

I have observed your comments and like to request you to please try using following sample code, where I have set the InvertIfNegative property for the series, on your end and then share your kind feedback with us. The series are filled with color as expected. Line series is plotted on primary axis and column series is plotted on secondary axis.

//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;
series.InvertIfNegative = false;

//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;
series.InvertIfNegative = false;

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

If this does not satisfies your requirements then please share with us a presentation file after making necessary changes to the chart using PowerPoint, as expected output, so that we may try to help you further.

Best Regards,

Hi Adnan,

Thank you for your reply.

On setting InvertIfNegative property to false for the series,the series are filled with color as expected but Column chart serieses are still being plotted upside down (Line series is plotted on primary axis and column series is plotted on secondary axis).

So I am attaching a presentation file(AsposeChartLinePlusColumn.pptx) as expected output. Please look into that and try to help me further.

Hi Pradeep,

I have observed your comments and like to request you to add 2 lines of code in your program. Below is the code for your kind reference.

chart.Axes.SecondaryVerticalAxis.IsPlotOrderReversed = true;
chart.Axes.SecondaryHorizontalAxis.IsVisible = false;

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Thank you very much Adnan for your inputs. Its working now.

Hi Pradeep,

Thanks for your valuable feedback.

We are glad that your issue is resolved and things have started working at your end.

Please feel free to contact us if we can be of any help to you.

Best Regards,