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

164
Visualizações
Keep selection in highcharts even on page refresh

I am using highcharts for generating/showcasing graph on UI(HTML with JavaScript Page)

There are multiple elements in series section that one can select or unselect to display on graph. But after every refresh, user selected elements gets unselected and only the default selections appear. And user has to select the elements again.

Any solution to it?

One can relate the question from the picture: enter image description here

In this, By default A is selected. If user selects Ball or C then the point graph will appear for Ball and C as well but as soon as graph refreshes, graph will have point graph with A only.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can store your visible series states in local storage. Example:

const savedStates = localStorage.getItem('seriesStates');
const seriesStates = savedStates ?
    JSON.parse(savedStates) : {
        A: true,
        Ball: false,
        C: false,
        D: false
    };

Highcharts.chart('container', {
    series: [{
        name: 'A',
        data: [1, 2, 3],
        visible: seriesStates.A
    }, {
        name: 'Ball',
        data: [2, 2, 2],
        visible: seriesStates.Ball
    }, {
        name: 'C',
        data: [3, 3, 3],
        visible: seriesStates.C
    }, {
        name: 'D',
        data: [4, 4, 4],
        visible: seriesStates.D
    }],
    plotOptions: {
        series: {
            events: {
                legendItemClick: function() {
                    seriesStates[this.name] = !this.visible;
                    localStorage.setItem(
                        'seriesStates',
                        JSON.stringify(seriesStates)
                    );
                }
            }
        }
    }
});

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

Docs: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

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