簡體   English   中英

如何在StackedColumn圖表中獲取列的動態寬度

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

我正在一個項目中工作,我需要使用 Aspose.Slides 庫處理 StackedColumn 圖表。 對於圖表的每一列,都有一個對應的計數器值,我需要像在此示例幻燈片中一樣顯示它。

模板

基本上,每個標簽都應與相應列寬度的中間對稱顯示。

正確的標簽定位

有 5 列,標簽像模板一樣顯示得很好。 但是,如果少於該數量,標簽將顯示為這樣。

有 4 列 有 2 列

這是一段代碼,負責為系列添加數據點並為每個數據點添加標簽。

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

我試圖獲取每個數據點的 ActualWidth 但只得到零值。 似乎該字段的值只會在整個圖表(或者可能是整個 powerpoint 文件)呈現后才被設置。 有誰知道如何從代碼中獲取每列的動態寬度值(甚至在呈現之前)?

沒關系。 我自己得到了答案。 在獲得實際寬度之前調用它。

chart.validateChartLayout();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM