调整图表数据标签形状以适应文本

如何在Microsoft Excel中调整图表数据标签的形状以适应文本

可以通过在图表上选择任何数据标签来访问Excel界面上的此选项。右键单击并选择格式数据标签菜单。在大小和属性选项卡上,展开对齐以显示相关属性,包括调整形状以适应文本选项。

如何在 Aspose.Cells for .NET 中调整图表的数据标签形状以适应文本大小

为了模仿Excel调整数据标签形状以适应文本的功能,Aspose.Cells API已经暴露了布尔类型 DataLabels.IsResizeShapeToFitText 属性。以下代码片段展示了 DataLabels.IsResizeShapeToFitText 属性的简单使用场景。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create an instance of Workbook containing the Chart
var book = new Workbook(dataDir + "source.xlsx");
// Access the Worksheet that contains the Chart
var sheet = book.Worksheets[0];
foreach (Chart chart in sheet.Charts)
{
for (int index = 0; index < chart.NSeries.Count; index++)
{
// Access the DataLabels of indexed NSeries
var labels = chart.NSeries[index].DataLabels;
// Set ResizeShapeToFitText property to true
labels.IsResizeShapeToFitText = true;
}
// Calculate Chart
chart.Calculate();
}
// Save the result
book.Save(dataDir + "output_out.xlsx");