Chartjs-Chartjs bar chart appears empty when page loads

0👍

Figured it out. In my original code I was using

$.getJSON('http://localhost:5000/api').done((data) => {}

to call my expressjs backend.

I changed it to use

$.ajax({
url: "http://localhost:5000/api",
          success: function (result) {
            let labels = [];
            let data = [];
            for (let item in result.category) {
              if (!result.category.hasOwnProperty(item)) {
                continue;
              }
              labels.push(item);
              data.push(result.category[item]);
            }
       },
       error: function(err) { console.log(err); }
})

and was able to display my bar chart successfully and as expected.

Leave a comment