Highcharts - 多 Y 轴

3

我在一个页面上有多个 Highcharts 图表。其中一些图表(线图)在一个图表上包含多个系列。我遇到的问题是无法选择一个或两个系列中的多个点。

以下是我尝试做的一些示例代码,但它给了我一些问题...

function hc_json(series, hc_id) {
    $('#' + hc_id).highcharts('StockChart', {
        chart: {
            events: {           //Sets an event listener for the chart
                /*
                 *  If an event is registered it checks if the external zoom/selects are checked. 
                 *  If select is checked it gets the data points that were within the range at sets 
                 *  them as selected. 
                 */
                selection: function(event) {
                    var mode = $('input[name=mode]:checked', '#' + hc_id  + '_control').val();
                    if (mode != hc_id + '_zoom') {

                        for (var i = 0; i < this.series.length; i++)
                        {
                            console.log("Series: ", this.series);
                            console.log("Series length: ", this.series.length);
                            var points = this.series[i].points;   // visible points
                            var xs = event.xAxis[0]; //There seems to be no min/max forxAxis[1]
                            $.each(points, function (i,p) {
                                if (p.x >= xs.min && p.x <= xs.max) {
                                    console.log("Point:", p.x, "is selected");
                                    p.select(true, true);
                                }
                            });
                            //return false;
                        }
                        return false;
                    }
                },
            },

比如说,我希望能够选择图表中某个系列的数据点,但是我需要能够区分出我要选择的是哪个系列。我查阅了一些“visible”系列的资料,但还没有弄清楚如何将一个系列设置为可见或不可见。

1个回答

1
请看这个解决方案:

 chart: {
        events: {
            selection: function(event) {
                var chart = this,
                    min = event.xAxis[0].min,
                    max = event.xAxis[0].max,
                    txt = '';
                if (event.xAxis) {

                    $.each(chart.series,function(i,serie){
                        $.each(serie.data,function(j,point){
                            if(point.x >=min && point.x <=max) {
                                txt += '<br>serie: ' + serie.name + ' point: '+ point.y;
                                point.select(true,true);
                            }
                        });
                    });

                    $report.html(txt);
                }
            }
        },
        zoomType: 'x'
    },

http://jsfiddle.net/cNRx5/2/


非常感谢!这正是我在寻找的! - cmircovich

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接