I have been running a few Highcharts on my website. Previously, I populated these with data from my $result array. Below is an example of code for how I would first push several series of data into the $result array and then import it into the Highcharts embed.
$result array is created in variables.php:
$result = array();
array_push($result,$xAxis);
array_push($result,$yAxis);
print json_encode($result, JSON_NUMERIC_CHECK);
$result data is set into the Highcharts embed in a separate php file:
var tableName = '<?php echo $tableName; ?>'
$.getJSON("../data/variables.php", {id: escape(tableName)}, function(json) {
chartOptions.chart1.xAxis.categories = json[0]['data'];
chartOptions.chart1.series[0].data = json[1]['data'];
});
Because I now have to create many different charts, I changed how I make the $result array and now use a loop instead ($result array is now renamed to $compData). This works just fine and all the data I need is captured in $compData using this new setup. However, I don't understand how I can now set data into the Highcharts embed with this new setup of the $compData array. I tried using the 'print json_encode($compData, JSON_NUMERIC_CHECK);' but this doesn't work. I would very much appreciate if anyone can help me with this.
To summarise: the code below works just fine but I am trying to understand how I can input data from the $compData array into my Highcharts.
foreach($idArray as $val) {
$data = [];
$sth->bind_param("s", $val);
$sth->execute();
$result = $sth->get_result();
while ($r = $result->fetch_array()) {
$data = array_merge($data, array_splice($r, 2, $CI_NOYEARS));
}
$compData[$val]["data"] = $data;
}