首页 文章

Highcharts明细表:在向下钻取或钻取时显示/隐藏绘图带和线

提问于
浏览
0

我在Highcharts中有一个下钻图表,我希望在发生下钻时隐藏绘图带和绘图线 .

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

看到这个小提琴: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();

有效隐藏标签,但在出现下钻图表时会重新出现 .

1 回答

  • 1

    而不是 .hide() ,你可以使用 .css() 代替: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'   
                            });
                        }
                    });
                }
            }
    

    最有可能的是,标签返回是因为在将其他图形放置在绘图区域之后,标签返回(x / y位置和可见性) .

相关问题