我想在工具提示中隐藏标签,因为它显示未定义

时间:2016-02-16 11:46:29

标签: chart.js linechart

我正在使用chart.js来显示折线图。如何隐藏chart.js折线图的工具提示标签?工具提示中的标签显示print (df / df.xs('All')).reset_index().rename(columns={0:'action_type_percentage'}) action action_type action_type_percentage 0 a Missing 0.181818 1 a Unknown 0.208333 2 b Missing 0.272727 3 b Unknown 0.166667 4 c Missing 0.454545 5 c Unknown 0.250000 6 d Missing 0.090909 7 d Unknown 0.375000 8 All Missing 1.000000 9 All Unknown 1.000000 ,因此我想隐藏标签(请参见屏幕截图)?

也许有一种方法可以修改工具提示,我只能在工具提示中显示图例值?我的代码如下:

undefined

enter image description here

5 个答案:

答案 0 :(得分:6)

只需在您的选项中将tooltipTitleFontSize设置为0

预览

enter image description here

<强>脚本

myLine = new Chart(ctx).Line(lineChartData, {
    ...
    tooltipTitleFontSize: 0
});

答案 1 :(得分:1)

我知道我来晚了,但是我想添加它仍然值得。

检查此:https://stackoverflow.com/a/44632748/12061669

它使用一个函数来隐藏标题:

options:{
   tooltips:{
     callbacks:{
        title: ()=>{}
     }
   }
}

答案 2 :(得分:1)

将标题的字体大小设置为零是不理想的,因为您仍会在工具提示的顶部看到一个(丑陋的)额外空间,好像标题行仍然存在-坦白地说,这是如您所愿。

相反,我使用了Yumin Gui的答案,但必须返回null才能起作用: `

tooltips: {
  callbacks: {
    title: () => null,
  },
},

结果与饼图中的结果完全一样(饼图的默认工具提示中没有标题)。

答案 3 :(得分:0)

正如Aman在评论中所说,接受的答案在chart.js的较新版本中将不起作用,您现在可以使用的是:

tooltips: { titleFontSize: 0 }

示例:

var bar_chart = document.getElementById('bar_canvas').getContext('2d');
window.myBar = new Chart(bar_chart, {
    type: 'bar',
    data: bar_chart_data,
    options: {
        tooltips: {
            titleFontSize: 0,
            bodyFontSize: 14,
        }
    }
});

答案 4 :(得分:0)

要隐藏工具提示标题/标签,应将其添加到该图表的选项对象中,如下所示:

options: {
   plugins: {
      tooltip: {
         callbacks: {
            title : () => null // or function () { return null; }
         }
      }
   }
}

请参阅文档以更好地理解它应该使用自定义回调函数处理,而不是可以直接在选项中设置的配置。