图表点的富文本自定义数据标签
Contents
[
Hide
]
您可以使用Aspose.Cells为图表点创建富文本自定义数据标签。 Aspose.Cells 提供DataLabels.Characters()方法返回FontSetting对象,该对象可用于设置文本的字体属性,如颜色、粗细等。
数据点的图表富文本自定义数据标签
以下代码访问第一个系列的第一个图表点,设置其文本,然后通过设置字体的颜色为红色并将其粗体设置为true 来设置前10个字符的字体。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 a workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first chart inside the sheet | |
Chart chart = worksheet.Charts[0]; | |
// Access the data label of first series first point | |
DataLabels dlbls = chart.NSeries[0].Points[0].DataLabels; | |
// Set data label text | |
dlbls.Text = "Rich Text Label"; | |
// Set the font setting of the first 10 characters | |
FontSetting fntSetting = dlbls.Characters(0, 10); | |
fntSetting.Font.Color = Color.Red; | |
fntSetting.Font.IsBold = true; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |