Chartjs-Calling chart JS with PHP Data (file structure)

0👍

ChartJS expects the data in a comma separated statement, such as:

 data: 5, 7, 8, 9;

I suspect the json_encode is confusing it, and would suggest you return strings, rather than arrays:

$stmt=$pdo->prepare("SELECT * FROM asset_details");
$stmt->execute(); 
$json= "";
$json2= [];
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
    extract($row);
    $json .= "'".$type."',";
    $json2 .= (int)$manufacturer.",";
}
echo $json; // should be 'Red','Green','Blue' ... 
echo $json2; // should be 5,6,9,4 ... etc 
?>   

Leave a comment