Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!