Chart.js v2 隐藏数据集标签 [英] Chart.js v2 hide dataset labels

查看:19
本文介绍了Chart.js v2 隐藏数据集标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码使用 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/

这篇关于Chart.js v2 隐藏数据集标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆