Skip to content

Out-of-range datapoints are shown in tooltip of scatter chart #10108

Description

Expected behavior

When hovering a scatter chart, no tooltip should be displayed for datapoints that are outside of the range defined by the Axis Range Settings (https://www.chartjs.org/docs/latest/axes/#axis-range-settings).

Current behavior

When hovering a scatter chart, it can happen that a tooltip is displayed for a datapoint that is outside of the range defined by the Axis Range Settings (https://www.chartjs.org/docs/latest/axes/#axis-range-settings).

In the attached reproducible sample, when you hover the chart near the point (1,0), the datapoint (0,0) is displayed in the tooltip although the min setting for the x axis is 1 and so (0,0) is out of range.

Additional information:

  • This seems to be more likely to happen when there is a large number of datapoints and/or the chart area is small, so it might be due to a rounding error.
  • It can be worked around by subtracting a large enough offset from all x coordinates that are less than the min value. Removing those datapoints from the data all together is usually not an option if you need the animation to work when you switch between different views into a set of datapoints by changing the range settings.

bug

Reproducible sample

https://codepen.io/ms-tng/pen/RwjPYGX

Optional extra steps/info to reproduce

Hover the chart near the point (1,0)

Possible solution

It seems that the comparison between coordinates and range settings is done after converting to pixel values, which can lead to rounding errors. Maybe this comparison can be done on the coordinates directly.

See https://github.com/chartjs/Chart.js/blob/v3.7.0/src/controllers/controller.line.js#L154

Context

No response

chart.js version

v3.7.0

Browser name and version

Google Chrome 97.0.4692.99

Link to your project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions