TradingPal / react-native-highcharts

📈 Add Highcharts charts to react-native app for IOS and Android
https://github.com/TradingPal/react-native-highcharts
256 stars 158 forks source link

Add bubble up of highcharts events to react-native level #53

Open mobitinker opened 6 years ago

mobitinker commented 6 years ago

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.

leogomesdev commented 6 years ago

Please, I also need use this!

ap050492 commented 5 years ago

@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 ?

Luke-Gurgel commented 5 years ago

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} />
    )
  }
}