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',但我怎么做,而不是每次都有相同的值? –