Adding thousands separator for custom formatted highcharts tooltip
Asked Answered
D

4

16

I am using highcharts to in my app and want to add tooltip with thousand separator like I did it in data labels. I used custom formatting for tooltip, so what should I change to achieve this

tooltip options in highcharts

tooltip: {
                formatter: function () {
                    return (this.x + ':' + this.y);
                },
                shared: true,
                useHTML: true
            },

JS FIDDLE

Doubledealing answered 8/10, 2015 at 9:15 Comment(0)
T
20

use thousand separator in lang

$(function () {
Highcharts.setOptions({

    lang: {
      decimalPoint: '.',
      thousandsSep: ','
    }
});

and in tooltip- formatter use like

   tooltip: {
             pointFormat: '<b>{point.x} :</b>' + 'Count: <b>{point.y:,.0f}</b>',

            shared: true,
            useHTML: true
        }

Updated fiddle with separator without decimal point

Tabby answered 8/10, 2015 at 9:26 Comment(6)
please take a look in the fiddleDoubledealing
if don't want decimal part replace .1f with .0f pointFormat: ' <b>{point.x} :</b>' + 'Count: <b>{point.y:,.0f}</b>'Tabby
:) I was making your desired format ,Initially I made it with 1 decimal point .Check the fiddle nowTabby
The fiddle(s) is/are gone now. Is it possible to re-upload it?Knossos
jsfiddle page does not existsCamper
@Irrfan23, please refer another answer given by that fiddle is still availableTabby
C
6

Just following Nishith Kant Chaturvedi's answer, and since there is no jsfiddle example available, here you can see how to implement that answer.

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

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: ''
    },
    xAxis: {
        categories: ['Salary']
    },
    yAxis: {
        title: {
            text: ''
        },
        stackLabels: {
            enabled: true,
            format: '{total:,.2f} $us'
        },
        labels: {
            format: "{value:,.2f} $us",
        }
    },
    legend: {
        backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
        borderColor: '#CCC',
        borderWidth: 1,
    },
    tooltip: {
        headerFormat: '<b>{point.x}</b><br/>',
        pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                    format: '{point.y:,.2f} $us',
                enabled: true,
                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
            }
        }
    },
    series: [{
            type: 'column',
        name: 'Tomas',
        data: [60000]
    }, {
            type: 'column',
        name: 'Amy',
        data: [18000]
    }, {
            type: 'column',
        name: 'Jenny',
        data: [85000]
    }]
});

http://jsfiddle.net/zrc5skLy/

Chappie answered 25/1, 2019 at 21:53 Comment(1)
Great answer! Helped me finally get the $1,000,000 formatting correct. You can modify the formatting of the highlighted values by using '{series.name}: {point.y:,.2f}<br/>Total: {point.stackTotal:,.2f}'.Calcimine
T
4

Use Highcharts.numberFormat() in point.x or point.y

example:

tooltip: {
  enabled: true,
  split: true,
  shared: true,
  formatter: function () {
    // The first returned item is the header, subsequent items are the points
    return [Highcharts.dateFormat("%Y-%m-%d %H:%M:%S", this.x)].concat(
      this.points
        ? this.points.map(function (point) {
            return (
              point.series.name +
              ": " +
              // numberFormat(data, decimal)
              Highcharts.numberFormat(point.y, 2)
            );
          })
        : []
    );
  },
},
Taimi answered 28/1, 2021 at 1:3 Comment(0)
L
0

Since this option is not available in our framework,

lang: {
      decimalPoint: '.',
      thousandsSep: ','
    }

I came up with a trick using point formatter

"pointFormatter": "function (){ return (this.base/1000).toString().replace('.', ',')}"
Leong answered 27/4, 2023 at 1:50 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Rosenkranz

© 2022 - 2024 — McMap. All rights reserved.