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

155
Visualizações
plotly js globals not being available to other function

This is usually a simple problem to solve with a global var. But nooooo... All the code works, the csv is read in, the arrays created with the correct values (x,y), a default graph is drawn, but the newPlot function vars are not acting like globals and are empty, so the plot is an empty default of 6x6 with no traces. The newPlot vars are globals. Is plotly.js different? Line 63 is the culprit. This code is pretty much a clone of: plotlyHover

<!DOCTYPE html>
<html lang="en" >
<head>
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<div id="myDiv"></div>
<div id="hoverinfo" style="margin-left:80px;"></div>
 
<!-- cloudcover.csv looks like this.
Time,CloudCover
2022-04-06 10:07:09,0
2022-04-06 11:07:18,100.0
2022-04-06 12:08:17,100.0
2022-04-06 13:09:16,96.0
2022-04-06 14:10:15,66.0
2022-04-06 15:11:14,7.0
-->


<script>
    var traces = [];
    var layout = {};
    var config = {};
    const CSV = "cloudcover.csv";
  
    Plotly.d3.csv(CSV, function(rows) {
      let x = [];
      let y = [];
      let row;
      let i = 0;
      while (i < rows.length) {
        row = rows[i];
        x.push(row["Time"]);
        y.push(row["CloudCover"]);
        i += 1;
      };
      traces = [{
        x: x,
        y: y,
        line: {
          color: "#387fba"
        },
        width: 16,
      }];
  
      layout = {
        title: 'Cloudcover',
        yaxis: {
          range: [0, 100]
        },
        xaxis: {
          tickformat: "%H:%M:%S"
        }
      };
  
      config = {
        responsive: true
      };
  
    });
    
    Plotly.newPlot('myDiv', traces, layout, config, {
      showSendToCloud: true
    });
  
    var myPlot = document.getElementById('myDiv')
    hoverInfo = document.getElementById('hoverinfo')
  
    myPlot.on('plotly_hover', function(data) {
      var infotext = data.points.map(function(d) {
        return (d.data.name + ': x= ' + d.x + ', y= ' + d.y.toPrecision(3));
      });
      hoverInfo.innerHTML = infotext.join('<br/>');
    })
  
    myPlot.on('plotly_unhover', function(data) {
      hoverInfo.innerHTML = '';
    });
  </script>
  </body>
  
  </html>
  
  
about 4 years ago · Santiago Trujillo
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