图表点富文本自定义数据标签
Contents
[
Hide
]
您可以使用 Aspose.Cells 创建图表点的富文本自定义数据标签。 Aspose.Cells 提供了DataLabels.characters() 方法返回字体设置对象,可用于设置文本的字体属性,如颜色、粗体等。
图表点富文本自定义数据标签
以下代码访问第一个系列的第一个图表点,设置其文本,然后通过将其颜色设置为红色并将粗体设置为 true 来设置前 10 个字符的字体。
This file contains hidden or 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RichTextCustomData.class); | |
// Create a workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the first chart inside the sheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Access the data label of first series first point | |
DataLabels dlbls = chart.getNSeries().get(0).getPoints().get(0).getDataLabels(); | |
// Set data label text | |
dlbls.setText("Rich Text Label"); | |
// Set the font setting of the first 10 characters | |
FontSetting fntSetting = dlbls.characters(0, 10); | |
fntSetting.getFont().setColor(Color.getRed()); | |
fntSetting.getFont().setBold(true); | |
// Save the workbook | |
workbook.save("output.xlsx"); |