简体   繁体   English

Highcharts:如何保持标记格式并使用5K +点散点图触发点击事件?

[英]Highcharts : How do I keep the marker formatting and make the click event fire with a 5K+ point scatter plot?

We are running into an issue where our scatter chart starts to act abnormally when we reach 5,000 points on the screen. 我们遇到了一个问题,即当我们在屏幕上达到5,000点时,散点图将开始异常运行。 Specifically, at 5k+ points, the point event 'click' will stop firing when we click on a point, and our point formatting (fillColor & symbol) is lost. 具体来说,在5k +点处,当我们单击一个点时,点事件“ click”将停止触发,并且我们的点格式(fillColor和符号)将丢失。

4999 points: http://jsfiddle.net/xrpf0pfq/7/ 4999分: http//jsfiddle.net/xrpf0pfq/7/

$(function() {

// Prepare the data
var data = [],
    n = 4999, // < 5K points
    i;
for (i = 0; i < n; i += 1) {
    data.push([
        Math.pow(Math.random(), 2) * 100,
        Math.pow(Math.random(), 2) * 100
    ]);
}

if (!Highcharts.Series.prototype.renderCanvas) {
    console.error('Module not loaded');
    return;
}

console.time('scatter');
console.time('asyncRender');
$('#container').highcharts({

    chart: {
        zoomType: 'xy'
    },

    xAxis: {
        min: 0,
        max: 100,
        gridLineWidth: 1
    },

    yAxis: {
        // Renders faster when we don't have to compute min and max
        min: 0,
        max: 100,
        minPadding: 0,
        maxPadding: 0
    },

    title: {
        text: 'Scatter chart with ' + Highcharts.numberFormat(data.length, 0, ' ') + ' points'
    },
    legend: {
        enabled: false
    },
    series: [{
        type: 'scatter',
        data: data,
        marker: {
            radius: 5,
            symbol: 'triangle', //shows correctly 
            fillColor: 'rgba(128,0,128,1)' //shows correctly
        },
        point: {
            events: {
                click: function() {
                    alert("click"); //event is fired correctly

                }
            }
        },
        tooltip: {
                enable: false,
            followPointer: false,
            pointFormat: '[{point.x:.1f}, {point.y:.1f}]'
        },
        events: {
            renderedCanvas: function() {
                console.timeEnd('asyncRender');
            }
        }
    }]

});
console.timeEnd('scatter');

});

5000 points: http://jsfiddle.net/xrpf0pfq/10/ 5000分: http : //jsfiddle.net/xrpf0pfq/10/

$(function() {

// Prepare the data
var data = [],
    n = 5000, // 5K points
    i;
for (i = 0; i < n; i += 1) {
    data.push([
        Math.pow(Math.random(), 2) * 100,
        Math.pow(Math.random(), 2) * 100
    ]);
}

if (!Highcharts.Series.prototype.renderCanvas) {
    console.error('Module not loaded');
    return;
}

console.time('scatter');
console.time('asyncRender');
$('#container').highcharts({

    chart: {
        zoomType: 'xy'
    },

    xAxis: {
        min: 0,
        max: 100,
        gridLineWidth: 1
    },

    yAxis: {
        // Renders faster when we don't have to compute min and max
        min: 0,
        max: 100,
        minPadding: 0,
        maxPadding: 0
    },

    title: {
        text: 'Scatter chart with ' + Highcharts.numberFormat(data.length, 0, ' ') + ' points'
    },
    legend: {
        enabled: false
    },
    series: [{
        type: 'scatter',
        data: data,
        marker: {
            radius: 5,
            symbol: 'triangle', //marker shape not showing 
            fillColor: 'rgba(128,0,128,1)' //color not showing
        },
        point: {
            events: {
                click: function() {
                    alert("click"); //click even not firing

                }
            }
        },
        tooltip: {
                enable: false,
            followPointer: false,
            pointFormat: '[{point.x:.1f}, {point.y:.1f}]'
        },
        events: {
            renderedCanvas: function() {
                console.timeEnd('asyncRender');
            }
        }
    }]

});
console.timeEnd('scatter');

});

Is there way to keep the marker formatting and make the click event fire when you have 5K or more points on a scatter plot? 当散点图上的点数达到5K或更多时,是否可以保持标记格式并使点击事件触发?

Apparently, this behaviour is caused by boost module. 显然,此行为是由boost模块引起的。 Look at the example without it: http://jsfiddle.net/xrpf0pfq/12/ . 查看没有它的示例: http : //jsfiddle.net/xrpf0pfq/12/ You can check in a source code of a boost module ( http://code.highcharts.com/modules/boost.src.js ) that the boostThreshold property is set with value 5000. You can set boostThreshold by yourself, check out the example: http://jsfiddle.net/xrpf0pfq/16/ . 您可以签入boost模块的源代码( http://code.highcharts.com/modules/boost.src.js ),将boostThreshold属性设置为值5000。可以自己设置boostThreshold,请查看例如: http : //jsfiddle.net/xrpf0pfq/16/

plotOptions: {
    series: {
        boostThreshold: 8001
    }
}

Also, not working click event with boost module is a known issue (beside, it is not good idea to click on a point where there are thousands of them and they are densely populated). 此外,使用boost模块的点击事件不起作用是一个已知问题(此外,单击有数千个它们且人口稠密的点不是一个好主意)。 There is a workaround for that though, take a look at this topic on GitHub: https://github.com/highcharts/highcharts/issues/4569 . 不过,有一种解决方法,请在GitHub上查看以下主题: https : //github.com/highcharts/highcharts/issues/4569 As Paweł mentioned, to make click event work with a huge amount of points, you need to enable halo and make it clickable (here is an example with boost module loaded and with more points than boostThreshold value but with click event working: http://jsfiddle.net/xrpf0pfq/17/ ). 正如Paweł所提到的,要使点击事件具有大量的点,您需要启用光晕并使之可点击(以下示例加载了boost模块,并且其点数超过boostThreshold值,但click事件起作用: http:/ /jsfiddle.net/xrpf0pfq/17/ )。

mouseOver: function() {
    if (this.series.halo) {
        this.series.halo.attr({'class': 'highcharts-tracker'}).toFront();
    }
}

Regards. 问候。

Ran accross the same problem. 遇到同样的问题。 The halo-workaround didn't work for me, because i wanted to get the click event for the recently highlighted point, even if it is not directly clicked. 晕轮变通办法对我而言不起作用,因为我想获取最近突出显示的点的click事件,即使未直接单击也是如此。 Highcharts has the ability to highlight the nearest point if you point anywhere on the chart. 如果您指向图表上的任何位置,Highcharts都可以突出显示最近的点。 My workaround is, to use the tooltip formatter to store the x value away and then use it on the global click event for the chart. 我的解决方法是,使用工具提示格式化程序将x值存储起来,然后在图表的全局click事件上使用它。

See the fiddle: 看到小提琴:

http://jsfiddle.net/StefanJelner/a1m0wuy6/ http://jsfiddle.net/StefanJelner/a1m0wuy6/

var recent = false;
$('#container').highcharts({
    chart: {
        events: {
            click: function() {
            console.log('chart click', recent);
          }
        }
    },
    tooltip: {
        formatter: function() {
            recent = this.x;
            return 'The value for <b>' + this.x +
            '</b> is <b>' + this.y + '</b>';
        }
    },
    plotOptions: {
        series: {
            point: {
                events: {
                    click: function (e) {
                        console.log('point click', e); // never happens
                    }
                }
            }
        }
    }
});

This should also work for Version 6. 这也适用于版本6。

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

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