How to get the datapoint index number in custom positioner for tooltips? #11108
-
I am trying to understand the tooltip. As this is one of items I want to truly learn about Chart.js. However I struggle to get it correctly. I am using a basic HTML file without import and I am very close to the answer but not quite. I get an error of the I did read and studied this example: https://www.chartjs.org/docs/latest/samples/tooltip/position.html, but I just cannot figure it out. As that requires import which I do not use in my HTML file. I hope someone can shed a light on this item.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@Udemology I think the issue here is that the Chart.js/src/plugins/plugin.tooltip.js Lines 644 to 645 in 916aa6e It seems the 2 statements rows might be inverted in the plugin, without any issue. Tests are needed. |
Beta Was this translation helpful? Give feedback.
-
@Udemology what do you think the following examples (are going to what you want?), because having a look to your code, you can do in different ways: The tooltip is fixed in the position of X element Chart.Tooltip.positioners.bottom = function(elements, eventPosition) {
const {chartArea: {bottom}, scales: {x, y} } = this.chart;
return {
x: x.getPixelForValue(x.getValueForPixel(eventPosition.x)),
y: bottom,
xAlign: 'center',
yAlign: 'bottom'
};
}; or (on a bar chart, the tooltip scrolls on the element width) Chart.Tooltip.positioners.bottom = function(elements, eventPosition) {
const {chartArea: {bottom}, scales: {x, y} } = this.chart;
return {
x: eventPosition.x,
y: bottom,
xAlign: 'center',
yAlign: 'bottom'
};
}; |
Beta Was this translation helpful? Give feedback.
@Udemology what do you think the following examples (are going to what you want?), because having a look to your code, you can do in different ways:
The tooltip is fixed in the position of X element
or (on a bar chart, the tooltip scrolls on the element width)