Chartjs-Show the latest labels in a bar chart with React.js using react-chartjs

1👍

Pass only the latest n number of data for every 10 seconds.

const updatedData = {...this.props.loadInfo[0]}

const newData = {
  data: {
    labels: [...updatedData.labels].reverse().slice(0, 30).reverse(),
    datasets: [...updatedData.datasets].reverse().slice(0, 30).reverse(),
  }
}

const newLimitedData = {...updatedData, ...newData }

<Bar data={newLimitedData.data} options={newLimitedData.options} width="600" height="250" />

Hope this helps!

Leave a comment