-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chart.js 3.7.1: Error thrown after updating data and subsequent user interaction #10467
Comments
This still occurs in 3.8.2. Debugging
Possible Causes
SolutionsIt seems like the correct behaviour here is to have CC @kurkle @LeeLenaleee thoughts? |
Did some testing, |
Without looking at the code, doesn't the lookup util return .lo and .hi? |
Won't you get the same issue as you have now with this is you have multiple points with the same x value at the start of the chart?
Yes |
I don't think the issue will happen at the start because we'd look left-to-right for the start and right-to-left for the end. re |
mb, I thought you wanted to search rtl for both points, than it makes more sense. |
Hi, problem is not solved 3.9.1. I updating data and drag viewpoint chart.mjs:8866 Uncaught TypeError: Cannot read properties of undefined (reading 'hitRadius')
at PointElement.inRange (chart.mjs:8866:1)
at evaluationFunc (chart.mjs:5509:1)
at evaluateInteractionItems (chart.mjs:5434:1)
at getNearestCartesianItems (chart.mjs:5540:1)
at getNearestItems (chart.mjs:5549:1)
at nearest (chart.mjs:5637:1)
at Chart.getElementsAtEventForMode (chart.mjs:7668:1)
at Chart._getActiveElements (chart.mjs:8049:1)
at Chart._handleEvent (chart.mjs:8012:1)
at Chart._eventHandler (chart.mjs:7993:1)
at listener (chart.mjs:7832:1)
at Chart.event (chart.mjs:6320:1)
at helpers.segment.mjs:565:1 |
@fast0490f do you have a reproducable because it seems to be solved: https://stackblitz.com/edit/typescript-kzlsgp?file=package.json |
@LeeLenaleee I am still running into this as well. Here is a sample, I've only changed the data slightly from the original. |
Expected behavior
After an update to the data (regardless if data points in the update were considered to be out of the chart area), interaction with the chart should be possible as usual
Current behavior
Context: Simple line chart with point objects, fixed scales (min, max)
An update of dataset's data with additional points causes chart.js to synchronously create empty PointElement instances (buildOrUpdateElements)
Subsequently, LineController checks for visible points (getStartAndCountOfVisiblePoints). If added points lie on or beyond an axis' bounds, previously created PointElement instances remain uninitialized.
If then the user interacts with the chart (hover / click), an Error is thrown, as evaluation functions (e.g. for displaying tooltips) try to access a PointElement's options, which are undefined.
Error in /turbo_modules/[email protected]/dist/chart.js (9319:84)
Cannot read properties of undefined (reading 'hitRadius')
This is causing the chart / app to crash. Happens on any browser, not just the one noted below
Reproducible sample
https://stackblitz.com/edit/typescript-w1ahqk
Optional extra steps/info to reproduce
The provided code (https://github.com/bdorninger/chartjs-update-bug) can be edited on stackblitz: (https://stackblitz.com/edit/typescript-w1ahqk)
Possible solution
If points are considered invisible (due to being out of bounds), please make sure they are properly initialized or are being removed from the internal dataset representation.
Workaround:
Context
In our app, the chart is embedded in an Angular app. Chartjs is used to display live data being sent from a server. The app does not crash, but the chart is not usable anymore in such cases. Page has to be reloaded. Any time "unfavorable" data arrives from the server this happens again. No more interaction possible and the console is filled with error messages
chart.js version
v3.7.1 but also on 3.8.0
Browser name and version
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
Link to your project
https://github.com/bdorninger/chartjs-update-bug
The text was updated successfully, but these errors were encountered: