Chartjs-How to set default callback for tooltip title with chart.js

1👍

Replace key global with horizontalBar

Chart.defaults.horizontalBar.tooltips.callbacks.title = function(tooltipItems, data) {
  return "Overriden title"; // This code is executed
};

new Chart($("#barchart"), {
  type: 'horizontalBar',
  data: {
    "labels": ["Label"],
    "datasets": [{
      "data": [42]
    }]
  },
});
<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