Search code examples
highchartstooltipdata-visualization

How to show decimal values in highcharts graph?


series: [{
        name: 'name',
        type: 'spline',
        data: d1,
        tooltip: {
            pointFormat: '{series.name}: <b>{point.y:.2f}%</b>'
        }
}]
d1=[0.12,-1.58,-0.8]

Show in graph 0.00,1.00,0.00


Solution

  • Use the Highcharts.numberFormat function in combination with the formatter function, as Ahmed Sayed noted (see http://api.highcharts.com/highcharts#Highcharts.numberFormat).

    For your specific code, you would format it this way:

    series: [{
        name: 'name',
        type: 'spline',
        data: d1,
        tooltip: {
          // format the tooltip to return the y-axis value to two decimal places
          formatter: function() { 
            return this.series.name + ': <b>' + Highcharts.numberFormat(this.y,2) + '%</b>';
          }
        }
    }]
    

    I hope this is helpful for you.