How do you hide the title of a chart tooltip?

删除回忆录丶 提交于 2020-01-22 18:56:07

问题


I'm using chart js to show grouped bar chart and try to hide the title of the tooltip

Code to generate bar

var ctx = document.getElementById("myChart").getContext("2d");

var data = {
    labels: ["Chocolate", "Vanilla", "Strawberry"],
    datasets: [
        {
            label: "Blue",
            backgroundColor: "blue",
            data: [3,7,4]
        },
        {
            label: "Red",
            backgroundColor: "red",
            data: [4,3,5]
        },
        {
            label: "Green",
            backgroundColor: "green",
            data: [7,2,6]
        }
    ]
};

var myBarChart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: {
        barValueSpacing: 20,
        scales: {
            yAxes: [{
                ticks: {
                    min: 0,
                }
            }]
        }
    }
});

In the tooltip it showing the labels Chocolate,Vanilla,Strawberry and i have tried to hide the label with following

by setting the titlefontsize to 0 but it doesnt work

tooltipTitleFontSize: 0

and i have tried with the tooltip callbacks it disables the label blue,red,green but i wont need that

 tooltips: {
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }

Help me thanks in advance


回答1:


To hide the title of tooltip, you need to return an empty function on tooltips title­'s callback, like so ...

options: {
   tooltips: {
      callbacks: {
         title: function() {}
      }
   },
   ...
}


来源:https://stackoverflow.com/questions/44632529/how-do-you-hide-the-title-of-a-chart-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!