Chartjs 显示标签 &鼠标悬停时的单位统计 [英] Chartjs display label & units when mouse is hover stats

查看:17
本文介绍了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...

推荐答案

我找到了解决方案 在 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 显示标签 &amp;鼠标悬停时的单位统计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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