react-native-highcharts icon indicating copy to clipboard operation
react-native-highcharts copied to clipboard

Add bubble up of highcharts events to react-native level

Open mobitinker opened this issue 7 years ago • 3 comments

It would be great to be able to receive events in React-Native via a bridge such as is found with react-native-webview-bridge. For example if I have a column chart, I'd like to be able to define an event for onPress for the data series and have the event be detectable at the app level.

mobitinker avatar Oct 18 '17 20:10 mobitinker

Please, I also need use this!

leogomesdev avatar Feb 26 '18 23:02 leogomesdev

@mobitinker & @leogomezzz have you found any solution ?

if i write below code into chart config then it's show alert dialog , but can't able to call React native function from config data

events: {
     click: function (event) {
         alert(
               event
	 );
	 // this.clickOnArea(event);
     }
}

@infinity0106 can you please help us ?

ap050492 avatar Sep 14 '18 07:09 ap050492

Hope this helps somebody...

// create your config object

const window = "window"

const config = {
  // all the other stuff...
  plotOptions: {
    series: {
      point: {
        events: {
          click: function (e) {
            const seriesName = e.point.series.name;
            window.postMessage(seriesName) // this will send data back up to the React Native component that's rendering the WebView
          }
        }
      }
    }
  }
}

// Pass the onMessage prop to the WebView and create a handler method for it

import { WebView } from "react-native-webview"

export default class ChartView extends Component {

  // all the other stuff...

  onMessage = (e) => {
     console.log(e.nativeEvent.data)
  } 

  render() {
    return (
      <WebView {...this.props} onMessage={this.onMessage} />
    )
  }
}

Luke-Gurgel avatar Feb 01 '19 18:02 Luke-Gurgel