Javascript Highcharts v3.0.5 - 如何在使用多个Y轴时隐藏Y轴标题 [英] Javascript Highcharts v3.0.5 - How to hide Y Axis Title when using multiple Y Axis
问题描述
使用Highcharts(v.3.0.5)时,我在同一个图表中显示了多个Y轴。使用图例,用户可以选择隐藏或显示任何Y轴。所有这些都建立在Highcharts JavaScript库的功能中。但是,当Y轴被隐藏时,它的标题仍然在图表中显示。当Y轴的其余部分隐藏时,我想隐藏它。惊讶这已不是默认行为。有人知道如何做到这一点吗?
When using Highcharts (v.3.0.5), I have multiple Y Axis displayed in the same chart. Using the legend, a user can choose to hide or show any of the Y Axis as they want. All this is built in feature of the Highcharts javascript library. However, when a Y Axis is hidden, its Title still appears visible in the Chart. I would like to hide it when the rest of the Y Axis is hidden. Surprised this is not the default behaviour already. Does anyone know how to do that?
通过查看Highcharts示例页面上提供的示例,可以看到该行为:
The behaviour can be seen by looking at the example provided on Highcharts examples page:
http://www.highcharts.com/demo/combo-multi-axes
例如,如果您隐藏降雨量轴,则标题将保留在图表中作为降雨量。
If you hide the "rainfall" axis for example, the title remains in the chart as "Rainfall".
我发现这个帖子(几岁),问完全相同的问题。但是,所提出的解决方案不起作用。显示和隐藏事件,重新显示所有内容。
I found this post (several years old) where the exact same question was asked. However, the solution proposed does not work. The show and hide events, redisplay everything.
http://forum.highcharts.com/highcharts-usage/how-to-hide-y-axis-title-multiple-axis- t6973 /#p32842
推荐答案
事实证明,这是一个备受追捧的问题/答案。自Highcharts V2.2以来,可以为y轴定义分配showEmpty:false,这将确保在隐藏时,Y轴文本标签也被隐藏。
This actually turns out to be a much sought after question/answer. Since Highcharts V2.2, it is possible to assign "showEmpty: false" to y axis definitions and this will ensure that when hidden, the Y-axis text label is also hidden. Example snippet of config below:
yAxis: [{
min: 0,
showEmpty: false,
labels: {
formatter: function() {
return this.value;
},
style: {
color: '#3366CC'
}
},
title: {
text: 'Clicks',
style: {
color: '#3366CC'
}
},
id: 'Clicks'
},
...
我已阅读报告,其中showEnabled = false如果同时设置了最小值和最大值,则会中断。在上面的例子中,只有min被设置,它对我来说使用Highcharts V3.0.5很好。
I have read reports where this showEnabled = false breaks if both min and max are also set. In the case above, where only min is set, it worked well for me using Highcharts V3.0.5
这篇关于Javascript Highcharts v3.0.5 - 如何在使用多个Y轴时隐藏Y轴标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!