frappe / charts

Simple, responsive, modern SVG Charts with zero dependencies
https://frappe.io/charts
MIT License
14.94k stars 717 forks source link

Missing legend causes uncaught errors when updateing data. #409

Open echobops opened 1 year ago

echobops commented 1 year ago

Expected Behaviour

Replacing data on a bar chart that previusly had 1 data set item, with new data that has 2+ dataset items, the legend should appear and show the data.

Actual Behaviour

Replacing the datasets with 2+ items on a bar chart that only has 1 current dataset item will throw an error in the console and fail to render the chart:

Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'textContent')

This is likely caused by the fact that a single dataset item bar chart does not create a legend. When replacing the data with something that now needs a legend, the code assumes one is present and attempts to set the names on the legend.

Steps to Reproduce:

NOTE: Add a GIF/Screenshot if required.

Frappé Charts version: 1.6.2 Codepen / Codesandbox: