As always show tips on Chart.js 2

How to always show hints with Chart.js version 2 (alpha)?

I tried this Chart.js - tooltips for Donut shows always? but it seems that this has changed in this latest version.

+3
source share
2 answers

This worked for me:

events: [], animation: { duration: 0, onComplete:function () { var self = this; var elementsArray = []; Chart.helpers.each(self.data.datasets, function (dataset, datasetIndex) { Chart.helpers.each(dataset.metaData, function (element, index) { var tooltip = new Chart.Tooltip({ _chartInstance: self, _chart: self.chart, _data: self.data, _options: self.options, _active: [element] }, self); tooltip.update(); tooltip.transition(Chart.helpers.easingEffects.linear).draw(); }, self); }, self); } } 
+5
source

You need to scroll through the data sets and specify and create tooltips in onAnimationComplete (setting an array of events to an empty array will not work).

As before deleting events from the events array, so that tooltips do not disappear after the mouse and mouse, but in this case you need to set events to false .

Also, I think that the version in dev, when I last checked, had a problem with onAnimationComplete, but not with launch, if the animation duration not 0 .

Here is the relevant code

 var config = { type: 'pie', options: { events: false, animation: { duration: 0 }, onAnimationComplete: function () { var self = this; var elementsArray = []; Chart.helpers.each(self.data.datasets, function (dataset, datasetIndex) { Chart.helpers.each(dataset.metaData, function (element, index) { var tooltip = new Chart.Tooltip({ _chart: self.chart, _data: self.data, _options: self.options, _active: [element] }, self); tooltip.update(); tooltip.transition(Chart.helpers.easingEffects.linear).draw(); }, self); }, self); } }, 

Fiddle - https://jsfiddle.net/c8Lk2381/


enter image description here

+4
source

Source: https://habr.com/ru/post/1261612/


All Articles