-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>)
}
}