Set the Values Format Code of Chart Series with Node.js via C++

Possible Usage Scenarios

You can set the values format code of chart series using the Series.getValuesFormatCode() property. This property is not only useful for series that are based on a range inside the worksheet but also works well for series created with an array of values.

Set the Values Format Code of Chart Series

The following sample code adds a series to an empty chart that has no series initially. It adds the series using an array of values. Once it adds the series, it formats it with the code $#,##0 using the Series.getValuesFormatCode() property, and the number 10000 becomes $10,000. The screenshot shows the effect of the code on the sample Excel file and the output Excel file after execution.

todo:image_alt_text

Sample Code

const AsposeCells = require("aspose.cells.node");
const path = require("path");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "51740712.xlsx");

// Load the source Excel file 
const workbook = new AsposeCells.Workbook(filePath);

// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Access first chart
const chart = worksheet.getCharts().get(0);

// Add series using an array of values
chart.getNSeries().add("{10000, 20000, 30000, 40000}", true);

// Access the series and set its values format code
const series = chart.getNSeries().get(0);
series.setValuesFormatCode("$#,##0");

// Save the output Excel file
workbook.save(path.join(dataDir, "51740713.xlsx"));