我希望在我的 PHP 專案中使用 QuickChart。我完全瀏覽了檔案。但是,其中的所有內容都將資料靜態加載為陣列。我正在嘗試將從其他地方生成的外部資料加載到圖表中。為了理解 QuickChart,我嘗試在檔案中提供的示例中動態加載資料。
<?php
require_once('QuickChart.php'); //the QuickChart.php file is copied in the same folder as this file.
$qc = new QuickChart();
$data = array(50, 60, 70, 180); //loading data dynamically.
$qc->setConfig("{
type: 'bar',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Users',
data: $data //line with error.
}]
}
}");
$a = $qc->getUrl();
$imageData = base64_encode(file_get_contents($a));
echo '<img src="data:image/jpeg;base64,'.$imageData.'">';
?>
但是,有如下錯誤。
Notice: Array to string conversion in C:\xampp\htdocs\quickChart\index.php on line 12
以下是我修改的示例。
<?php
require_once('../QuickChart.php');
$qc = new QuickChart();
$qc->setConfig("{
type: 'bar',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Users',
data: [50, 60, 70, 180]
}]
}
}");
echo $qc->getUrl();
?>
我在互聯網上搜索了一段時間,但似乎 QuickChart 沒有那么流行,因此可以閱讀的資源并不多。這種情況下的解決方案是什么?
uj5u.com熱心網友回復:
這看起來像一個陣列的 JSON 字串表示,例如
$jj = json_encode([50, 60, 70, 180]);
$qc->setConfig("{
type: 'bar',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Users',
data: $jj
}]
}
}";
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/365913.html
上一篇:將yahoofinancials多維字典輸出轉換為資料框
下一篇:PHP日期格式變數
