Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show tooltips in Chart.js?

Following the tutorial this code draws the line chart, but no tooltips. Am I missing some configuration option here? In the tutorial there are tooltips showing up.

var chartData = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
};

var ctx = document.getElementById("chart").getContext("2d");
var myNewChart = new Chart(ctx).Line(chartData, {
    showTooltip: true,
    tooltipTemplate: "<%= value %>"
});
like image 468
VuesomeDev Avatar asked Jul 02 '14 08:07

VuesomeDev


People also ask

What is tooltip chart?

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

What version of chart.js are you using?

I can confirm that tooltips work using v1.0.1-beta2

<script src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js"></script>

but do not work using v0.2.0.

Version 1.0.1-beta2 is available from cdnjs.

like image 68
cooncesean Avatar answered Sep 29 '22 13:09

cooncesean


It works and shows tooltips properly.. Do you get any error in the console?

Here's how I used your code:

var chartData = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
};

window.onload = function(){
    var ctx = document.getElementById("chart").getContext("2d");
    window.myNewChart = new Chart(ctx).Line(chartData, {
        showTooltip: true,
        tooltipTemplate: "<%= value %>"
    });
};
like image 39
Manolis Avatar answered Sep 29 '22 12:09

Manolis