0

How to always show tooltip BUT with 2 datasets for line chart?

Here is jsfiddle which works with one dataset.

My tooltip code is:

var options = 
{
    tooltipTemplate: "<%= value %>",

    showTooltips: true,

    onAnimationComplete: function()
    {    
        this.showTooltip(this.datasets[0].points, true);          
    },
    tooltipEvents: []
}

And in same appirience I would like to have with 2,3 or more datasets.

Here is jsfiidle where I tried 2 datasets.

I guess, this line has something to do with it:

this.showTooltip(this.datasets[0].points, true);  
Gnesh
  • 45
  • 1
  • 10

2 Answers2

1

I manage to find a solution. Here it is: Chart JS: Always show tooltips in a multi dataset line chart

But if you want to do the same thing but on Bar chart, you need to change:

for (var dataIndex = 0; dataIndex < this.datasets[0].points.length; dataIndex++) {

to

for (var dataIndex = 0; dataIndex < this.datasets[0].bars.length; dataIndex++) {

and from

dataCollection = dataset.points;

to

dataCollection = dataset.bars;

At the bottom you should call Bar chart, eg.

var chart = new Chart(ctx).Bar(dataBar, options);
Community
  • 1
  • 1
Gnesh
  • 45
  • 1
  • 10
0

Try this:

tooltip: {
    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
}
Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51
Karthick Kumar
  • 77
  • 1
  • 12
  • Can you please refer where should I use this? Thanks – Gnesh Mar 08 '16 at 10:58
  • Sorry I am not following. Can you provide jsfiddle? – Gnesh Mar 08 '16 at 11:15
  • Sorry, this is not something that I am need. As you can see in my first jsfiddle example - I want tooltip, BUT for chartjs to be visible all the time. It works when I have one dataset but when I have more, it only shows first value. thanks – Gnesh Mar 08 '16 at 11:23
  • Sorry, this is not something that I need. Here is what I need http://jsfiddle.net/5gyfykka/454/ – Gnesh Mar 08 '16 at 11:34