[Chartjs]-Chartjs display label & units when mouse is hover stats

13πŸ‘

βœ…

I found the solution on the ChartJS repository on Github.

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

Will give you :

  • Dataset_label : value

8πŸ‘

Try this one, it will work. You just need to check what’s the data coming in the label function.

options: {
  tooltips: {
    callbacks: {
      title: function() {
        return "";
      },
      label: function(item, data) {
        var datasetLabel = data.datasets[item.datasetIndex].label || "";
        var dataPoint = item.yLabel;
        return datasetLabel + ": " + dataPoint + "min";
      }
    }
  }
}

Leave a comment