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

后端 未结 1 1769
星月不相逢
星月不相逢 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(
    <View style={styles.container}>
        <ChartView
            onMessage={m => this.onMessage(m)}
            config={config}
        />
    </View>
    

    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 `<div class="text">bla bla bla
                                <a href="http://www.google.cat">my link here/a>
                            </div>`;
                }
        };
    

    It works well on iOS, but not in Android.

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