When updating data dynamically, Axis is not updated
See original GitHub issueI 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:
- Created 6 years ago
- Comments:16 (2 by maintainers)
Top 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 >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
It’s still an issues on version 1.8.1
No plan to fix this issue?
workaround to pass random key to force rerender…
The problem for me was that the API returned the numbers in a string format which confused Recharts.