0👍
You have to use the custome positioner.
Here is an example on how to implement it:
// Define the custom position mode function
Chart.Tooltip.positioners.custom = function(elements, eventPosition) {
var tooltipWidth = this._chart.tooltip._view.width;
var chartArea = this._chart.chartArea;
var xPosition = eventPosition.x;
var yPosition = eventPosition.y;
// Check if the hovered element belongs to the second dataset
if (elements[0]._datasetIndex === 1) {
// If yes, set the x position to be the center of the chart
xPosition = chartArea.left + chartArea.width / 2;
}
return {
x: xPosition - tooltipWidth / 2,
y: yPosition
};
};
var chartdata = {
= {
type: 'line',
...
options: {
tooltips: {
position: 'custom'
}
}
};
You can find more help in ChartJS documentation
- Chartjs-Have shading begin at 0 but not scale
- Chartjs-How to dynamically render new list of charts based on a dropdown filter?
0👍
I think setting up plugins.tooltip.position
to average
is enough to avoid positioning the tooltip.
Source:stackexchange.com