Horizontal Stacked Bar Chart

No specific set of data here: I’m just trying to create a regular horizontal stacked bar chart with some sample code (c# in asp.net) following this message.


The problem is the generated stacked bar chart has each of the segments differing in height in a staggered formation. In powerpoint, you can manually edit this output and set the overlap to 100% but I’m having trouble finding out you can do this here. Can someone point me in the right direction? Thank you.





Presentation pres = new Presentation(); // creates a blank presentation with one blank slide. must be done first
ISlide sld = pres.Slides[0]; // pres.Slides returns a list of slides in the presentation, sets sld to first slide
/* text
IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
ashp.AddTextFrame(" "); // adds text frame
ITextFrame txtFrame = ashp.TextFrame; // variable to access text frame
IParagraph para = txtFrame.Paragraphs[0]; // creates paragraph object for text frame
IPortion portion = para.Portions[0]; // creates portion object for paragraph
portion.Text = testString;
*/
// chart
IChart chart = sld.Shapes.AddChart(ChartType.ClusteredBar, 0, 0, 640, 480);
chart.ChartTitle.AddTextFrameForOverriding(“Clustered Bar Chart”);
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, “red key”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “green key”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, “blue key”), chart.Type);

//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “2014”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “2013”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “2012”));

//Take first chart series
IChartSeries series = chart.ChartData.Series[0];

//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 = 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, 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 = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;


series = chart.ChartData.Series[2];
//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 3, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 30));

//Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Blue;
//create custom labels for each of categories for new series

//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(“test”, Aspose.Slides.Export.SaveFormat.Pptx, Response, false);

Hi Bradley,

Thank you for sharing the sample code.

To understand your issue, please share your generated file and expected output file which you can create using MS PowerPoint. We will check it and get back to you soon.

Thanks & Regards,

The files are attached. The current chart it’s generating, current_output.pptx, is showing the stacked barchart in staggered formation. The desired outcome is the same level barcharts in expected_output.pptx.


In powerpoint, editing the bars and setting overlap to 100% will do the trick. The documentation does not illustrate where to set this in code though.

Hi Bradley,

Thank you for sharing the files.

Your requested feature to overlap the series is not supported at the moment. A new feature request is already registered in our issue tracking system with issue id: SLIDESNET-34412. I have attached this thread with the above issue and you will be notified once the feature is supported.

Thanks & Regards,

Any update to this feature? I’m running into the same issue. Is there any workaround other than editing the charts directly in PPT?

Hi Brad,

Thank you for considering Aspose.

I am afraid, the feature is still pending for further analysis from our development team and currently there is no work around available. We will update you via this thread once there is any progress against this issue.

Thanks & Regards,

Hi,

Is this bug already fixed. It is not possible to create a simple stacked bar chart at this moment?

Thanks for your reply!
S.

Hi Sofie,

The issue has been fixed and will be part of our next release of Aspose.Slides for .NET v14.8.0. You will get a notification via this forum thread once the new version gets released.

Thanks & Regards,

Hi,


do you know the release date of the new Aspose.Slide .NET version (14.8.0)? We encountered the same issue and this will delay our project, if this would not be fixed soon.

Best regards,

Hi Sofie,

I like to share that Aspose.Slides for .NET 8.0.0 is
scheduled for delivery by next week. However, I will share the updated
information about the product release with you as soon as it will be
shared by our development team.

Many Thanks,

The issues you have found earlier (filed as SLIDESNET-34412) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(8)