How can I add links in a Highcharts tooltip that will open on mobile's browser?

后端 未结 1 1784
星月不相逢
星月不相逢 2021-01-07 15:58

I am developing a React Native app with expo. One of the screens contains a graphic created with Highcharts. All points have an associated tooltip with some text, t

1条回答
  •  庸人自扰
    2021-01-07 16:31

    I solved it by using onMessage from the CharView:

    return(
    
         this.onMessage(m)}
            config={config}
        />
    
    

    This triggers this method to open the URL:

    onMessage = (m) => {
        let data = JSON.parse(m.nativeEvent.data);
        Linking.openURL(data.url)
    };
    

    And the URL gets populated through a global variable window.myURL and sending the message with postMessage():

    render() {
        let Highcharts = "Highcharts";
        let config ={
            ...
            plotOptions: {
                series: {
                    stickyTracking: false,
                    point: {
                        events: {
                            click: function(e) {
                                window.postMessage(JSON.stringify({'url': window.myUrl}));
                            }
                        }
                    }
                },
            },
            tooltip: {
                useHTML: true,
                formatter: function () {
                    window.myUrl = extras.url;
                    return `
    bla bla bla my link here/a>
    `; } };

    It works well on iOS, but not in Android.

    0 讨论(0)
提交回复
热议问题