简体   繁体   English

Javascript Highcharts v3.0.5 - 如何在使用多个Y轴时隐藏Y轴标题

[英]Javascript Highcharts v3.0.5 - How to hide Y Axis Title when using multiple Y Axis

When using Highcharts (v.3.0.5), I have multiple Y Axis displayed in the same chart. 使用Highcharts(v.3.0.5)时,我在同一图表中显示多个Y轴。 Using the legend, a user can choose to hide or show any of the Y Axis as they want. 使用图例,用户可以根据需要选择隐藏或显示任何Y轴。 All this is built in feature of the Highcharts javascript library. 所有这些都是Highcharts javascript库的功能。 However, when a Y Axis is hidden, its Title still appears visible in the Chart. 但是,当隐藏Y轴时,其标题仍然在图表中可见。 I would like to hide it when the rest of the Y Axis is hidden. 当隐藏Y轴的其余部分时,我想隐藏它。 Surprised this is not the default behaviour already. 感到惊讶的是,这不是默认行为。 Does anyone know how to do that? 有谁知道这是怎么做到的吗?

The behaviour can be seen by looking at the example provided on Highcharts examples page: 通过查看Highcharts示例页面上提供的示例可以看到该行为:

http://www.highcharts.com/demo/combo-multi-axes 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 http://forum.highcharts.com/highcharts-usage/how-to-hide-y-axis-title-multiple-axis-t6973/#p32842

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. 从Highcharts V2.2开始,可以为y轴定义指定“showEmpty:false”,这将确保隐藏时,Y轴文本标签也会被隐藏。 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'
            }, 
                 ...

I have read reports where this showEnabled = false breaks if both min and max are also set. 如果同时设置了min和max,我已经阅读过showEnabled = false的报告。 In the case above, where only min is set, it worked well for me using Highcharts V3.0.5 在上面的例子中,只设置了min,使用Highcharts V3.0.5对我来说效果很好

you can use yAxis.setTitle() and set/remove the title when needed. 您可以使用yAxis.setTitle()并在需要时设置/删除标题。

here is the api documentation link 这是api文档链接

@arcseldon, it is true that showEnabled = false breaks if both min and max are also set. @arcseldon,如果同时设置了min和max,showEnabled = false就会中断。 A possible workaround in this case is to set floor and max instead 在这种情况下,可能的解决方法是设置楼层和最大值

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

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