Chart.js Tooltip only for one dataset - Javascript Chart.js

Javascript examples for Chart.js:Chart Tooltip

Description

Chart.js Tooltip only for one dataset

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  a 2s  .  c o  m*/
var labels = ["January", "February", "March", "April", "May", "June", "July"];
var data1 = [65, 0, 80, 81, 56, 85, 40];
var data2 = [0, 80, 81, 56, 85, 40, 65];
var data3 = [80, 81, 56, 85, 40, 65, 0];
var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: labels,
    datasets: [{
      type: 'line',
      data: data3
    }, {
      type: 'bar',
      data: data1,
      backgroundColor: "#3EAFD5",
      hoverBackgroundColor: "#3EAFD5"
    }, {
      type: 'bar',
      data: data2,
      backgroundColor: "#D24B47",
      hoverBackgroundColor: "#D24B47",
    }]
  },
})
var originalGetElementAtEvent = myChart.getElementAtEvent;
myChart.getElementAtEvent = function () {
  return originalGetElementAtEvent.apply(this, arguments).filter(function (e) {
    return e._datasetIndex == 0;
  });
}
    }

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

Related Tutorials