When the data changes in echarts-for-react, how to update the chart in real time.

-when sharp-sharp-sharp clicks on the chart, the data data changes and the chart cannot be refreshed in real time.

import React from "react";
import { Card } from "antd";
import ReactEchartsCore from "echarts-for-react/lib/core";
import echarts from "echarts/lib/echarts";
import "echarts/lib/chart/pie";
echarts.registerTheme("myTheme",{
    backgroundColor: "rgb(15,55,95)"
});
export default class Bar extends React.Component{
    constructor(props){
        super(props);
        this.state={
            loadingChart:true,
            data:[
                { value: 500, name: "Android" },
                { value: 200, name: "IOS" },
                { value: 360, name: "PC" },
                { value: 100, name: "Ohter" }
             ]
        }
    }
    onChartClick=()=>{
        const data=this.state.data;
        data.push({
            value:Math.random()*100,
            name:"Other"+Math.random()
        });
        this.setState({
            data
        });
    }
    onChartLegendselectchanged = () => {
        console.log(2)
    }

    // 
    onEvents = {
        "click": this.onChartClick,
        "legendselectchanged": this.onChartLegendselectchanged
    }

    // 
    getOption=()=>{
            const option = {
                title:{
                    text:"ECharts "
                }, 
                lengend:{},        
                series:[{
                    name:"",
                    type:"pie",    
                    radius:"60%", 
                    data:this.state.data
                }]
            };
            return option;
    }

    // charts loadReady 
    onChartReadyCallback=()=>{
        setTimeout(()=>{
            this.setState({
                loadingChart: false
            });
        } ,2000);
    }

  render(){
    return (
      <div>
        

{JSON.stringify(this.state.data)}

<Card title=""> <ReactEchartsCore echarts={echarts} style={{ height: "500px" }} className="noneClass" theme="light" onChartReady={this.onChartReadyCallback} option={this.getOption()} showLoading={this.state.loadingChart} onEvents={this.onEvents} lazyUpdate={(this.getOption(),false)} > </ReactEchartsCore> </Card> </div>) } }

you need to use echarts's setOption
I wrote it with function components

<ReactEcharts
    ref={(e) => { refs.echartsReact = e; }}
    className="graph"
    option={options}
    notMerge={false}
    lazyUpdate={true}
    style={style || {height:'484px',width:'685px'}}
/>

refs.echartsReact.getEchartsInstance().setOption(options); 

data has changed, but the option in echarts has not been recalculated, so you need to call this.getOption () again to calculate the new data. You can put getOption () in render

.
Menu