简体   繁体   English

如何在StackedColumn图表中获取列的动态宽度

[英]How to get dynamic width of column in StackedColumn chart

I'm working in a project where I need to deal with StackedColumn chart using Aspose.Slides library.我正在一个项目中工作,我需要使用 Aspose.Slides 库处理 StackedColumn 图表。 For each column of the chart, there is a corresponding counter value and I need to display it like in this sample slide.对于图表的每一列,都有一个对应的计数器值,我需要像在此示例幻灯片中一样显示它。

模板

Basically, each label should be displayed symmetrical to the middle of the corresponding column's width.基本上,每个标签都应与相应列宽度的中间对称显示。

正确的标签定位

With 5 columns, the labels display fine like the template.有 5 列,标签像模板一样显示得很好。 However, if there are less than that the labels will display like these.但是,如果少于该数量,标签将显示为这样。

有 4 列 有 2 列

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.我试图获取每个数据点的 ActualWidth 但只得到零值。 It seems the field's value will only be set once the entire chart (or maybe the entire powerpoint file) is rendered.似乎该字段的值只会在整个图表(或者可能是整个 powerpoint 文件)呈现后才被设置。 Does anyone know how to get dynamic width value of each column from code (even before it is rendered)?有谁知道如何从代码中获取每列的动态宽度值(甚至在呈现之前)?

Never mind.没关系。 I got the answer myself.我自己得到了答案。 Just call this before getting actual width.在获得实际宽度之前调用它。

chart.validateChartLayout();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM