简体   繁体   English

高图:一个传说,两个图表

[英]HighCharts: One Legend, Two Charts

I have four different HighChart spline charts. 我有四个不同的HighChart样条图。 All contain six series representing the six New England states. 全部包含代表新英格兰六个州的六个系列。 I want to click any legend and hide/show that series in all charts. 我想单击任何图例并在所有图表中隐藏/显示该系列。 I have tried legendclickitem but cannot get it to effect both charts. 我尝试了legendclickitem,但无法使其同时影响两个图表。 Is what i am asking possible, if so can you point me in the right direction, thanks. 我想问的是可能的,如果可以的话,您能指出我正确的方向吗,谢谢。

Answer: 回答:

Using Paweł FusIn code and in order to keep a legend on each chart I used the following code. 使用PawełFusIn代码并为了在每个图表上保留图例,我使用了以下代码。 You can click on any legend item and it updates all charts. 您可以单击任何图例项目,它会更新所有图表。

plotOptions: {
series: {
events: {
legendItemClick: function(event) {
if (this.visible) {
$('#container1').highcharts().series[this.index].hide(); 
$('#container2').highcharts().series[this.index].hide(); 
$('#container3').highcharts().series[this.index].hide(); 
$('#container4').highcharts().series[this.index].hide(); 
} 
else {
$('#container1').highcharts().series[this.index].show(); 
$('#container2').highcharts().series[this.index].show(); 
$('#container3').highcharts().series[this.index].show(); 
$('#container4').highcharts().series[this.index].show();
}
return false;
}
}
}

It's possible, take a look: http://jsfiddle.net/teEQ3/ 有可能看看: http : //jsfiddle.net/teEQ3/

$('#container1').highcharts({
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    legend: {
        enabled: false
    },

    series: [{
        id: 'someId',
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});
$('#container2').highcharts({
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    plotOptions: {
        series: {
            events: {
                legendItemClick: function (event) {
                    var XYZ = $('#container1').highcharts(),
                        series = XYZ.get(this.options.id); //get corresponding series

                    if (series) {
                        if (this.visible) {
                            series.hide();
                        } else {
                            series.show();
                        }
                    }
                }
            }
        }
    },

    series: [{
        id: 'someId',
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});

So the idea is to enable only in one chart legend, then in all respective charts hide corresponding series. 因此,其想法是仅在一个图表图例中启用,然后在所有各个图表中隐藏相应的系列。

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

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