0

I'm trying to create a line chart using chart.js and I want to pass the axis (the labels in this case) from a php file, this:

<?php  
$new_labels = array('January', 'February', 'March', 'April', 'May', 'June', 'July');
echo json_encode($new_labels);
?>

with this javascript:

         function retrieveLabel(label) {
              $.ajax({
                  url: "sys/class/profilesGraphHandler.php",
                  type: "GET",
                  success: function (data) {
                      label(data);
                  }

              });
          }

          retrieveLabel(function (output) { new_labels = output, console.log(new_labels) });

The console shows me that there are 7 elements in the array I retrieve from the php file but the labels are not shown anyway.

var areaChartData = { labels: new_labels , dataset....};

How can I pass the "new_labels" from the ajax to the labels of the areaChartData ?

0 Answers0