opened
hades200082
username_0
I'm trying to update the values on a bar chart dynamically.  I followed the instructions and get an error "Uncaught TypeError: Cannot read property '0' of undefined"

I've created an example here: http://jsbin.com/zikuzusaqe/edit?html,js,output

It seems that "datasets" is undefined on a bar chart, but the example at http://www.chartjs.org/docs/#bar-chart-prototype-methods shows to use it to update existing data.
Bar charts - Uncaught TypeError: Cannot read property '0' of undefined
issue
created
yanickrochon
username_1
How was this resolved? I have this weird error that only happens when the data is computed. For example:

```js
// adding another dataset..
data.datasets.push({
  label: "Total",
  data: [30, 20, 40, 15]
});
``` 
is fine, but
```js
// adding another dataset..
data.datasets.push({
  label: "Total",
  data: transactions.map(t => t.qty)   // =>  [30, 20, 40, 15]
});
```
fails. This is dumbfounding.
comment
created
Toxyl
username_2
I'm running into an issue at the exact same location as @username_1 but slightly different case:
I have a doughnut chart that is instantiated with several datasets and can be updated by selecting a time span from a dropdown. With one setting the amount of datasets changes from 3 to 4 (i.e. the maximum `datasetIndex` should be 2 and 3 respectively) but after the change it tries to read `databaseIndex` 4 and crashes with `Cannot read property '98' of undefined`. After going back to the previous setting (which has 3 datasets) and then switching back to the problematic case (i.e. 4 datasets) everything works as expected. I'm using the React library `react-chartjs-2`.
comment
created
LeeLenaleee
username_3
@username_2 do you have a working example because I am not able to reproduce the issue you or @username_1 have, with the current master (v3 rc 6, https://jsfiddle.net/Leelenaleee/q9tnLs8y/7/) and latest stable v2 release (2.9.4, https://jsfiddle.net/Leelenaleee/19v8qenz/2/)
comment
created
Toxyl
username_2
@username_3 Unfortunately nothing I can share nor a reliable test case, the only thing that seems to work rather reliable is a doughnut chart that has multiple datasets (in my case 3 but I assume the exact number does not matter). In my React application the chart is part of a component that is refreshed once the data changes. As long as it stays at 3 datasets all is fine, but when a dataset is added it crashes. However, if I start out with a setting that has 4 datasets I can go back to a setting with 3 datasets without crash. But going back to a setting with 4 sets will crash it again. Stepping through the code @username_1's screenshot shows I noticed that the `databaseIndex` is off-by-one.
Be aware that I'm using a React library for ChartJS, so the bug might be hiding in there as well.
comment