File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,23 @@ import renderChart from './renderChart';
4
4
import echarts from './echarts.min' ;
5
5
6
6
export default class App extends Component {
7
+
8
+ constructor ( props ) {
9
+ super ( props ) ;
10
+ this . setNewOption = this . setNewOption . bind ( this ) ;
11
+ }
12
+
13
+
7
14
componentWillReceiveProps ( nextProps ) {
8
15
if ( nextProps . option !== this . props . option ) {
9
16
this . refs . chart . reload ( ) ;
10
17
}
11
18
}
12
19
20
+ setNewOption ( option ) {
21
+ this . refs . chart . postMessage ( JSON . stringify ( option ) ) ;
22
+ }
23
+
13
24
render ( ) {
14
25
return (
15
26
< View style = { { flex : 1 , height : this . props . height || 400 , } } >
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ export default function renderChart(props) {
9
9
document.getElementById('main').style.width = "${ width } ";
10
10
var myChart = echarts.init(document.getElementById('main'));
11
11
myChart.setOption(${ toString ( props . option ) } );
12
+ window.document.addEventListener('message', function(e) {
13
+ var option = JSON.parse(e.data);
14
+ myChart.setOption(option);
15
+ });
12
16
myChart.on('click', function(params) {
13
17
var seen = [];
14
18
var paramsString = JSON.stringify(params, function(key, val) {
Original file line number Diff line number Diff line change @@ -3,10 +3,15 @@ import { WebView, View } from 'react-native';
3
3
import { Container , Echarts } from './components'
4
4
5
5
export default class App extends Component {
6
+
7
+ setNewOption ( option ) {
8
+ this . chart . setNewOption ( option ) ;
9
+ }
10
+
6
11
render ( ) {
7
12
return (
8
13
< Container width = { this . props . width } >
9
- < Echarts { ...this . props } />
14
+ < Echarts { ...this . props } ref = { e => this . chart = e } />
10
15
</ Container >
11
16
) ;
12
17
}
You can’t perform that action at this time.
0 commit comments