[Chartjs]-Add all data in the tooltip of Chart JS

9πŸ‘

βœ…

To add all the data from a specific label (date) in the tooltip, you need to set tooltips mode to index in your chart options, like so :

options: {
   tooltips: {
      mode: 'index'
   },
   ...
}

ᴅᴇᴍᴏ

var chart = new Chart(ctx, {
   type: 'line',
   data: {
      labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
      datasets: [{
         label: 'LINE 1',
         data: [3, 1, 4, 2, 5],
         backgroundColor: 'rgba(0, 119, 290, 0.2)',
         borderColor: 'rgba(0, 119, 290, 0.6)'
      }, {
         label: 'LINE 2',
         data: [4, 2, 3, 5, 1],
         backgroundColor: 'rgba(0, 119, 290, 0.1)',
         borderColor: 'rgba(0, 119, 290, 0.6)'
      }]
   },
   options: {
      tooltips: {
         mode: 'index'
      },
      scales: {
         yAxes: [{
            ticks: {
               beginAtZero: true
            }
         }]
      }
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>

Leave a comment