Javascript 使用XY缩放高图时,如何隐藏未选定的系列和轴?
我们使用highcharts(特别是highstock)来绘制多种类型的数据。我们希望利用XY缩放类型,但是,如果我们可以只放大到使用选择框选择的内容,那将非常棒 但是,当一个轴使用XY放大时,如果在另一个轴中未选择任何数据,则该轴将不显示任何内容。如果高亮显示/选定区域在整个图形上重新绘制,这将是理想的 我试着在浏览器控制台窗口中查看图表对象,缩放后的所有轴的“series[x].visible”等值都相同。甚至有可能实现我的要求吗 编辑:我应该注意的是,我们不需要仅仅因为要显示的数据量而让图表彼此重叠,这就是为什么两个图表独立显示的原因 小提琴:Javascript 使用XY缩放高图时,如何隐藏未选定的系列和轴?,javascript,jquery,highcharts,highstock,Javascript,Jquery,Highcharts,Highstock,我们使用highcharts(特别是highstock)来绘制多种类型的数据。我们希望利用XY缩放类型,但是,如果我们可以只放大到使用选择框选择的内容,那将非常棒 但是,当一个轴使用XY放大时,如果在另一个轴中未选择任何数据,则该轴将不显示任何内容。如果高亮显示/选定区域在整个图形上重新绘制,这将是理想的 我试着在浏览器控制台窗口中查看图表对象,缩放后的所有轴的“series[x].visible”等值都相同。甚至有可能实现我的要求吗 编辑:我应该注意的是,我们不需要仅仅因为要显示的数据量而让图
是的,这是可能的,但只需手动处理即可: 要实现所述行为,您可以通过以下方式: 此外,我看到您试图通过更改
x
和y
来对齐yAxis
标签的位置。但是它使定位相对于另一个轴:因此,首先,当应用上述代码段时,在隐藏第二个序列时,您将看不到标签1
标题,因为它将定位在highcharts容器之外。要解决该问题,只需确保正确定位,以及:
$('#container').highcharts({
chart: {
type: 'line',
rightMargin: 80,
zoomType: 'xy'
},
yAxis: [{
id: 'hi',
height: '40%',
top: '10%',
title: { text: 'label 1', y: 0, x: -30, align: 'middle' },
labels: { align: 'left', x: -25 }
}, {
id: 'ho',
height: '40%',
top: '60%',
title: { text: 'label 2', y: 0, x: 0, align: 'middle' },
labels: { align: 'left', x: 0 }
}],
xAxis: [{
type: 'datetime',
tickInterval: 24 * 3600 * 1000,
yAxis: 'hi'
},{
type: 'datetime',
tickInterval: 24 * 3600 * 1000,
yAxis: 'ho'
}],
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],
pointStart: Date.UTC(2010, 0, 1),
pointInterval: 24 * 3600 * 1000,
yAxis: 'hi'
},{
data: [129.9, 171.5, 1106.4, 1129.2, 1144.0, 1176.0, 1135.6, 1148.5, 1216.4],
pointStart: Date.UTC(2010, 0, 1),
pointInterval: 24 * 3600 * 1000,
yAxis: 'ho'
}]
});
plotOptions: {
series: {
events: {
legendItemClick: function (e) {
var thisIndex = this.index;
var otherIndex = (this.index == 0) ? 1 : 0;
var isOtherEnabled = false;
if (this.chart.yAxis[otherIndex].options.labels.enabled) {
isOtherEnabled = true;
}
var isThisEnabled = false;
if (this.chart.yAxis[thisIndex].options.labels.enabled) {
isThisEnabled = true;
}
if (isThisEnabled) {
this.chart.yAxis[thisIndex].update({
labels: {
enabled: false
},
title: {
text: null
}
});
if (isOtherEnabled) {
this.chart.yAxis[otherIndex].update({
height: '80%',
top: '10%'
});
}
} else {
this.chart.yAxis[thisIndex].update({
labels: {
enabled: true
},
title: {
text: (thisIndex == 0) ? 'label 1' : 'label 2'
},
height: (isOtherEnabled) ? '40%' : '80%',
top: (isOtherEnabled) ? ((thisIndex == 0) ? '10%' : '60%') : '10%'
});
if (isOtherEnabled) {
this.chart.yAxis[otherIndex].update({
height: '40%',
top: (otherIndex == 0) ? '10%' : '60%'
});
}
}
this.chart.reflow();
}
}
}
},
yAxis: [{
id: 'hi',
height: '40%',
top: '10%',
offset: 30,
title: { text: 'label 1', offset: 30, align: 'middle' },
labels: { align: 'left' }
}, {
id: 'ho',
height: '40%',
top: '60%',
offset: 30,
title: { text: 'label 2', offset: 30, align: 'middle' },
labels: { align: 'left' }
}],