0

我在 Highcharts 中有一个向下钻取图表,我希望在向下钻取时隐藏绘图带和绘图线。

我使用向下钻取事件成功隐藏了绘图带,但是当显示向下钻取时,绘图带标签似乎重新出现。

看到这个小提琴:http: //jsfiddle.net/jmunger/KFpJC/

隐藏或显示波段和线的代码如下:

    events: {
        drilldown: function () {
            var myAxis = this.xAxis[0];
            var myPlotBands = myAxis.plotLinesAndBands;
            $.each(myPlotBands, function (i, linesAndBands) {
                if (linesAndBands.label) {
                    linesAndBands.label.hide();
                    linesAndBands.label.opacity = 0;
                }
                linesAndBands.svgElem.hide();
            });
        },
        drillup: function () {
            $.each(this.xAxis[0].plotLinesAndBands, function (i, linesAndBands) {
                linesAndBands.svgElem.show();
                if (linesAndBands.label) {
                    linesAndBands.label.show();
                }
            });
        }
    }

有没有办法确保标签在向下钻取时隐藏,并在向上钻取时重新出现?该行:

linesAndBands.label.hide();

有效地隐藏了标签,但在出现向下钻取图表时它会重新出现。

4

1 回答 1

1

Instead of .hide() you can usee .css() instead: http://jsfiddle.net/KFpJC/2/

        events: {
            drilldown: function () {
                var myAxis = this.xAxis[0];
                var myPlotBands = myAxis.plotLinesAndBands;
                $.each(myPlotBands, function (i, linesAndBands) {
                    linesAndBands.svgElem.hide();
                    if (linesAndBands.label) {
                        linesAndBands.label.css({
                            display: 'none'   
                        });
                    }
                });
            },
            drillup: function () {
                $.each(this.xAxis[0].plotLinesAndBands, function (i, linesAndBands) {
                    linesAndBands.svgElem.show();
                    if (linesAndBands.label) {
                        linesAndBands.label.css({
                            display: 'block'   
                        });
                    }
                });
            }
        }

Most probably, label returns because it's positioned (x/y position and visibility) after other graphics are placed on a plotting area.

于 2014-03-05T10:39:05.660 回答