I'm building an API to create ECharts configs and would like the data labels to appear in the correct format based on where the end user is reading the chart from.
For example, if a number in a chart is 10,000 I would like it to appear as 10,000 in North America and 10.000 in Europe.
It looks like it's not possible to set a global format in ECharts, so I will need to use the formatter
option. I thought this would be as simple as passing in a function that uses JavaScript's toLocaleString()
or Intl.NumberFormat
, but the ECharts docs make this look much more complicated.
I haven't found any examples of formatter
that show both the inputs and outputs for common formatting scenarios, so I'm hoping to get some help in understanding the right way to do this.
Below is a very simple example of the function I'm hoping to include in formatter
, but this particular example doesn't work.
formatter: function(d){
return d.toLocaleString()
}