Hi,
I’m working in a project where I need to deal with StackedColumn chart. For each column of the chart, there is a corresponding counter value and I need to display it like in this sample slide.
Template (11.2 KB)
Basically, each label should be displayed symmetrical to the middle of the corresponding column’s width.
Supposed positions of labels (10.9 KB)
With 5 columns, the labels are displayed fine. However, if there are less than that the labels will display like these.
With 4 columns (10.0 KB)
With 2 columns (7.7 KB)
Here is the piece of code that is responsible for adding data point for the series and adding label for each data point.
dataSeries.DataPoints.AddDataPointForBarSeries(itemValueCell);
dataSeries.Format.Fill.FillType = fillType;
dataSeries.Format.Fill.SolidFillColor.Color = fillColour;
dataSeries.ParentSeriesGroup.Overlap = 100;
dataSeries.ParentSeriesGroup.GapWidth = 75;
var counter = workbook.GetCell(index, rowIndex, 7, item.Counter);
dataSeries.DataPoints[index - 1].Label.ValueFromCell = itemNameCell;
slide.Shapes.AddAutoShape(ShapeType.Rectangle, startX + dataSeries.GapWidth / 4.0f + (index - 1) * dataSeries.GapWidth * 1.85f, startY, dataSeries.GapWidth / 2.0f, 20);
var label = ((AutoShape)slide.Shapes[slide.Shapes.Count() - 1]);
label.TextFrame.Text = counter.Value.ToString();
label.FillFormat.FillType = FillType.NoFill;
label.LineFormat.FillFormat.FillType = FillType.NoFill;
label.TextFrame.TextFrameFormat.CenterText = NullableBool.True;
label.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Normal;
label.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
label.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.FromArgb(0, 173, 219);
I tried to get ActualWidth of each datapoint but only got zero value. It seems the field’s value will only be set once the entire chart (or maybe the entire powerpoint file) is rendered. Does anyone know how to get dynamic width value of each column from code?