Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Legend overlapping when data from server

class SearchContentChart extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {

    const loadLines = data => data.map((item) => {
      return <Line type="monotone" key={item.key} dataKey={item.key} name={item.name} stroke={item.color} dot={null}/>
    });

    return (
      <ResponsiveContainer height={ 300 }>
        <LineChart data={this.props.data.data || []}>
          <XAxis dataKey="name"/>
          <YAxis />
          <CartesianGrid strokeDasharray="3 3"/>
          <Tooltip />
          <Legend/>
          {loadLines(this.props.data.line || [])}
        </LineChart>
      </ResponsiveContainer>
    )
  }
}

When the component first rendering legend is overlapping but from the next rendering the chart works well.

How can I make it working at the first rendering when I get data from the server side?

like image 411
Gregory Avatar asked Jun 19 '26 13:06

Gregory


1 Answers

Setting debounce={1} to the ResponsiveContainer worked for me.

<ResponsiveContainer debounce={1}>
like image 105
Jason Jin Avatar answered Jun 22 '26 02:06

Jason Jin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!