简体   繁体   English

你如何隐藏图表工具提示的标题?

[英]How do you hide the title of a chart tooltip?

I'm using chart js to show grouped bar chart and try to hide the title of the tooltip 我正在使用图表j来显示分组条形图并尝试隐藏工具提示的标题

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 通过将titlefontsize设置为0但它不起作用

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 提前谢谢你

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() {}
      }
   },
   ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 悬停时谷歌图表工具提示闪烁,你如何解决它? - Google chart tooltip flashes on hover, how do you fix it? 您如何使用Google图表工具提示和JSON提取元数据 - How do you use google chart tooltip and json to pull metadata 如何隐藏谷歌地理标志中的工具提示标题(并在工具提示中显示其他信息) - How to hide tooltip title in google geocharts (and show other info in the tooltip) 如何从图表中隐藏Highcharts系列,但始终在工具提示中显示? - How do I hide a Highcharts series from the chart, but always show it in the tooltip? 如何使用chart.js为工具提示标题设置默认回调 - How to set default callback for tooltip title with chart.js Chart.js 2.0:如何更改工具提示的标题 - Chart.js 2.0: How to change title of tooltip 如何在Google Chart API中动态控制(显示和隐藏)工具提示? - how to control (show & hide) the tooltip dynamically in google chart api? 如何在chart.js中隐藏某些条形的工具提示 - How to hide tooltip for certain bars in chart.js 如何根据选择隐藏Google图表工具提示操作? - How to hide google chart tooltip action based on selection? 如何使用 charts.js 为折线图设置 x 和 y 轴和标题? - How do you set x and y axis and Title for a line chart using charts.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM