score:1

Accepted answer

you can do this easily by referring to the current dataset index tooltipitems.datasetindex and then based on that index set the tooltip text like:

label: function(tooltipitems, data) {
    var text = tooltipitems.datasetindex === 0 ? 'some text 1' : 'some text 2'
    return tooltipitems.ylabel + ' ' + text;
}

working demo:

var ctx = document.getelementbyid('mychart').getcontext('2d');
var chart = new chart(ctx, {
  // the type of chart we want to create
  type: "line",
  // the data for our dataset
  data: {
    labels: array.from({length: 5}, (x,i)=> `label ${i+1}`),
    datasets: [{
      label: "dataset 1",
      data: [12, 123, 234, 32, 23],
    }, {
      label: "dataset 2",
      data: [4, 54, 765, 45, 5],
    }]
  },
  // configuration options go here
  options: {
    tooltips: {
      enabled: true,
      mode: 'single',
      callbacks: {
        label: function(tooltipitems, data) {
          var text = tooltipitems.datasetindex === 0 ? 'some text 1' : 'some text 2'
          return tooltipitems.ylabel + ' ' + text;
        }
      }
    }
  }
});
.chart-container {
   width: 500px;
}
#mychart {
  display: block; 
  width: 500px; 
}
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>

<div class="chart-container">
    <canvas id="mychart"></canvas>
</div>


Related Query