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.

When updating data dynamically, Axis is not updated

See original GitHub issue

I used websocket to dynamically update state, and now the curve has changed, but the value on the axis is unchanged

I want the chart to show changes with the state changes, is there any way?

version: 0.22.3

import React, { Component } from 'react';
import { ComposedChart, Line, Area, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';

export default class extends Component {
  static defaultProps = {
    chartData: [],
  };

  state = {
    chartData: this.props.chartData,
  }

  componentWillReceiveProps({ chartData }) {
    if (this.props.chartData !== chartData) {
      this.setState({ chartData });
    }
  }

  render() {
    const { chartData } = this.state;
    return (
      <div>
        {
          chartData.length ? <ResponsiveContainer height={250} >
            <ComposedChart data={chartData} margin={{ top: 0, right: -15, left: -8, bottom: 0 }} >
              <XAxis dataKey="Name" />
              <YAxis yAxisId="left" orientation="left" />
              <YAxis yAxisId="right" orientation="right" />
              <CartesianGrid strokeDasharray="3 3" />
              <Tooltip />
              <Legend />
              <Area yAxisId='left' type='monotone'  dataKey='TotalCount' fill={'#00BCD4'} stroke={'#00BCD4'}  />
              <Line yAxisId='right' type='monotone'  dataKey='AverageElapsed' stroke={'#00E676'} unit='ms' />
              <Bar yAxisId='right' type='monotone'  dataKey='TotalErrors' fill={'#F44336'}  />
            </ComposedChart>
          </ResponsiveContainer> : <div className='chart-empty'>empty</div>
        }
      </div>
    )
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
xiaoyu-tamucommented, Oct 17, 2019

It’s still an issues on version 1.8.1

No plan to fix this issue?

workaround to pass random key to force rerender…

    <YAxis
          key={Math.random()}
          orientation="right"
          yAxisId="y2"
    />
8reactions
TheWildHorsecommented, May 26, 2018

The problem for me was that the API returned the numbers in a string format which confused Recharts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The x-axis values do not update when change the values
Hello,. format the X axis and ensure that the minimum and maximum values are not set to fixed numbers, but "Auto", so Excel...
Read more >
Y axis not fixed after updating graph data dynamically angular ...
Hi, I have horizontal scroll graph and data will be updated dynamically from api. When data is updated y-axis also scrolls along with...
Read more >
jquery flot chart does not update X axis values dynamically for ...
I want my chart's x axis to be changed for given data. I put a sample code into fiddle here. X axis is...
Read more >
Axes not updating dynamically in panel histogram plots
I'm trying to generate a histogram plot that responds dynamically to two Select panel widgets that select data from a dataframe: one widget ......
Read more >
Update Axis after updating datasource | Angular - EJ 2 Forums
By default, based on the data given to the chart, datetime axis will calculate the auto label format and interval type, so on...
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