0
我想用CanvasJS創建兩個圖表,我使用php文件中的值。 我有兩個圖表,但只有一個呈現,第二個只有白色背景和標題文本。 這裏是PHP代碼值:CanvasJS和PHP
<?php
require 'excCon.php';
$dataPoints = array(
array("y" => $excel_result, "label" => "Quantity"),
array("y" => $excel_result2, "label" => "Value"),
);
$dataP = array(
array("y" => $excel_result3, "name" => "1", "exploded" => false),
array("y" => $excel_result4, "name" => "2"),
array("y" => $excel_result5, "name" => "3&5"),
array("y" => $excel_result6, "name" => "4"),
);
?>
和javascript:
<div id="chartContainer style="height: 400px;width: 80%"">
<script type="text/javascript">
$(function() {
var chart1 = new CanvasJS.Chart("chartContainer", {
theme: "theme2",
animationEnabled: true,
title: {
text: "Sum"
},
data: [
{
type: "column",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
}
]
});
chart1.render();
});
</script>
</div>
<div id="chartContainer2" style="height: 400px;width: 80%">
<script type="text/javascript">
$(function() {
var chart2 = new CanvasJS.Chart("chartContainer2",
{
theme: "theme2",
title:{
text: "All"
},
exportFileName: "All",
exportEnabled: false,
animationEnabled: false,
data: [
{
type: "pie",
showInLegend: true,
toolTipContent: "{name}: <strong>{y}%</strong>",
indexLabel: "{name} {y}%",
dataP: <?php echo json_encode($dataP, JSON_NUMERIC_CHECK); ?>
}]
});
chart2.render();
});
</script>
</div>
整個代碼在index.php
文件。
爲了記錄,我在這裏搜索了其他解決方案以及官方頁面,但都沒有工作。
我覺得現在的問題是'dataPoints'。它必須是每個圖表中的'dataPoints',但我怎麼做,而不是每次都有相同的值? –