Merge pull request #42 from superandrew213/add-onPress

Add onPress
This commit is contained in:
Arron Zhu 2017-10-26 04:42:00 -05:00 committed by GitHub
commit eeeaead411
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,7 @@ export default class App extends Component {
height: this.props.height || 400,
}}
source={require('./tpl.html')}
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
/>
</View>
);

View File

@ -9,5 +9,18 @@ export default function renderChart(props) {
document.getElementById('main').style.width = "${width}";
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(${toString(props.option)});
myChart.on('click', function(params) {
var seen = [];
var paramsString = JSON.stringify(params, function(key, val) {
if (val != null && typeof val == "object") {
if (seen.indexOf(val) >= 0) {
return;
}
seen.push(val);
}
return val;
});
window.postMessage(paramsString);
});
`
}