How to format the series values (IChart)

I am using this code to populate a series from an anonymous type:


IChartSerie serieAñoActual = grafico.Series.Add(ExcelChartType.Line_Markers);

serieAñoActual.EnteredDirectlyValues = _datos

    .Where(d => (int)d.GetType().GetProperty("Año").GetValue(d) == añoActual)

    .Select(d => (d.GetType().GetProperty("Actividad").GetValue(d)))

    .ToArray();


The values appear correctly, but not formatted, meaning instead of appearing as "5000," it should appear as "5,000."

Thank you in advance.

Regards


3 Replies

MA MohamedyusufKhan AhamedMusthafa Syncfusion Team September 21, 2023 02:08 PM UTC

Hi Jose,

We suggest you to use PrimaryValueAxis.NumberFormat to set the number format for the value axis. Please find the code snippet below.

Code Snippet:

//Create a chart

IChartShape chart = sheet.Charts.Add();

  

//Add chart series

IChartSerie series = chart.Series.Add(ExcelChartType.Line_Markers);

series.EnteredDirectlyValues = new object[] { 1000,500,5000,1000,10000,13000,1000,10000,13000};

//Add NumberFormat

chart.PrimaryValueAxis.NumberFormat = "#,##0.00";

Please go through the below link for more value axis properties.

https://help.syncfusion.com/file-formats/xlsio/working-with-charts#different-primary-value-axis-properties

Regards,

Mohamed Yusuf Khan.



JA Jose Antonio replied to MohamedyusufKhan AhamedMusthafa October 10, 2023 09:19 AM UTC

Hi, this only applies to the values appearing on the Y-axis, not to the values in the data series.



MC Mohan Chandran Syncfusion Team October 31, 2023 11:27 AM UTC

Hi Jose,

Yes. The number formatting can be applied only to the numbers in the value axis. If you have a different requirement, please share with us the expected Excel chart screenshot or document to validate further at our end.

Regards,

Mohan.


Loader.
Up arrow icon