Add dataset indexes to tooltipModel
See original GitHub issueFeature Proposal
I think it would make sense to include an array of dataset indexes in the tooltipModel that is passed to any custom tooltip callback. The array should contain the index for each dataset that was included when calculating the position for the tooltip. Another way to phrase it is to say that the array should contain the index for each dataset that the tooltip belongs to.
Feature Use Case
Knowing which datasets the tooltip belongs to would make it possible to know what data to show in it if one e.g. uses the ‘nearest’ position option. For example, I have a custom tooltip (position: 'nearest'
) in which I want to show the current value it’s pointing to. In the tooltipModel, I just get a list of all the datasets that are relevant at the current index. By knowing which dataset the tooltip belongs to, I can easily pick out the right data from dataPoints
. Currently, this is only possible by performing a (possibly faulty) comparison of caretY
and dataPoints[...].y
.
Possible Implementation
It looks like perhaps the positioners
functions can easily be modified to return an array on top of the x and y coordinate, and then that array could easily be added to the model as something like “datasets”, “datasetIndexes”, or maybe “belongsTo”. If the change is this “simple”, I could try submitting a PR for it.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10 (3 by maintainers)
Top GitHub Comments
As of chart.js 3.0 you can get a single element array in a multi-dataset by setting tooltip mode to
point
.Closing as resolved