Chart.js v2 隐藏数据集标签标签、数据、Chart、js

2023-09-07 11:31:35 作者:笑叹★尘世美

我有以下代码使用 Chart.js v2.1.3 创建图表:

I have the following codes to create a graph using Chart.js v2.1.3:

var ctx = $('#gold_chart');
var goldChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: dates,
        datasets: [{
            label: 'I want to remove this Label',
            data: prices,
            pointRadius: 0,
            borderWidth: 1
        }]
    }
});

代码看起来很简单,但我无法从图表中删除标签.我尝试了很多网上找到的解决方案,但大多数都使用 Chart.js v1.x.

The codes look simple, but I cannot remove the label from the graph. I tried a lot of solutions I found online, but most of them use Chart.js v1.x.

如何删除数据集标签?

推荐答案

像这样设置 labeltooltip 选项

Just set the label and tooltip options like so

...
options: {
    legend: {
        display: false
    },
    tooltips: {
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }
}

小提琴 - http://jsfiddle.net/g19220r6/

 
精彩推荐
图片推荐