UNPKG

re-chart

Version:

A react chart library powered by ECharts

32 lines (27 loc) 737 B
import React, { Component, PropTypes } from 'react' import { findDOMNode } from 'react-dom' import echarts from 'echarts/lib/echarts' class BaseChart extends Component { componentDidMount() { const { callback, option } = this.props this.chart = echarts.init(findDOMNode(this)) if (callback) { callback(this.chart) } this.chart.setOption(option) } componentWillReceiveProps(nextProps) { if (this.props.option !== nextProps.option) { this.chart.setOption(nextProps.option) } } render() { return <div style={ this.props.style } /> } } BaseChart.propTypes = { option: PropTypes.object.isRequired, style: PropTypes.object, callback: PropTypes.func, } export default BaseChart