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

tooltip callbacks possible? #173

Closed
ssuess opened this issue Aug 16, 2017 · 2 comments
Closed

tooltip callbacks possible? #173

ssuess opened this issue Aug 16, 2017 · 2 comments

Comments

@ssuess
Copy link

ssuess commented Aug 16, 2017

Expected Behavior

In plain old chart.js, I can do something like this in the options:

tooltips: {
          callbacks: {
            label: function (tooltipItem, data) {
              // get the concerned dataset
              var tooltipLabel = data.labels[tooltipItem.index]
              var dataset = data.datasets[tooltipItem.datasetIndex]
              // calculate the total of this data set
              var total = dataset.data.reduce(function (previousValue, currentValue, currentIndex, array) {
                return previousValue + currentValue
              })
              // get the current items value
              var currentValue = dataset.data[tooltipItem.index]
              // calculate the precentage based on the total and current item, also this does a rough rounding to give a whole number
              var precentage = Math.floor(((currentValue / total) * 100) + 0.5)
              return tooltipLabel.replace(/-/g, ' ') + ': ' + precentage + '%'
            }
          }
        }

Actual Behavior

But in vue-chartjs, it is being ignored, and/or I don't seem to be accessing the data. Is there a way I should refer to this? (I have tried the same data object name as for the chart to no avail, and also tried this._chart.data with no success)

@apertureless
Copy link
Owner

apertureless commented Aug 17, 2017

Well the tooltip callbacks are working

https://codepen.io/apertureless/pen/BZKBdX

If you hover you will see the data in the console. And you can access it.

@ssuess
Copy link
Author

ssuess commented Aug 17, 2017

misplaced brackets, your example helped. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants