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

258
Vistas
Cant update ApexChart graph with JavaScript...>

Im trying to refresh a chart after fetching data from MySQL but my updateChart function isnt being executed.

I know it's not being executed because the console.logs (displaying the Boo! and displaying the driversChartData array are not being displayed in the console. I know there is data in the array because it consoles out the data if I do the console.log from outside the function.

Any idea why my function isnt being run after the if statement?

(Ive tried removing the whole if statement in case it interfered but to no avail). Must be a really single thing, but Im new to JS so any help would be greatly appreciated :)

Thanks. M.

document.addEventListener('DOMContentLoaded', function () {
    fetch('http://127.0.0.1:3000/driversChart')
    .then(response => response.json())
    .then(data => loadDriversChart(data['data']));
});

function loadDriversChart(driversChartData) {

    const driversChartArea = document.querySelector("#driversChart");

    if (driversChartData.length === 0) {
        var options = {
            chart: {
                height: 350,
                type: 'line',
            },
            dataLabels: {
                enabled: false
            },
            series: [],
            title: {
                text: 'F1 Drivers Points Repartition',
            },
            noData: {
              text: 'Loading Drivers Chart...'
            }
          }
          
          var chart = new ApexCharts(
            document.querySelector("#driversChart"),
            options
          );
          
          chart.render();
    }

    // Data is fetched so update the Drivers' Chart
    function updateChart(driversChartData) {
        console.log('Boo!');
        console.log(driversChartData);
        driversChartArea.updateSeries( [ {
          name: 'F1 Drivers Points Repartition',
          data: driversChartData
        } ] );
      };
}
about 4 years ago · Santiago Trujillo
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