Chartjs-React-chartjs-2 โ€“ Each dataset needs a unique key

3๐Ÿ‘

โœ…

You can use datasetKeyProvider which returns random id for the each datasets. Here is one example how to use it and function which creates random string using btoa.

 const datasetKeyProvider=()=>{ 
     return btoa(Math.random()).substring(0,12)
 } 

  return (
    <React.Fragment>
      <Line 
          data={data} 
          datasetKeyProvider={datasetKeyProvider}
      />
    </React.Fragment>
  );

Leave a comment