Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hover mode on Chart.js

Is it possible to have the hover activated when you are not hovering over a specific 'point' in a line graph?

I want that particular tooltip to activate whenever I hover over any part of the chart.

Edit: something like this http://watchstocks.herokuapp.com/

like image 241
JohnSnow Avatar asked Mar 15 '17 08:03

JohnSnow


3 Answers

For chart version > 3 rename the object tooltips to tooltip and place it inside the plugin object.

options: {
      plugins: {
                 legend: {
                 display: false
                 },
                 tooltip: {
                 mode: 'index',
                 intersect: false
                 }
      },
      hover: {
             mode: 'nearest',
             intersect: false
             }


}
like image 51
Chaitra Avatar answered Nov 10 '22 08:11

Chaitra


Yes, you can use chart.js to configure tooltips to get a similiar behavior to the chart that you referenced.

For more information, check out the mode tooltip config option and hover config options for your needs. Here is an example.

options: {
  responsive: true,
  title:{
    display:true,
    text:'Chart.js Line Chart'
  },
  tooltips: {
    mode: 'index',
    intersect: false,
  },
 hover: {
    mode: 'nearest',
    intersect: true
  },
  scales: {
    xAxes: [{
      display: true,
      scaleLabel: {
        display: true,
        labelString: 'Month'
      }
    }],
    yAxes: [{
      display: true,
      scaleLabel: {
        display: true,
      },
    }]
  }
}

Here is a codepen example demonstrating the behavior that matches your example.

like image 41
jordanwillis Avatar answered Nov 10 '22 07:11

jordanwillis


tooltips: {
  mode: 'x-axis'
},

^^ That will bring up the tooltip when you hover over any y-axis position. If you only want it to show up when you hover over a point on a line, use this:

tooltips: {
  mode: 'label'
},
like image 9
Jeff Schwarting Avatar answered Nov 10 '22 07:11

Jeff Schwarting