Skip to content

chart.js 3.7.1: Error thrown after updating data and subsequent user interaction #10467

@bdorninger

Description

@bdorninger

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/chart.js@3.7.1/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)

  • Start the app
  • Wait for 2 secs until data is updated
  • Interact with the chart --> Error is thrown

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:

  • enable animations, set duration value to zero, if no animation wanted seems to help

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

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