简体   繁体   English

高图:如何通过plotOptions.series.events处理触摸事件

[英]Highcharts: how to handle touch events via plotOptions.series.events

On a Highcharts bar chart, when the user clicks one of the bars, additional data is loaded elsewhere on the page via the loadDetails function. 在Highcharts条形图上,当用户单击其中一个条形图时,其他数据将通过loadDetails函数加载到页面上的其他位置。

loadDetails is specified as a click callback function for a chart via plotOptions.series.events : loadDetails被指定为用于经由图表的点击回调函数plotOptions.series.events

var chart = new Highcharts.Chart({
    defaultSeriesType: 'bar',
    ...
    plotOptions: {
        series: {
            events: {
                click: loadDetails
            }
        }
    },
    ...

});

function loadDetails() {
    ...
}

The problem is I need to call the same callback function for a touchstart event on mobile devices. 问题是我需要为移动设备上的touchstart事件调用相同的回调函数。

There doesn't seem to be any obvious way of adding a touch event handler via the Highcharts API as far as I could tell: http://api.highcharts.com/highcharts#plotOptions.series.events . 据我所知,似乎没有任何明显的方法可以通过Highcharts API添加触摸事件处理程序: http : //api.highcharts.com/highcharts#plotOptions.series.events

Has anyone got any idea how to add callback functions for touch events, or trigger the click callback function from a touch event? 有谁知道如何为触摸事件添加回调函数,或从触摸事件触发点击回调函数?

Yeah, something like this is not supported, I advice you to create idea here . 是的,不支持这样的操作,我建议您在此处创建想法。

The only workaround which comes to my mind is use Element.on function to add custom events to elements which exists on a chart. 我想到的唯一解决方法是使用Element.on函数向图表上存在的元素添加自定义事件。 For example: http://jsfiddle.net/3bQne/269/ 例如: http : //jsfiddle.net/3bQne/269/

    chart: {
        renderTo: 'container',
        events: {
            load: function(){
                var chart = this,
                    path = chart.series[0].tracker;

                path.on('click', function() {
                   alert("click");; 
                });
            }
        }
    }

This works. 这可行。 I was trying to get Highcharts to work with Apple Pencil. 我试图让Highcharts与Apple Pencil一起使用。 I used code above but included markerGroup (along with tracker) so event triggers when user click on points along with lines of a series. 我在上面使用了代码,但包括markerGroup(以及跟踪器),因此当用户单击点和一系列直线时会触发事件。 I use 'touchstart' event to trap apple pencil click. 我使用“ touchstart”事件来捕获苹果铅笔的点击。 See below. 见下文。

chart: {
        renderTo: 'container',
        events: {
            load: function(){
                var chart = this,
                    path = chart.series[0].tracker;
                    path2 = chart.series[0].markerGroup;
            path.on('touchstart', function() {
               alert(“touch");
            });
            path2.on('touchstart'), function() {
               alert(“touch 2”);
            });
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM