Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!