Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
How to draw a chart with highcharts.js once I retrieved all the data from firebase database?

I get data from my Firebase database every ten seconds. I want to plot a graph with highcharts.js, but when I access the web page, I get all the data prior to the moment the page is loaded. At this point, my web page freezes and crashes after a few minutes while the data is being recovered. (I also have a second piece of code that retrieves the new data each time it is added to the database but the web page crashes before).

I think it's my plotvalue function that is crashing the page. When I suppress plotValue(...) I can read my data in a few seconds even if there's 15k+. Indeed, it may be because i'm redrawing the chart each time I receive a data instead of waiting to retrieve it all.

I would like to know how to draw the chart once all of my data is retrieved from my database.

I thank you in advance for your answers.

Here is the code:

setInterval(test, 10000);
function test() {
 if (it === 0) {
  console.log("it=", it);
  dbRef.orderByKey().once('value', snapshot => { //"value" to have all existing data
    var jsonData = snapshot.toJSON();
    //console.log(jsonData); // Test purpose
    var coco = Object.values(jsonData); //Extract the numerical values of the object
    // Save values on variables
    //console.log(Défaut_communication_automate); //Test purpose
    coco.forEach(elt => { //Choose in coco for each element 
            var Puissance_batterie = elt.Puissance_batterie; //Choose all the values 
           of the element named "Puissance_batterie"
            var Puissance_AC_Onduleurs = elt.Puissance_AC_Onduleurs;
            var Tension_réseau = elt.Tension_réseau;
            var timestamp = elt.timestamp;
            //console.log(Puissance_batterie);
            plotValues(chartALM, timestamp, Puissance_batterie, 0);
            plotValues(chartALM, timestamp, Puissance_AC_Onduleurs, 1);
            plotValues(chartALM, timestamp, Tension_réseau, 2);
        })
        ++it;
    console.log("it=", it);
})
}
//function to plot values on charts
function plotValues(chart, timestamp, value, series) {
  var x = epochToJsDate(timestamp).getTime();
  var y = Number(value);
  chart.series[series].addPoint([x, y], false, false);
  chart.redraw();
}

 // Create the charts when the web page loads
 window.addEventListener('load', onload);

 function onload(event) {
   chartALM = createALMChart();
   barALM = createALMBar();
 }

 // Create Chart
 function createALMChart() {

  var chart = new Highcharts.Chart({
   chart: {
      renderTo: 'chart-ALM',
      type: 'spline'
   }
   //The following is only about the visual aspect
  }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda