Chartjs显示标签鼠标悬停状态时的单位 [英] Chartjs display label & units when mouse is hover stats
本文介绍了Chartjs显示标签鼠标悬停状态时的单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用标签&鼠标指针悬停在图表上时的单位?目前只有数字.
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...
推荐答案
我找到了解决方法解决方案是,如果图形包含多个数据,则使用选项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
会给您:
- Dataset_label:值
这篇关于Chartjs显示标签鼠标悬停状态时的单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文