For a bar chart I have the following click event defined:
plotOptions: {
series: {
It's working now! The problem was the following (as I understand it):
Like this:
In the config object (passed to the chart):
plotOptions: {
series: {
point: {
events: {
click: function() {
window.postMessage( //data you want to send to react native )
}
}
}
}
}
Pass the onMessage method as prop to the ChartView such as you would pass it to a WebView (https://facebook.github.io/react-native/docs/webview#onmessage)
<ChartView style={{ height: 300 }} config={conf} onMessage={m => onMessage(m)} options={options}></ChartView>
Just now you can console.log, setState, or do anything in your react native onMessage function
onMessage = (m) => {
console.log(m.nativeEvent.data)
}
And that's it, now I can click a bar and change the state of my component ;)
Only alert supports since Highcharts is rendering inside Webview. so for this
let data = "ClickedWebView" ;
write the following code in config as
plotOptions: {
series: {
point: {
events: {
click: function() {
window.ReactNativeWebView.postMessage(data);
}
}
}
}
}
in ChartView Code Code would be
<ChartView style={{ height: 400 }} config={confi} onMessage={m => this.onMessage(m)} options={options}></ChartView>
can write custom message function as
onMessage = (message) => {
console.log(message.nativeEvent.data)
}