-1

enter image description here

image from https://www.chartjs.org/docs/latest/charts/radar.html

I know that I can show tooltip on dataset, but is there any way to display tooltip on label? for example, when I hover on 'Drinking', I want to show description about the label.

amu03
  • 129
  • 11
  • I could create and use the custom toolitip mode: https://www.chartjs.org/docs/latest/configuration/tooltip.html#custom-position-modes – user2057925 Apr 03 '23 at 07:13

1 Answers1

0

I could set a custom interaction mode, as following:

Chart.Interaction.modes.labels = function(chart, e, options, useFinalPosition) {
  const result = [];
  const labels =  chart.data.labels;
  const datasets =  chart.data.datasets;
  for (let i = 0; i < labels.length; i++) {
    const area = chart.scales.r.getPointLabelPosition(i);
    if (e.x >= area.left && e.x <= area.right 
        && e.y >= area.top && e.y <= area.bottom) {
      for (let k = 0; k < datasets.length; k++) {
        const meta = chart.getDatasetMeta(k);
        result.push({
          datasetIndex: k,
          index: i,
          element: meta.data[i]
        });
      }
    }
  }
  return result;
};

the you can set the interaction mode to the tooltip:

plugins: {
  tooltip: {
    mode: 'labels'
  }
},
user2057925
  • 2,377
  • 1
  • 12
  • 12