amcharts / amcharts3-react

Official amCharts V3 React component
Apache License 2.0
117 stars 50 forks source link

Chart not reflecting changes after validateNow is called #18

Open pranavkaushik9 opened 7 years ago

pranavkaushik9 commented 7 years ago

When I change the configuration for chart, it calls validateNow but this is not causing the chart to redraw

https://github.com/amcharts/amcharts3-react/blob/master/amcharts3-react.js#L195

Pauan commented 7 years ago

@pranav-xx Could you please provide your code?

yairEO commented 7 years ago

for me, when I call the validateNow method on my amChart (after it was rendered on the screen and nothing else was happening) the whole chart disappears!

Pauan commented 7 years ago

@yairEO You shouldn't call validateNow or validateData

Instead, you should:

  1. Create some state for your component.

  2. Use the state in the render method.

  3. Use setState to change the state.

This is the normal way to change state in React.

nk2580 commented 6 years ago

this does not rigger a change in the chart for me though, even though my data is there.. why is that?

raymondsiu commented 6 years ago

@nk2580 I had this issue before when my render method made reference to a config like:

class Chart extends React.Component {
  render() {
    const { styles, config } = this.props;
    return (
      <div style={ styles }>
        <AmCharts.React options={config} />
      </div>
    );
  }
}

When I made updates to the config prop it wasn't causing re-renders because passing the config to the component was passing by reference. To force the re-render and essentially update the chart, everytime I updated the config prop from the parent component, I would use _.cloneDeep(config) to ensure a new reference is generated.

Hope that sort of helps.