We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Stacked Columns- Colour individual datapoints

I’m having trouble colouring datapoints within a stacked column.

Its possible in powerpoint, so hoping there’s a simple solution,

Here’s an example of what im trying.

//Instantiate Presentation class that represents PPTX file//Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();

//Access first slide
ISlide sld = pres.Slides[0];

// Add chart with default data
IChart chart = sld.Shapes.AddChart(ChartType.StackedColumn, 0, 0, 500, 500);

//Setting chart Title
// chart.ChartTitle.TextFrameForOverriding.Text = “Sample Title”;
chart.ChartTitle.AddTextFrameForOverriding(“Sample Title”);
chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = 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
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
IChartSeries series = chart.ChartData.Series[0];

//Now populating series data

series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#006A4D");
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#FF9933");
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#666666");

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

//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#FF0000");
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#CC99FF");
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#00B050");

//create custom labels for each of categories for new series
IChartSeriesCollection series2 = chart.ChartData.Series;
if (series2[0].Overlap == 0)
{
series2[0].ParentSeriesGroup.Overlap = 100;
}
//first label will be show Category name
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 = “/”;


pres.Save(“AsposeChart.pptx”, Aspose.Slides.Export.SaveFormat.Pptx, HttpContext.Current.Response, false);

Hi Pete,


Thank you for your interest in Aspose.Slides.

I have observed your comments and like to request you to please share with us a sample presentation created using PowerPoint which explains your requirements so that I may try to help you out as per your requirements.

Best Regards,

Hi


Each datapoint needs to be a different colour, my example shows a different colour being added with each datapoint. like this
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)).Format.Fill.SolidFillColor.Color = ColorTranslator.FromHtml("#006A4D");

So every series and category needs to have a different colour.

Once in powerpoint i can colour each datapoint.

Thanks

Hi Pete,


I have observed your comments and like to request you once again to please share with us a presentation file created using PowerPoint so that we can try to provide you code sample as per your requirements. I will proceed further once the requested information is shared by you.

Best Regards,

Hi,

Attached is the presentation file from the above code, with my extra edits once in PowerPoint which I would like to be able to achieve using slides.

Thanks

Hi Pete,


Thank you for sharing the file with us.

I have observed your requirements and like to request you to please try using following sample code on your end to serve the purpose.

IChartDataPoint point = series.DataPoints[0];
point.Format.Fill.FillType = FillType.Solid;
point.Format.Fill.SolidFillColor.Color = Color.Green;

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

Best Regards,

Hi

Thanks for the idea. I think we’re getting close.
I need to get the datapoint index of the last added then i think your code will work.

So if I set the data point like this.
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1,26));
How can I find that index and then i should be able to use the code below.
IChartDataPoint point = series.DataPoints[0]; //
point.Format.Fill.FillType = FillType.Solid;
point.Format.Fill.SolidFillColor.Color = Color.Green;

Thanks

Hi Pete,


I have observed your comments and like to share with you that there is not any method or property which stores the information about recently added datapoint however you can know about the last data point as in the below code.

int i = series.DataPoints.Count();
IChartDataPoint point = series.DataPoints[i-1];

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

Best Regards,

Thanks. That’s solved it.


Cheers

Hi Pete,


Thank you for your valuable feedback.

We are glad know things have started working on your end. Please feel free to contact us if we could be of any help to you.

Best Regards,