我正在使用一个高图来控制另一个。设置 chart.evetns.selection 后,如果我缩放一个小区域,chart.yAxis.getExtremes 将无法返回正确的 dataMax。但是,如果我再次单击,它会返回正确的。有什么建议可以避免这种情况吗?这是我的代码:http: //jsfiddle.net/tianhuidong/Jhupu/
$(function () {
$('#container1').highcharts({
chart: {
events: {
selection: function (event) {
m1 = event.xAxis[0].min
m2 = event.xAxis[0].max
var chart1 = $('#container1').highcharts()
var chart2 = $('#container2').highcharts()
chart1.xAxis[0].setExtremes(m1, m2);
chart2.xAxis[0].setExtremes(m1, m2);
},
click: function (event) {
var chart1 = $('#container1').highcharts()
var chart2 = $('#container2').highcharts()
xx = chart1.xAxis[0].getExtremes()
yy = chart1.yAxis[0].getExtremes()
alert(yy.min)
alert(yy.dataMax)
alert(yy.userMax)
alert(Object.keys(yy))
chart1.xAxis[0].setExtremes(xx.dataMin, xx.dataMax);
chart1.yAxis[0].setExtremes(yy.dataMin, yy.dataMax);
chart2.xAxis[0].setExtremes(xx.dataMin, xx.dataMax);
}
},
zoomType: 'xy'
},
tooltip: {
crosshairs: true
},
plotOptions: {
series: {
events: {
legendItemClick: function (event) {
var chart1 = $('#container1').highcharts()
var chart2 = $('#container2').highcharts()
//alert(Object.keys(chart1.series[0]))
chart2.series[0].hide()
//chart2.showResetZoom()
//alert(Object.keys(chart.resetZoomButton))
}
}
}
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 186.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 186.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
$(function () {
$('#container2').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 116.4, 194.1, 95.6, 54.4, 29.9, 71.5, 186.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});