react-native-echarts/src/components/Echarts/index.js

31 lines
943 B
JavaScript
Raw Normal View History

2016-10-21 07:05:57 +00:00
import React, { Component } from 'react';
2016-11-03 02:43:21 +00:00
import { WebView, View, StyleSheet } from 'react-native';
2016-10-21 07:54:29 +00:00
import renderChart from './renderChart';
2016-10-21 07:05:57 +00:00
import echarts from './echarts.min';
export default class App extends Component {
2016-11-03 02:43:21 +00:00
componentWillReceiveProps(nextProps) {
if(nextProps.option !== this.props.option) {
this.refs.chart.reload();
}
}
2016-10-21 07:05:57 +00:00
render() {
return (
2016-11-03 02:43:21 +00:00
<View style={{flex: 1, height: this.props.height || 400,}}>
<WebView
ref="chart"
scrollEnabled = {false}
injectedJavaScript = {renderChart(this.props)}
style={{
height: this.props.height || 400,
}}
source={require('./tpl.html')}
style={{backgroundColor: this.props.option.backgroundColor || 'rgba(0, 0, 0, 0)'}}
2017-05-13 01:15:33 +00:00
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
2016-11-03 02:43:21 +00:00
/>
</View>
2016-10-21 07:05:57 +00:00
);
}
}