Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js - how to disable everything on hover

How can I set the code that there will be no hover effects, hover options, (hover) links etc on chart?

I'm using chart.js. Below is my code, where I set pie chart.

Html..

<div id="canvas-holder" style="width:90%;">     <canvas id="chart-area" /> </div> 

..and js...

$(document).ready(function () {                   var config = {                     type: 'pie',                     data: {                         datasets: [{                             data: [60,20],                             backgroundColor: [                                 "#ddd",                                 "#58AC1C"                             ],                              label: 'Dataset 1'                         }],                         labels: [                             "Bla1 ",                             "Bla2 "+                         ]                        },                     options: {                         responsive: true                     }                 };                   window.onload = function() {                     var ctx = document.getElementById("chart-area").getContext("2d");                     window.myPie = new Chart(ctx, config);                 };                   }); 
like image 217
ggsplet Avatar asked Jan 31 '17 07:01

ggsplet


People also ask

Does chart JS work offline?

Is it possible to use chart. js for a desktop/mobile application using html that connects through an esp8266 access point or does it need a wifi connection? @marionboynton, CanvasJS is a standalone library that can work offline without any internet connection.

Does chart js use SVG?

Other than that the most obvious distinction between the two is that Chart. js is canvas based, while d3. js is mainly about SVG.

Does chart js use canvas?

Let's get started using Chart.js! First, we need to have a canvas in our page. It's recommended to give the chart its own container for responsiveness.

What is a chart tooltip?

Tooltips are the little boxes that pop up when you hover over something. (Hovercards are more general, and can appear anywhere on the screen; tooltips are always attached to something, like a dot on a scatter chart, or a bar on a bar chart.)


2 Answers

In order to remove all hover styles/tooltips from vanilla chart.js:

var myChart = new Chart(canvas, {     options: {         tooltips: {enabled: false},         hover: {mode: null},     }     ... }); 

Chart.js is watching all mousemove events on the canvas within which it has instantiated your chart. Setting hover 'mode' to null seems to override all the ways the canvas looks for matching elements to assign activated :hover classes to.

The tooltip event seems separate, so I had to use both lines to make the chart effectively static.

Note, initial animations still work on a chart with these options.

UPDATE: newest Chart.js has re-bundled the way hover is 'listened' for:

var myChart = new Chart(canvas, {     options: {         events: []     }     ... }); 

Making the 'events' option an empty list (instead of ['click', 'hover', etc]) makes the chart blind'/static because it will be listening for no events.

like image 80
Megan Word Avatar answered Oct 10 '22 16:10

Megan Word


You can try

 showTooltips: false 

You can also use the following link

http://jsfiddle.net/TZq6q/298/

like image 30
Sanyami Vaidya Avatar answered Oct 10 '22 15:10

Sanyami Vaidya