I'm trying to always show tooltips for a multi dataset line chart in ChartJS
The existing solutions only work for a single dataset (e.g. Chart.js - Doughnut show tooltips always?) like so:
var options =
{
tooltipTemplate: "<%= value %>",
onAnimationComplete: function()
{
this.showTooltip(this.segments, true);
//Show tooltips in bar chart (issue: multiple datasets doesnt work http://jsfiddle.net/5gyfykka/14/)
//this.showTooltip(this.datasets[0].bars, true);
//Show tooltips in line chart (issue: multiple datasets doesnt work http://jsfiddle.net/5gyfykka/14/)
//this.showTooltip(this.datasets[0].points, true);
},
tooltipEvents: [],
showTooltips: true
}
var context = $('#chart').get(0).getContext('2d');
var chart = new Chart(context).Pie(data, options);
The existing JS Fiddle for working single dataset solution: http://jsfiddle.net/5gyfykka/14/
I have managed to get How to display Line Chart dataset point labels with Chart.js? working using a different onAnimationComplete function
onAnimationComplete: function () {
var ctx = document.getElementById("LineWithLine").getContext("2d");
ctx.font = '.8rem "Gotham Book",sans-serif';
ctx.fontWeight = 'bold';
ctx.fillStyle = '#000';
ctx.textAlign="right";
var self = this;
$(self.datasets).each(function(idx,dataset){
$(dataset.points).each(function(pdx,pointinfo){
if ( pointinfo.value !== null ) {
ctx.fillText(pointinfo.value,pointinfo.x,pointinfo.y - 18);
}
});
});
},
And while this works, it's not as nice as the multi tooltip that Chart JS provides.
JS Fiddle: https://jsfiddle.net/hdnu4bpa/
You need to kind of take control over the tootip generation process (i.e. copy paste the relevant section of code from the Chart.js library :-))
Show Tooltips automatically (without hover) for Multi Series Line Charts
Here's how its going to look
Just change your options like this
Fiddle - https://jsfiddle.net/racqd639/