question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

chart not updating

See original GitHub issue

I’m trying to get my chart to update dynamically as new data comes in (from socket.io) so I have a method onChange(data) that is used as the callback function of setState called when the new data comes in.

The Chart however does not update itself… unless I refresh/resize the browser. If I set redraw={true}, then the chart updates but it seems to refresh the whole page (?) and kills the performance for the rest of the page…

Any idea what I’m doing wrong here?

import React from 'react'
import ReactDOM from 'react-dom'

import {Line} from 'react-chartjs-2'

module.exports =  class MyChart extends React.Component {

  constructor(props)
  {
      super(props)
      this.buffersize

      this.data = {
        labels: [],
        datasets: [
          {/
            label: 'My Chart',
            data: []
          }
        ]
      }

  }

  onChange(newdata) {

    const size = this.data.datasets[0].data.length
    if (size >= this.buffersize)
    {
      this.data.datasets[0].data.shift()
      this.data.labels.shift()
    }

    this.data.labels.push(newdata.label)
    this.data.datasets[0].data.push(newdata.value)

  }

  render()
  {
    return (
      <Line data={this.data}/>
    )
  }

}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:44

github_iconTop GitHub Comments

60reactions
nealokecommented, Jan 5, 2017

@dmichel76 Don’t you need to use the redraw prop like so? (This did it for me)

<Line data={this.data} redraw />

52reactions
jim-alexandercommented, Jul 31, 2018

@gor181 Thanks!

just using key={Math.random()} in my chartjs component did the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Excel Chart Not Updating with New Data (2 Suitable Solutions)
2 Solutions If Excel Chart Is Not Updating with New Data · Steps: · Step 1: Create Defined Names and Set Dynamic Formulas...
Read more >
Update the data in an existing chart - Microsoft Support
Learn how to update the data in an existing chart from its source. Edit a chart in Excel, create a chart from a...
Read more >
KB0163: Charts linked with Excel data link do not update after ...
Problem. I have a think-cell chart linked to an Excel workbook and the Excel's calculation mode is set to manual. When I copy...
Read more >
[SOLVED] Chart not updating - Excel Help Forum
Tried opening a new workbook, using the same values as a data set, recreated the chart and all works fine when updating values....
Read more >
How to auto update a chart after entering new data in Excel?
Supposing you have created a chart to track the daily sales based on a range of data in your workbook. But you need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found