html - 如何去除工具提示上的颜色标签?
问题描述
我正在尝试从图表工具提示中删除彩色标签方块。我怎样才能在这段代码中实现这一点,而所有其他代码都完好无损?
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Title
</title>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js">
</script>
</head>
<body onLoad="ready()">
<canvas id="myChart" width="600" height="200">
</canvas>
<script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
data: [], //start empty backgroundColor: '#e8ebf8', borderColor: '#615BD4', borderWidth: 1 }] }, options: { scales: { yAxes: [{ ticks: { display: false, beginAtZero: true } }], xAxes: [{ ticks: { stepSize: 2, maxTicksLimit: 90 } }] }, legend: { display: false }, tooltips: { intersect: false, showTooltips: true, tooltipEvents: ["mousemove", "touchstart", "touchmove"], tooltipFillColor: "rgba(0,0,0,0.8)" } } }); window.onmessage = function(event) { myChart.data.datasets[0].data = event.data.data; myChart.data.labels = event.data.labels; myChart.update(); }; function handleClick(e) { var activeBars = myChart.getElementAtEvent(e); var value = myChart.config.data.datasets[activeBars[0]._datasetIndex].data[activeBars[0]._index]; var label = activeBars[0]._model.label; window.parent.postMessage({ "type": "click", // "label":label, "value": value }, "*"); } function ready() { window.parent.postMessage({ "type": "ready" }, "*"); }
</script>
</body>
</html>
解决方案
使用回调功能删除标签:
options: {
legend: {
display: false
},
tooltips: {
callbacks: {
label: function(tooltipItem) {
console.log(tooltipItem)
return tooltipItem.yLabel;
}
}
}
}
推荐阅读
- python - 从控制台上的 PyQt5 浏览器中删除日志
- termux - 如何安装特定的python版本(Termux)
- c++ - stdafx.h:致命错误:afxwin.h:没有这样的文件或目录(适用于 2018 VS 社区,但不适用于 VS 代码)
- node.js - 无法在 Alpine Linux 上运行 node-gdal:“__printf_chk:找不到符号”
- kotlin - 内联行映射器
调用 JdbcTemplate.query(String!, RowMapper !, 可变参数任意!) - python-3.x - 为数据框中的每个类别创建日期时间范围:python/SQL
- html - HTML/CSS 中的响应式表格,第一个单元格作为一整行
- xslt - 访问树中其他地方的属性
- python - BeautifulSoup 通过里面的文字找到一个 div 标签
- cmd - 如何使用 PrintUIEntry 在 Windows 7 x64 中的 IPP 打印机上设置“直接打印到打印机”属性?