Creating chart in pptx: Column/Bar series color is not applied if generated with negative axis

Hi there,


Using the below sample code I am creating a chart and saving the new presentation out to disk.I am using 15.9.0.0 version of Aspose.slides for .Net.
Problem:
Column/Bar series color is not applied when chart contains series with negative axis(Please see attached “IssueRedEncircled.png”).

Please check the below code:

private void CreatePPTXChartWithNegativeAxis()
{
//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);

//Setting chart Title
// chart.ChartTitle.TextFrameForOverriding.Text = “Sample Title”;
chart.ChartTitle.AddTextFrameForOverriding(“Sample Title”);
chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = Aspose.Slides.NullableBool.True;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;

//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”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “Series 2”), chart.Type);

//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.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, -50));
series.DataPoints.AddDataPointForBarSeries(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.Red;


//Take second chart series
series = chart.ChartData.Series[1];

//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, -60));

//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 = “/”;



//Save presentation with chart
pres.Save(“AsposeChart.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);
}

Hi Pradeep,

I have observed your requirements and like to share that when chart series contains negative values, it gets inverted. You need to explicitly set InvertIfNegative value to false with series. Please use the following sample code on your end to serve the purpose.

series.InvertIfNegative = false;


Many Thanks,