John Sket
John Sket

Reputation: 117

Formatting the float numbers in Highcharts

When the mouse moves to the series, highcharts displays all the numbers, as shown in this picture:

enter image description here

I want to make the float numbers all have 2 digits after dot point. I searched online, and came up sth like:

    plotOptions: {
        series: {
            dataLabels: {
                formatter: function() {
                    return '<b>' + this.point.name + '</b>: ' + this.percentage.toFixed(2) + ' %';
                }
            }
        }
    }

But it does not work.

Upvotes: 3

Views: 7997

Answers (2)

Xueli Li
Xueli Li

Reputation: 11

You can do like this.

formatter: function () {
    let perc = this.percentage.toFixed(2)
    return `<span>${perc}%</span>`
}

Upvotes: 1

Barbara Laird
Barbara Laird

Reputation: 12717

dataLabels controls numbers that show up near the points on the chart itself. That rollover you have in your image is the tooltip. Check out: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/tooltip/valuedecimals/

    tooltip: {
        valueDecimals: 2
    },

Upvotes: 8

Related Questions