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

橙三吉。 提交于 2019-12-01 01:49:12

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!