58
votes

I'm using Highcharts and I want to format all numbers showed anywhere in the chart (tooltips, axis labels...) with comma-separated thousands.

Otherwise, the default tooltips and labels are great, and i want to keep them exactly the same.

For example, in this chart, the number should be 2,581,326.31 but otherwise exactly the same.

enter image description here

How can I do this?

I tried adding:

    tooltip: {
        pointFormat: "{point.y:,.0f}"
    }

But this got rid of the nice circle and series label in the tooltip - I'd like to keep that. And ideally I'd prefer to use a single option to set global number formatting, across the whole chart.

4
I would try with a custom lang, see stackoverflow.com/questions/7419358/…user180100

4 Answers

125
votes

This can be set with the thousandSep (API) global option.

Highcharts.setOptions({
    lang: {
        thousandsSep: ','
    }
});

See this JSFiddle example.

4
votes

In case you want to show numbers without commas and spaces.

eg. by default 9800 shows as 9 800.

If you want 9800 to be shown as 9800

you can try this in tooltip:

    tooltip: {
     pointFormat: '<span>{point.y:.f}</span>'
   }
3
votes

This way worked with me.

I configured in yAxis option.

yAxis: {
  labels: {
    formatter: function() {
        return Highcharts.numberFormat(this.value, 2);
    }
  }
}
0
votes

This way work for me.

I use Angular 10 and I did this for Tooltip and yAxis.

for yAxis use numberFormat:

 labels: {
              format: '{value}',
              style: {
                color: Highcharts.getOptions().colors[0]
              },
              formatter: function() {
                return Highcharts.numberFormat(this.value, 3);
            }
            },

and for Tooltip :

{point.y:.f}