【问题标题】:Hide Series without hiding y-Axis隐藏系列而不隐藏 y 轴
【发布时间】:2014-11-28 07:47:15
【问题描述】:

有很多隐藏 Y-Axis without hiding the series 的例子 - 但我需要相反的。

我想让一个系列不可见,同时仍然显示 y 轴,我不知道怎么做!

为什么?

因为我有 2 个图表,它们的 x 轴完全对齐:

但是当我禁用两个温度字段时,轴将丢失,并且图表的大小不正确:

我也不喜欢禁用所有并失去整个图表样式的想法:

有一个空图表没有问题,但有一个空白框不是我想要达到的样式。

我试图在legendItemClick 事件中操纵轴,但选择正确的轴并将其值设置为可见并没有成功。我该如何解决这个问题?

【问题讨论】:

  • 仅供参考:第二个“图表”是一个简单的 HTML 表格 - 与 highcharts 无关

标签: javascript jquery css highcharts alignment


【解决方案1】:

我认为你有两个选择:

如果您在开始时不知道最小/最大值,您可以在 legendItemClick 中更改它们,如下所示:

 plotOptions: {
        series: {
            events: {
                legendItemClick: function() {
                    var temperatur = this.chart.series[0];
                    var taupunkt = this.chart.series[1];
                    var other = this.name=="Lufttemperatur"?taupunkt:temperatur;
                    var element = this;
                    if(this.name == "Lufttemperatur" || this.name == "Taupunkt") {
                        if(this.visible && !other.visible) {
                            //both will be invisible soon
                            this.chart.yAxis[0].update({
                                min:element.yAxis.min,
                                max:element.yAxis.max
                            });
                        } else {
                            //one will be visible
                            this.chart.yAxis[0].update({
                                min:null,
                                max:null
                            });
                        }
                    }
                }
            }
        },
 }

这只会在您的系列中没有一个可见时设置最小/最大值,但如果您有一个可见则将其删除

【讨论】:

    猜你喜欢
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多