fixed #4
This commit is contained in:
parent
171d8a3519
commit
73570100e3
|
|
@ -9,36 +9,71 @@ import {
|
||||||
AppRegistry,
|
AppRegistry,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
View
|
View,
|
||||||
|
TouchableOpacity
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import Echarts from 'native-echarts';
|
import Echarts from 'native-echarts';
|
||||||
|
|
||||||
export default class app2 extends Component {
|
export default class app2 extends Component {
|
||||||
render() {
|
constructor(props) {
|
||||||
const option = {
|
super(props);
|
||||||
title: {
|
|
||||||
text: 'ECharts 入门示例'
|
this.state = {
|
||||||
|
option : {
|
||||||
|
title: {
|
||||||
|
text: 'ECharts 入门示例'
|
||||||
|
},
|
||||||
|
tooltip: {},
|
||||||
|
legend: {
|
||||||
|
data:['销量']
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
|
||||||
|
},
|
||||||
|
yAxis: {},
|
||||||
|
series: [{
|
||||||
|
name: '销量',
|
||||||
|
type: 'bar',
|
||||||
|
data: [5, 20, 36, 10, 10, 20]
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
tooltip: {},
|
text: 'test'
|
||||||
legend: {
|
|
||||||
data:['销量']
|
|
||||||
},
|
|
||||||
xAxis: {
|
|
||||||
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
|
|
||||||
},
|
|
||||||
yAxis: {},
|
|
||||||
series: [{
|
|
||||||
name: '销量',
|
|
||||||
type: 'bar',
|
|
||||||
data: [5, 20, 36, 10, 10, 20]
|
|
||||||
}]
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
changeOption() {
|
||||||
|
this.setState({
|
||||||
|
option: {
|
||||||
|
title: {
|
||||||
|
text: 'New Chart'
|
||||||
|
},
|
||||||
|
tooltip: {},
|
||||||
|
legend: {
|
||||||
|
data:['销量']
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
|
||||||
|
},
|
||||||
|
yAxis: {},
|
||||||
|
series: [{
|
||||||
|
name: '销量',
|
||||||
|
type: 'line',
|
||||||
|
data: [5, 20, 36, 10, 10, 20]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>
|
<Text style={styles.welcome}>
|
||||||
Welcome to React Native Echarts!
|
Welcome to React Native Echarts!
|
||||||
</Text>
|
</Text>
|
||||||
<Echarts option={option} height={300} />
|
<TouchableOpacity style={styles.button} onPress={this.changeOption.bind(this)}>
|
||||||
|
<Text style={{color: '#fff'}}>change state</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<Echarts option={this.state.option} height={300} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -56,6 +91,12 @@ const styles = StyleSheet.create({
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
margin: 30,
|
margin: 30,
|
||||||
},
|
},
|
||||||
|
button: {
|
||||||
|
backgroundColor: '#d9534f',
|
||||||
|
padding: 8,
|
||||||
|
borderRadius: 4,
|
||||||
|
marginBottom: 20
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AppRegistry.registerComponent('app2', () => app2);
|
AppRegistry.registerComponent('app2', () => app2);
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,28 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { WebView } from 'react-native';
|
import { WebView, View, StyleSheet } from 'react-native';
|
||||||
import renderChart from './renderChart';
|
import renderChart from './renderChart';
|
||||||
import echarts from './echarts.min';
|
import echarts from './echarts.min';
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if(nextProps.option !== this.props.option) {
|
||||||
|
this.refs.chart.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<WebView
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
||||||
scrollEnabled = {false}
|
<WebView
|
||||||
injectedJavaScript = {renderChart(this.props)}
|
ref="chart"
|
||||||
style={{
|
scrollEnabled = {false}
|
||||||
height: this.props.height || 400,
|
injectedJavaScript = {renderChart(this.props)}
|
||||||
}}
|
style={{
|
||||||
source={require('./tpl.html')}
|
height: this.props.height || 400,
|
||||||
/>
|
}}
|
||||||
|
source={require('./tpl.html')}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue