Rich Text Custom Data Label of Chart Point with Node.js via C++
Contents
[
Hide
]
You can use Aspose.Cells to create rich text custom data labels for chart points. Aspose.Cells provides the ChartTextFrame.characters(number, number) method to return the FontSetting object which can be used to set the font properties of the text like its color, boldness, etc.
Rich Text Custom Data Label of Chart Point
The following code accesses the first chart point of the first series, sets its text and then sets the font of the first 10 characters by setting its color to red and boldness to true.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create a workbook from source Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample_custom_datalabel.xlsx"));
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Access the first chart inside the sheet
const chart = worksheet.getCharts().get(0);
// Access the data label of first series first point
const 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
const fntSetting = dlbls.characters(0, 10);
fntSetting.getFont().setColor(AsposeCells.Color.Red);
fntSetting.getFont().setIsBold(true);
// Save the workbook
workbook.save(path.join(dataDir, "output_out.xlsx"));