$'dbhost' = 'localhost'; $dbname = 'chart'; $dbuser = 'root'; $dbpass = '';
try{
$dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $ex)
{ die($ex->getMessage());
}
$stmt=$dbcon->prepare("SELECT * FROM contribution ");
$stmt->execute();
while ($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
$json[] = $student;
$json2[] = (int)$contribution;
}
echo json_encode($json); echo json_encode($json2); ?>
window.onload = function ()
{
var chart = new CanvasJS.Chart("chartContainer",
{
animationEnabled: true
, exportEnabled: true
theme: "light1", // "light1", "light2", "dark1", "dark2"
title:{ text: "PHP Column Chart from Database" }
, data: [{ type: "column", //change type to bar, line, area, pie, etc
dataPoints: }]
}
);
chart.render();
}
答案 0 :(得分:0)
在代码正确对齐的情况下,您会看到在和标题之前缺少两个逗号
并且您必须将构建的json传递给数据点。
animationEnabled: true
, exportEnabled: true
,theme: "light1" // "light1", "light2", "dark1", "dark2"
,title:{ text: "PHP Column Chart from Database" }
, data: [{ type: "column",
dataPoints:<?php echo json_encode($json2); ?>
}]
但这只是一个示例,您所缺少的东西。
您必须检查$ jsons是否为correct format