Chartjs display label amp; units when mouse is hover stats(Chartjs 显示标签 amp;鼠标悬停时的单位统计)
问题描述
是否可以有标签 &当我的鼠标指针悬停在图表上时的单位?目前只有数字.
Is it possible to have the label & units when my mouse pointer is hover the chart ? For now there is only the number.
对于下面的示例,我想展示:
For the example bellow I would like to show :
- 58% 标签1
- 0% 标签2
- 0% 标签3
- 0% 标签4
- 0% 标签5
我的选项如下所示:
var options = {
//Boolean - Show a backdrop to the scale label
scaleShowLabelBackdrop : true,
//Boolean - Whether to show labels on the scale
scaleShowLabels : true,
// Boolean - Whether the scale should begin at zero
scaleBeginAtZero : true,
scaleLabel : "<%%= Number(value) + ' %'%>",
legendTemplate: "<ul class="<%%=name.toLowerCase()%>-legend"><%% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%%=datasets[i].strokeColor%>"></span><%%if(datasets[i].label){%><%%=datasets[i].label%> <strong><%%=datasets[i].value%></strong><%%}%></li><%%}%></ul>",
tooltipTemplate: "<%%= value %> Label"
}
使用 scaleLabel 选项,我在 Y 轴上显示 %,但在悬停弹出窗口上没有显示...
With scaleLabel option I have the % shown on the Y-axis but not on the hover pop-up...
推荐答案
我找到了解决方案 在 Github 上的 ChartJS 存储库中.
解决方案是使用选项multiTooltipTemplate
如果您的图表有多个数据.否则,您应该使用 tooltipTemplate
The solution is to use the option multiTooltipTemplate
if your graph has multiple data. Otherwise, you should use tooltipTemplate
multiTooltipTemplate: "<%=datasetLabel%> : <%= value %>" // Regular use
// or
multiTooltipTemplate: "<%%=datasetLabel%> : <%%= value %>" // Ruby on Rails use
会给你:
- 数据集标签:值
这篇关于Chartjs 显示标签 &鼠标悬停时的单位统计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Chartjs 显示标签 &鼠标悬停时的单位统计


基础教程推荐
- 响应更改 div 大小保持纵横比 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 动态更新多个选择框 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 悬停时滑动输入并停留几秒钟 2022-01-01