React-chartjs-2: "datasetKeyProvider" as a prop that returns a unique key.

Created on 1 Aug 2018  路  2Comments  路  Source: reactchartjs/react-chartjs-2

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.

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} />

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flyingpath picture flyingpath  路  5Comments

pkellner picture pkellner  路  4Comments

alexchoiweb picture alexchoiweb  路  3Comments

Holychung picture Holychung  路  4Comments

jbbae picture jbbae  路  5Comments