Skip to content

Commit 7357010

Browse files
committed
fixed #4
1 parent 171d8a3 commit 7357010

File tree

2 files changed

+78
-30
lines changed

2 files changed

+78
-30
lines changed

example/index.ios.js

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,71 @@ import {
99
AppRegistry,
1010
StyleSheet,
1111
Text,
12-
View
12+
View,
13+
TouchableOpacity
1314
} from 'react-native';
1415
import Echarts from 'native-echarts';
1516

1617
export default class app2 extends Component {
17-
render() {
18-
const option = {
19-
title: {
20-
text: 'ECharts 入门示例'
21-
},
22-
tooltip: {},
23-
legend: {
24-
data:['销量']
25-
},
26-
xAxis: {
27-
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
18+
constructor(props) {
19+
super(props);
20+
21+
this.state = {
22+
option : {
23+
title: {
24+
text: 'ECharts 入门示例'
25+
},
26+
tooltip: {},
27+
legend: {
28+
data:['销量']
29+
},
30+
xAxis: {
31+
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
32+
},
33+
yAxis: {},
34+
series: [{
35+
name: '销量',
36+
type: 'bar',
37+
data: [5, 20, 36, 10, 10, 20]
38+
}]
2839
},
29-
yAxis: {},
30-
series: [{
31-
name: '销量',
32-
type: 'bar',
33-
data: [5, 20, 36, 10, 10, 20]
34-
}]
40+
text: 'test'
3541
};
42+
}
43+
44+
changeOption() {
45+
this.setState({
46+
option: {
47+
title: {
48+
text: 'New Chart'
49+
},
50+
tooltip: {},
51+
legend: {
52+
data:['销量']
53+
},
54+
xAxis: {
55+
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
56+
},
57+
yAxis: {},
58+
series: [{
59+
name: '销量',
60+
type: 'line',
61+
data: [5, 20, 36, 10, 10, 20]
62+
}]
63+
}
64+
})
65+
}
66+
67+
render() {
3668
return (
3769
<View style={styles.container}>
3870
<Text style={styles.welcome}>
3971
Welcome to React Native Echarts!
4072
</Text>
41-
<Echarts option={option} height={300} />
73+
<TouchableOpacity style={styles.button} onPress={this.changeOption.bind(this)}>
74+
<Text style={{color: '#fff'}}>change state</Text>
75+
</TouchableOpacity>
76+
<Echarts option={this.state.option} height={300} />
4277
</View>
4378
);
4479
}
@@ -56,6 +91,12 @@ const styles = StyleSheet.create({
5691
textAlign: 'center',
5792
margin: 30,
5893
},
94+
button: {
95+
backgroundColor: '#d9534f',
96+
padding: 8,
97+
borderRadius: 4,
98+
marginBottom: 20
99+
}
59100
});
60101

61102
AppRegistry.registerComponent('app2', () => app2);

src/components/Echarts/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import React, { Component } from 'react';
2-
import { WebView } from 'react-native';
2+
import { WebView, View, StyleSheet } from 'react-native';
33
import renderChart from './renderChart';
44
import echarts from './echarts.min';
55

66
export default class App extends Component {
7+
componentWillReceiveProps(nextProps) {
8+
if(nextProps.option !== this.props.option) {
9+
this.refs.chart.reload();
10+
}
11+
}
12+
713
render() {
814
return (
9-
<WebView
10-
scrollEnabled = {false}
11-
injectedJavaScript = {renderChart(this.props)}
12-
style={{
13-
height: this.props.height || 400,
14-
}}
15-
source={require('./tpl.html')}
16-
/>
15+
<View style={{flex: 1, height: this.props.height || 400,}}>
16+
<WebView
17+
ref="chart"
18+
scrollEnabled = {false}
19+
injectedJavaScript = {renderChart(this.props)}
20+
style={{
21+
height: this.props.height || 400,
22+
}}
23+
source={require('./tpl.html')}
24+
/>
25+
</View>
1726
);
1827
}
1928
}
20-
21-

0 commit comments

Comments
 (0)