I have an array $results and I need to use it inside my javascript part of the code. I tried json_encode() but it did not work..
Here is the code
<?php
//...
include realpath($_SERVER['DOCUMENT_ROOT'] . '/Classes/Controllers/ReportController.php');
$vaccRep= ReportController::getVacRep();
include realpath($_SERVER['DOCUMENT_ROOT'] . '/Classes/Controllers/VaccineController.php');
$names=VaccineController::getVCName();
?>
<canvas id="bar" height="195" width="250" style="width: 250px; height: 195px;"></canvas>
<script>
//THIS IS THE PART THAT WILL BE THE OTPUT OF THE QUERY
var barChartData = {
labels: <?php$obj=json_encode($names); var_dump($obj);?>,
datasets: [{
highlightFill: "#45668e",
highlightStroke: "#45668e",
fillColor : "#1ABC9C",
strokeColor : "#1ABC9C",
data: <?php $obj=json_encode($vaccRep); var_dump($obj);?>
}]
};
new Chart(document.getElementById("bar").getContext("2d")).Bar(barChartData);
<?php $obj=json_encode($vaccRep); var_dump($obj);?>
</script>