Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
plotBands Hide and Show parameters do not work in Highcharts

When I clicked in legend, the plotBands parameters hide() and show() do not work.

I wish I could click on the legend and remove a specific PlotBand.

I tried using destroy() but it cleans the html dom and I can't return with PlotBand when I click on the legend again.

I couldn't find how to remove and put the PlotBand back on:

var a = 1,
    b = 2,
    c = 4,
    d = 5,
    dados = [[a, b, '#32CD32','manutenção','Mantuenção'], [c, d, '#FF0000','falha','Falha']];

Highcharts.chart('container', {
        chart: {
            zoomType: 'xy',

        },
        showInLegend: true,
        title: {
            text: 'Zoom Geral e Barras Verticais'
        },
        yAxis: {
            scrollbar: {
                enabled: true,
                showFull: false
            }
        },
            
        plotOptions: {
        series: {
            shadow:false,
            borderWidth:0,
            events:{
                legendItemClick:function(e){
                  
                  console.log(this.userOptions)

                  var ids = this.userOptions['id'];
                  console.log(ids)

                  if(this.userOptions['id'] === ids){
                    var hides = this.xAxis.plotLinesAndBands.filter(id => id.id == ids);
                    
                    if(this.visible == true){
                        hides[0].svgElem.hide()
                    } else {
                        hides[0].svgElem.show()
                      }
                  }
                }
            }
        }
    },    
            
        series: [{
              name:'Série A',
            data: [-10, 31, 35, 40, 15, 10]  
        }
    ]
    },
    function(){
                    for (let i = 0; i < dados.length; i++ ){
          this.xAxis[0].addPlotBand({
                   from: dados[i][0],
                   to: dados[i][1],
                   color: dados[i][2],
                   name: dados[i][4],
                   id: dados[i][3]

            }, )
            
          this.addSeries({
             marker: {
                        symbol: 'square',
                  radius: 20},
             name: dados[i][4],
             color: dados[i][2],
             type: 'scatter',
             id: dados[i][3]
            }, )
            }   
        }     
)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The plot bands are not hidden because the chart is redrawn after the event. You can return false from the callback function, but all plot bands will be visible after another redraw. Example: http://jsfiddle.net/BlackLabel/m2xrjhLk/

I recommend you to remove/add the plot band on legend click:

    plotOptions: {
        series: {
            ...,
            events: {
                legendItemClick: function(e) {
                    var id = this.options.id;

                    if (this.visible) {
                        this.xAxis.removePlotBand(id);
                    } else {
                        this.xAxis.addPlotBand(plotBands.find(
                            plotBand => plotBand.id === id
                        ));
                    }
                }
            }
        }
    }

Live demo: http://jsfiddle.net/BlackLabel/n1jgew27/

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda