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

222
Visualizações
Buttons for horizontal and vertical bar chart views, but axes failed to change

I’m using plotly.js to work on a bar chart and want to create two buttons to switch between horizontal and vertical views.

However, my code for the change in x-axis doesn’t seem to work.

Below are screenshots of the malfunction and my code:

Horizontal view image

Vertical view image (x-axis did not switch, y-axis not in counts but in categories)

    var data = [
    //horizontal graph
    {
      type: 'bar',
      x: xData2,
      y: yData2,
      marker: {
        color: 'rgba(255, 100, 102, 0.7)',
      },
      name:'Bar Chart',
      orientation:'h',
      xaxis: { title: 'Count' },
      yaxis: { title: xAxisAttribute },
      
    },
    //vertical graph
    {
      type: 'bar',
      y: yData,
      x: xData,
      orientation:'v',
      marker: {
        color: 'rgba(255, 100, 102, 0.7)',
      },
      name:'Bar Chart',
      visible: false
    }]
  var button_layer_2_height = 1.2;
  var updatemenus=[
      {
          buttons: [
              {
                  args: [{'visible': [true, false]}],
                  label: 'Horizontal View',
                  method: 'update'
              },
              {
                  args: [{'visible': [false, true]}],
                  label: 'Vertical View',
                  method: 'update'
              },
          ],
          direction: 'left',
          pad: {'r': 10, 't': 10},
          showactive: true,
          type: 'buttons',
          x: 0.1,
          xanchor: 'left',
          y: button_layer_2_height,
          yanchor: 'top'
      },
  ]  
  let layout = {
    title: title || 'Untitled',
    autosize: true,
    hovermode:'closest',
    updatemenus: updatemenus,
    };

  return (
    <div>
      <Plot
        data ={data}
        layout = {layout}
        config = {config}
          />
      </div>
    ) 
    }

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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