Cannot read property 'data' of undefined: Plotly.newPlot missing data handling
19K reputation · 05 Jan 2023, 18:05 UTC
Goal
The objective is to migrate a small Plotly.js application to a newer release without downtime. During the transition, the application may temporarily lack data when initializing charts.
Constraint
Plotly.newPlot throws a runtime exception – "Cannot read property 'data' of undefined" – when its first argument is undefined or null. The library documentation states that the data array is required, but it does not clarify how to handle missing data during dynamic loading.
Uncertainty
There is an unresolved decision in the codebase and community discussions: should Plotly.js silently create an empty trace when data is undefined, or should it continue to throw the error? This choice directly impacts migration strategies, as a silent fallback could allow charts to render during a data fetch delay, whereas an exception would require additional error handling in the application.
Questions
- Does Plotly.js provide a configuration option or a future release plan to suppress the "Cannot read property 'data' of undefined" error when data is missing?
- What is the recommended pattern for handling temporary data absence in a migration scenario—explicitly passing an empty array, using a placeholder trace, or wrapping the call in try/catch?
- Will future versions of Plotly.js change this error handling behavior, and how should a migration plan account for that potential shift?