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