【发布时间】:2020-05-24 14:31:59
【问题描述】:
我需要显示 2 个图表,一个是条形图。另一个是 php.so m 中的饼图,使用画布图表。但是当我添加第二个图表时,第一个图表会自动消失。
$dataPoints = array(
array("y" => $total_announcement, "label" => "Total Announcement" ),
array("y" => $active_announcement, "label" => "Active" ),
array("y" => $pending_announcement, "label" => "Pending " ),
array("y" => $other_announcement, "label" => "Others" )
);
<script>
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2",
title:{
text: ""
},
axisY: {
title: "Number Of Announcement"
},
data: [{
type: "column",
yValueFormatString: "#,##0.## ",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
}]
});
chart.render();
}
</script>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
这是我的第一个图表,运行良好。
$dataPoints2 = array(
array("label"=>"Industrial", "y"=>51.7),
array("label"=>"Transportation", "y"=>26.6),
array("label"=>"Residential", "y"=>13.9),
array("label"=>"Commercial", "y"=>7.8)
)
<script>
window.onload = function() {
var chart2 = new CanvasJS.Chart("chartContainer2", {
theme: "light2",
animationEnabled: true,
title: {
text: "World Energy Consumption by Sector - 2012"
},
data: [{
type: "pie",
indexLabel: "{y}",
yValueFormatString: "#,##0.00\"%\"",
indexLabelPlacement: "inside",
indexLabelFontColor: "#36454F",
indexLabelFontSize: 18,
indexLabelFontWeight: "bolder",
showInLegend: true,
legendText: "{label}",
dataPoints: <?php echo json_encode($dataPoints2, JSON_NUMERIC_CHECK); ?>
}]
});
chart2.render();
}
</script>
<div id="chartContainer2" style="height: 370px; width: 100%;"></div>
这是我的第二张图表。一旦 m 添加第二个 .. 第一个图表就会消失。 它们都工作正常,但只显示第二个。
【问题讨论】:
标签: javascript php canvasjs