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.

How to completely rerender the graph?

See original GitHub issue

What is the current behavior?

When I change the data to LineChart, the only curve is rerendered. But the initial animation(showing the drawing of the graph) is not there. I am using this into a ResponsiveContainer. Here is my state and state update function:

state = {
    first: true,
    second: false,
    color: '#44cc44'
  }

  componentDidMount () {
    this.timer = setInterval(() => {
      if (this.state.first) {
        this.setState({
          first: false,
          second: true,
          color: '#44cc44'
        })
      } else {
        this.setState({
          first: true,
          second: false,
          color: '#ff0000'
        })
      }
    }, 4000)
  }
{
                this.state.first
                  ? (
                    <ResponsiveContainer height={120}>
                      <LineChart data={data0}>
                        <Line type='monotone' dataKey='pv' dot={false} strokeWidth={5} stroke={this.state.color} />
                        <CartesianGrid vertical={false} />
                      </LineChart>
                    </ResponsiveContainer>
                  )
                  : (
                    <ResponsiveContainer height={120}>
                      <LineChart data={data1.slice()}>
                        <Line type='monotone' dataKey='pv' dot={false} strokeWidth={5} stroke={this.state.color} />
                        <CartesianGrid vertical={false} />
                      </LineChart>
                    </ResponsiveContainer>
                  )
              }

What is the expected behavior?

When I change the data, the whole graph should be rerendered.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
klarstrupcommented, Mar 18, 2019

You can force a remount by setting and changing the key prop

1reaction
AdamAvixcommented, Jan 28, 2020

Thank you @klarstrup, this just saved me hours of headache with this finicky library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mange the re-rendering of components through the app
When I uncheck the checkbox on a <ChartDataList> I would like to update the chart's options to provoke a re-render of the chart....
Read more >
Force chart re-render and ZoomPanModifier beyond min and ...
After I load all my data to the chart, how can I force to re-render the chart? The problem I'm having is that...
Read more >
Updating Charts - Chart.js
To update the options, mutating the options property in place or passing in a new options object are supported. If the options are...
Read more >
How to check if your component rerendered - and why!
There's a very handy tooltip that shows up when hovering over a component in the "Flamegraph", that shows the reason for a render...
Read more >
Force re-render function React component (or class component)
For example, when you need to fetch fresh data and re-render a graph for example. Below is some imaginary random data, you can...
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