Skip to content

Commit eeeaead

Browse files
authored
Merge pull request #42 from superandrew213/add-onPress
Add onPress
2 parents c9efc06 + b55bab0 commit eeeaead

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/components/Echarts/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class App extends Component {
2121
height: this.props.height || 400,
2222
}}
2323
source={require('./tpl.html')}
24+
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
2425
/>
2526
</View>
2627
);

src/components/Echarts/renderChart.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,18 @@ export default function renderChart(props) {
99
document.getElementById('main').style.width = "${width}";
1010
var myChart = echarts.init(document.getElementById('main'));
1111
myChart.setOption(${toString(props.option)});
12+
myChart.on('click', function(params) {
13+
var seen = [];
14+
var paramsString = JSON.stringify(params, function(key, val) {
15+
if (val != null && typeof val == "object") {
16+
if (seen.indexOf(val) >= 0) {
17+
return;
18+
}
19+
seen.push(val);
20+
}
21+
return val;
22+
});
23+
window.postMessage(paramsString);
24+
});
1225
`
1326
}

0 commit comments

Comments
 (0)