chart not updating
See original GitHub issueI’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:
- Created 7 years ago
- Reactions:6
- Comments:44
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dmichel76 Don’t you need to use the
redraw
prop like so? (This did it for me)<Line data={this.data} redraw />
@gor181 Thanks!
just using
key={Math.random()}
in my chartjs component did the trick.