Chart.js: Would it be possible to display a tooltip based on closest line on the x-axis

Created on 26 Feb 2016  路  12Comments  路  Source: chartjs/Chart.js

Hi again,

When displaying a line chart with a lot of data (30+ values) it becomes really awkward to hover over a point and display the tooltip without getting the mouse really close to it, even with the hit radius increased as it gets to the point where the hit radius of multiple points cross over. Would it be possible to have a hover option that will display the tooltip depending on what point you're closest in regards to the x-axis? By this I mean if you had a line chart with 10 points on the x-axis and your mouse is on the chart halfway between the x-axis and the line of data, it will display the tooltip and activate the hover for the point on the linechart that corresponds to how far along the x-axis you are.

Sorry if it isn't clear, it's quite difficult to explain. If you need me to try and clarify feel free to ask.

Thanks

enhancement

Most helpful comment

For anybody getting here, since 2.4.0, you may simply set your tooltip configuration (options.tooltips or Chart.defaults.global.tooltips) with the following options:

{
  mode: 'index',
  intersect: false
}

You may set the same options to the hover configuration (options.hover or Chart.defaults.global.hover) so that your points are rendered at the same time as the tooltips.

More info in the documentation.

All 12 comments

@dibsyjr1 I think I understand what you are asking for. You'd like the tooltip to always point to the closest point, even when the hitRadiusof 2 points are overlapping. Is this correct?

Hi, thanks for the reply, no sorry, I mean just like this example in the version 1 docs where the vertical position of the cursor is irrelevant and instead it works purely on the horizontal position

http://www.chartjs.org/docs/#line-chart-introduction

@dibsyjr1 ok, I understand. I think we can easily add this back.

+1 !

@dibsyjr1 @etimberg sorry In this post I don't find the solution to this problem (english poor), what is the solution to retrieve this feature like in v1 please

THIS WAS IMPORTANT feature for all touchdevices because we can "touchmove" on X axis or on label (independent of Y touchmove) and we see the tooltip appeare so when this feature come back ! thanks in advance

thanks very much (advice: add this feature back in next release please)

Merging with #2299

For anybody getting here, since 2.4.0, you may simply set your tooltip configuration (options.tooltips or Chart.defaults.global.tooltips) with the following options:

{
  mode: 'index',
  intersect: false
}

You may set the same options to the hover configuration (options.hover or Chart.defaults.global.hover) so that your points are rendered at the same time as the tooltips.

More info in the documentation.

mode: 'index' does not work when multiple dataset have different starting points on the x-axis. Any solution for this issue?

screen shot 2017-11-17 at 14 01 03

@JelleBlaauw yep, I have the same problem. My datasets have different starting dates and like in the picture when I hover the gray line, it will it will hilight the orange line on the "wrong" index (red arrow). I would like it to show the value from the same date (green arrow). Is this missing feature or am I doing something wrong here?

aparently it is in the current version using

options: {
    tooltips: {
        mode: 'x'
    }
}

and it is in here
https://www.chartjs.org/docs/latest/general/interactions/modes.html#x

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bytesnz picture bytesnz  路  3Comments

lizbanach picture lizbanach  路  3Comments

frlinw picture frlinw  路  3Comments

Woogles picture Woogles  路  3Comments

JAIOMP picture JAIOMP  路  3Comments