[我正在使用CanvasJs并在连接MySQL时遇到问题,我的值即将到来,但我的图形未显示

问题描述 投票:0回答:1
$'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(); 
    }
mysql canvasjs
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.