Set the Values Format Code of Chart Series
Possible Usage Scenarios
You can set the values format code of chart series using the Series.values_format_code property. This property is not only useful for the series which is based on the range inside the worksheet but also works well for the series created with an array of values.
Set the Values Format Code of Chart Series
The following sample code adds a series in the empty chart which has no series before. It adds the series using the array of values. Once, it adds the series, it formats it with the code $#,##0 using the Series.values_format_code property and the number 10000 becomes $10,000. The screenshot shows the effect of code on the sample Excel file and output Excel file after execution.
Sample Code
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load the source Excel file | |
wb = Workbook("sampleSeries_ValuesFormatCode.xlsx") | |
# Access first worksheet | |
worksheet = wb.worksheets[0] | |
# Access first chart | |
ch = worksheet.charts[0] | |
# Add series using an array of values | |
ch.n_series.add("{10000, 20000, 30000, 40000}", True) | |
# Access the series and set its values format code | |
srs = ch.n_series[0] | |
srs.values_format_code = "$#,##0" | |
# Save the output Excel file | |
wb.save("outputSeries_ValuesFormatCode.xlsx") |