Chartjs-Chartjs: get the label title on the radar's chart tooltip

1👍

Inside chart options, you need to define a tooltip callback for title as follows:

tooltips: {
  callbacks: {
    title: (tooltipItem, data) => data.labels[tooltipItem[0].index]
  }
}

Please have a look at your amended code below.

new Chart('chart1', {
  type: 'radar',
  data: {
    labels: ['coaster 1', 'coaster 2', 'coaster 3', 'coaster 4'],
    datasets: [{
      label: 'Altura',
      data: [10, 12, 13, 14]
    }]
  },
  options: {
    tooltips: {
      callbacks: {
        title: (tooltipItem, data) => data.labels[tooltipItem[0].index]
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="chart1" height="120"></canvas>

Leave a comment