How to show tooltips in Chart.js?

前端 未结 3 1698
再見小時候
再見小時候 2021-01-12 17:14

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.



        
3条回答
  •  别那么骄傲
    2021-01-12 17:42

    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 %>"
        });
    };
    

提交回复
热议问题