Thousand separator in pie chart tooltip of charts.js - Javascript Chart.js

Javascript examples for Chart.js:Chart Tooltip

Description

Thousand separator in pie chart tooltip of charts.js

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Chart.js - Pie Charts Tooltip Label Callback</title> 
   </head> 
   <body translate="no"> 
      <div id="canvas-holder" style="width:40%"> 
         <canvas id="chart-area"></canvas> 
      </div> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> 
      <script>
      var ctx = document.getElementById("chart-area").getContext("2d");
var myPie = new Chart(ctx, {//from   w w w . j  ava2  s . co m
  type: 'pie',
  data: {
    labels: ["Java","Mick","Jack"],
    datasets: [{
      backgroundColor: ["#00b638","#efaa30","#50c8ea"],
      data: [500000, 75000, 100000]
    }],
  },
  options: {
    title: {
      display: true,
      text: 'Employee Overview',
      fontStyle: 'bold',
      fontSize: 20
    },
    tooltips: {
      callbacks: {
        label: function(tooltipItem, data) {
          var dataLabel = data.labels[tooltipItem.index];
          var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].toLocaleString();
          if (Chart.helpers.isArray(dataLabel)) {
            dataLabel = dataLabel.slice();
            dataLabel[0] += value;
          } else {
            dataLabel += value;
          }
          return dataLabel;
        }
      }
    }
  }
});
      </script>  
   </body>
</html>

Related Tutorials