echarts-on-react
v1.0.3
Published
A flexible echarts wrapper for react.
Downloads
4
Readme
echarts-on-react
A flexible echarts wrapper for react.
1. install
npm install --save echarts-on-react
2. use
import EchartsOnReact from 'echarts-on-react/lib/EchartsOnReact';
import echarts from 'echarts';
...
<EchartsOnReact
ref={(chartRef) => {
this.echartsReact = chartRef;
}}
echarts={echarts}
options={options}
updateData={this.state.data}
notMerge={true}
lazyUpdate={true}
silent={true} />
3. full example
import React from 'react';
import ReactDOM from 'react-dom';
import EchartsOnReact from 'echarts-on-react/lib/EchartsOnReact'
import echarts from 'echarts';
const options = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ['衬衫','羊毛衫','雪纺衫','裤子','高跟鞋','袜子']
},
yAxis: {},
series: [
{
name: '销量',
type: 'bar',
data: [5,20,36,10,10,20]
}
]
};
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [[1, 2, 3, 4, 5]]
}
}
componentDidMount() {
// echarts container
console.log(this.echartsReact.chartRef);
// echarts instance
console.log(this.echartsReact.echarts.getInstanceByDom(this.echartsReact.chartRef));
setInterval(() => {
this.setState({
data: [[
parseInt(Math.random() * 100, 10),
parseInt(Math.random() * 100, 10),
parseInt(Math.random() * 100, 10),
parseInt(Math.random() * 100, 10),
parseInt(Math.random() * 100, 10)
]]
})
}, 5000)
}
render() {
return (
<div style={{
width: '300px',
height: '300px'
}}>
<EchartsOnReact
ref={(chartRef) => {
this.echartsReact = chartRef;
}}
echarts={echarts}
options={options}
updateData={this.state.data}
notMerge={true}
lazyUpdate={true}
silent={true} />
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));