1.0.3 • Published 6 years ago

echarts-on-react v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

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'));
1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago