Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
React D3 graph renders differently for same data

I have a component that renders react D3 graph. And I have a switch that displays graph1 when its ON and displays graph2 when its OFF.

Basically there was react conditional rendering based on one variable state.

Issue is: graph1 is appearing differently. When component loads first time, it looks different. When switch is OFF(graph2) and then again ON(graph1), now it looks different.

enter image description here

enter image description here

Code:

    handleChange = function() {
    if(this.state.nwtb) {
        // this.setState({data: swtb_data, nwtb: false});
        this.setState({nwtb: false});
    } else {
        // this.setState({data: nwtb_data, nwtb: true});
        this.setState({nwtb: true});
    }
};

render() {
  return (
    <div>
        <div>
            <Switch onChange={this.handleChange.bind(this)} checked={this.state.nwtb} />
        </div>
        <div>
            {this.state.nwtb ? <Graph id="graph" 
                config={this.config} 
                data={this.data} 
                onClickGraph={this.onClickGraph}
                onClickNode={this.onClickNode}
                onDoubleClickNode={this.onDoubleClickNode}
                onRightClickNode={this.onRightClickNode}
                onClickLink={this.onClickLink}
                onRightClickLink={this.onRightClickLink}
                onMouseOverNode={this.onMouseOverNode}
                onMouseOutNode={this.onMouseOutNode}
                onMouseOverLink={this.onMouseOverLink}
                onMouseOutLink={this.onMouseOutLink}
                onNodePositionChange={this.onNodePositionChange}
                onZoomChange={this.onZoomChange} /> 
            : <Graph id="graph" 
                config={this.config} 
                data={this.nwtb_data} 
                onClickGraph={this.onClickGraph}
                onClickNode={this.onClickNode}
                onDoubleClickNode={this.onDoubleClickNode}
                onRightClickNode={this.onRightClickNode}
                onClickLink={this.onClickLink}
                onRightClickLink={this.onRightClickLink}
                onMouseOverNode={this.onMouseOverNode}
                onMouseOutNode={this.onMouseOutNode}
                onMouseOverLink={this.onMouseOverLink}
                onMouseOutLink={this.onMouseOutLink}
                onNodePositionChange={this.onNodePositionChange}
                onZoomChange={this.onZoomChange} />
            }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!