Shaun
Shaun

Reputation: 471

How to add comma to data labels value in bar chart race of highcarts?

I have a bar chart race displaying and I now trying to render the data for the labels correctkly by adding a comma into them. Can someone tell me how can I add comma to the data labels that are over 1,000?

https://jsfiddle.net/samwhite/Lzh2rwab/

 Highcharts.getJSON('https://api.npoint.io/d70fd8f47a70326609bb', function (data) {
    initialData =[
    {
      "": "",
      "2017": 954,
      "2018": 983,
      "2019": 1107,
          "2020": 1710,
                  "2021": "",
      "Country Code": "CDF",
      "Country Name": "Corporate Disclosures and Financials"
    },
    {
        "": "",
        "2017": 758,
        "2018": 1054,
        "2019": 692,
            "2020": 1078,
                    "2021": "",
        "Country Code": "OF",
        "Country Name": "Offering Fraud"
      },
      {
        "": "",
        "2017": 67,
        "2018": 57,
        "2019": 35,
            "2020": 37,
                    "2021": "",
        "Country Code": "MSAPP",
        "Country Name": "Municipal Securities and Public Pension"
      }
  ];
        
      xAxis: {
        type: 'category',
      },
      yAxis: [{
        tickAmount: 5,
        title: {text:"Number of Tips"}
      }],
      series: [{
      colorByPoint: true,
                colors:['#7cb5ec', '#3e9af3', '#1e9af3',  '#006af3', '#0060f3', '#0020f3', '#0020c1', '#0020a3', '#001060'],
        dataSorting: {
          enabled: true,
          matchByName: true
        },
        type: 'bar',
        dataLabels: [{
          enabled: true,
        }],
        name: startYear,
        data: getData(startYear)[1]
      }]
    });
});

Upvotes: 0

Views: 791

Answers (1)

Sebastian Wędzel
Sebastian Wędzel

Reputation: 11633

You can achieve it by using the format feature.

API: https://api.highcharts.com/highcharts/series.line.dataLabels.format

Demo: https://jsfiddle.net/BlackLabel/5sk3ptj7/

Upvotes: 1

Related Questions