Chartjs-Change tooltips title at chart.js?

0👍

You can try to update the title callback like:

title: function(tooltipItem, data) {
    return new_title[tooltipItem[0].index]; 
},

DEMO:

const new_title = ['This is a custom title'];
new Chart($("#barchart"), {
  type: 'horizontalBar',
  data: {
    "labels": ["Label"],
    "datasets": [{"data": [40]}]
  },
  options: {
    tooltips: {
      callbacks: {
        title: function(tooltipItem, data) {
          return new_title[tooltipItem[0]['index']];
        }
      }
    }
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js"></script>

<canvas id="barchart" width="80" height="20"></canvas>

Leave a comment