I have created a line chart using react-highcharts
. It has 3 series and different data for each of them. And I have a range-selector that changes the data of the series dynamically. The chart looks like this:
It works all fine but the problem is whenever I change the risk value on the range-selector, the chart re-renders with new series' data. I don't want it to re-render every time. I want the series' data change with animation. Something like this: Live random data. And here is my related code:
class ContributionRiskGraph extends React.Component {
constructor() {
super();
this.state = {
riskValue: 8.161736
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(value) {
this.setState({
riskValue: value
});
}
render() {
const riskValue = this.state.riskValue / 100;
const LBData = getGraphPlotData(riskValue, 'lowerBound');
const EVData = getGraphPlotData(riskValue, 'expectedValue');
const UBData = getGraphPlotData(riskValue, 'upperBound');
const config = {
chart: {
animation: {
duration: 1000
}
},
title: {
text: 'Contribution Risk Graph'
},
series: [
{
name: 'Lower Bound',
data: LBData,
type: 'spline',
tooltip: {
valueDecimals: 2
}
},
{
name: 'Expected Value',
data: EVData,
type: 'spline',
tooltip: {
valueDecimals: 2
}
},
{
name: 'Upper Bound',
data: UBData,
type: 'spline',
tooltip: {
valueDecimals: 2
}
}
],
yAxis: {
gridLineWidth: 0,
opposite: true
},
xAxis: {
gridLineWidth: 2,
labels: {
formatter: function() {
if (this.value <= 1) {
return this.value + ' month';
}
return this.value + ' months';
}
}
},
};
return(
<div>
<ReactHighcharts config={config} />
<div style={{ display: 'flex', justifyContent: 'center', marginTop: 30 }}>
<RangeSlider
label="Risk Value"
defaultValue={8}
min={1}
max={62}
handleChange={this.handleChange}
/>
</div>
</div>
)
}
}