highcharts 显示点击的图例数据(隐藏其他)

function emitLegendItemClick(me) {
    var container = me.chart.container;
    var legenedItemIndex = me.index;
    if(container.curr_index == "undefined") {
        for (var i = 0; i < me.chart.series.length; i++) {
            if (i != legenedItemIndex) {
                me.chart.series[i].setVisible(false, false);
            }
        }
        container.curr_index = legenedItemIndex;
        return false;
    }
    else if ((container.curr_index ==0 || container.curr_index) && container.curr_index == legenedItemIndex) {
        for (var i = 0; i < me.chart.series.length; i++) {
            if (i != legenedItemIndex) {
                var visible = !me.chart.series[i].visible;
                me.chart.series[i].setVisible(visible, false);
            }
        }
        return false;
    } else {
        var curr_series = me.chart.series[legenedItemIndex];
        for (var i = 0; i < me.chart.series.length; i++) {
            if (i != legenedItemIndex) {
                me.chart.series[i].setVisible(false, false);
            }
        }
        container.curr_index = legenedItemIndex;
        if(curr_series.visible) {
            return false;
        }else {
            return true;
        }
    }
};
series: {
    cursor: 'pointer',
    events: {
        legendItemClick: function (e) {
            return emitLegendItemClick(this);
        }
    }
}

你可能感兴趣的:(前端)