The Wayback Machine - https://web.archive.org/web/20200225152430/https://github.com/chartjs/Chart.js/issues/6216
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not clear how to override the default tooltip #6216

Closed
guillaumekpomda opened this issue Apr 18, 2019 · 1 comment · Fixed by #6918
Closed

Not clear how to override the default tooltip #6216

guillaumekpomda opened this issue Apr 18, 2019 · 1 comment · Fixed by #6918

Comments

@guillaumekpomda
Copy link

@guillaumekpomda guillaumekpomda commented Apr 18, 2019

Documentation Is:

  • Missing or needed
  • Confusing
  • Not Sure?

The problem

When you want to alter the default tooltip for a chart, it is not clear how to do it:
https://www.chartjs.org/docs/latest/configuration/tooltip.html#label-callback

I had to dig in the source code of chart.js to see what the default callback looked like.

My proposal for Changes

Replace the example in the documentation with an example that actually works:

Example

var chart = new Chart(ctx, {
    type: 'line',
    data: data,
    options: {
        tooltips: {
            callbacks: {
                label: function(tooltipItem, data) {
                  var dataLabel = data.labels[tooltipItem.index];
                  var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];

                  if (helpers$1.isArray(dataLabel)) {
                    // show value on first line of multiline label
                    // need to clone because we are changing the value
                    dataLabel = dataLabel.slice();
                    dataLabel[0] += value;
                  } else {
                    dataLabel += value;
                  }

                  return dataLabel;
                }
            }
        }
    }
});
@rugk

This comment has been minimized.

Copy link

@rugk rugk commented Jun 11, 2019

Thanks, this is indeed strange. The actual up-to-date code can be found here:

label: function(tooltipItem, data) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.