I crate a data set and put into the chart but after react component update, It is not update the graph and show error
[react-chartjs-2] Warning: Each dataset needs a unique key. By default, the "label" property on each dataset is used. Alternatively, you may provide a "datasetKeyProvider" as a prop that returns a unique key.
I was bit confused as well, but then i just followed the raw meaning of the error.
I passed a function to datasetKeyProvider that returns a unique key and warning disappeared, boom !
Like this
datasetKeyProvider(){
return Math.random();
}
<Line
...props
datasetKeyProvider={this.datasetKeyProvider}
/>
That is the improper way of doing it. To fix this issue all you need to do is to define a variable called "label" a unique ID.
https://github.com/jerairrest/react-chartjs-2#working-with-multiple-datasets
Most helpful comment
I was bit confused as well, but then i just followed the raw meaning of the error.
I passed a function to datasetKeyProvider that returns a unique key and warning disappeared, boom !
Like this
datasetKeyProvider(){ return Math.random(); } <Line ...props datasetKeyProvider={this.datasetKeyProvider} />