Custom tooltip label - Javascript Chart.js

Javascript examples for Chart.js:Chart Tooltip

Description

Custom tooltip label

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js 2.1</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.0/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from   w w w  .  j a v  a2s  . co  m
Chart.defaults.myLine = Chart.helpers.clone(Chart.defaults.line);
Chart.controllers.myLine = Chart.controllers.line.extend({
  updateElement: function (point) {
    var result = Chart.controllers.line.prototype.updateElement.apply(this, arguments);
    point.inRange = function (mouseX, mouseY) {
      var vm = this._view;
      return vm ? (Math.abs(mouseX - vm.x) < (vm.hitRadius + vm.radius)) : false;
    };
    return result;
  }
});
var config = {
  type: 'myLine',
  data: {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [{
      label: "My First dataset",
      data: [65, 0, 80, 81, 56, 85, 40],
    }, {
      label: "My Second dataset",
      data: [0, 80, 81, 56, 85, 40, 12],
    }]
  },
  options: {
    tooltips: {
      mode: 'label'
    }
  }
};
var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, config);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart"></canvas>  
   </body>
</html>

Related Tutorials