我尝试将数据从数据库(dataviewer)推送到javascript图表,但没有成功。我需要将数据查看器显示为y:(在标签中:“vada 1”,y:数据查看器)。有人知道我在说什么吗´我做错了?谢谢您。数据库连接正常,图形似乎也正常。但数据库里没有数据。
<?php
require('db_config.php');
/* Getting srot_data vada */
$sql = "SELECT count(blok) AS count FROM srot_data WHERE Vada = '1' GROUP BY vada";
$viewer = mysqli_query($mysqli,$sql);
$viewer = mysqli_fetch_all($viewer,MYSQLI_ASSOC);
$viewer = json_encode(array_column($viewer, 'count'),JSON_NUMERIC_CHECK);
?>
<script>
window.onload = function () {
var data_viewer = <?php echo $viewer; ?>;
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "PPM 1"
},
axisY: {
title: "Hodnoty",
lineColor: "#4F81BC",
tickColor: "#4F81BC",
labelFontColor: "#4F81BC"
},
axisY2: {
title: "Procenta",
suffix: "%",
lineColor: "#C0504E",
tickColor: "#C0504E",
labelFontColor: "#C0504E"
},
data: [{
type: "column",
dataPoints: [
{ label: "Vada 1", y: data_viewer },
]
}]
});
chart.render();
createPareto();
function createPareto(){
var dps = [];
var yValue, yTotal = 0, yPercent = 0;
for(var i = 0; i < chart.data[0].dataPoints.length; i++)
yTotal += chart.data[0].dataPoints[i].data_viewer;
for(var i = 0; i < chart.data[0].dataPoints.length; i++){
yValue = chart.data[0].dataPoints[i].data_viewer;
yPercent += (yValue / yTotal * 100);
dps.push({label: chart.data[0].dataPoints[i].data_viewer, y: yPercent});
}
chart.addTo("data",{type:"line", yValueFormatString: "0.##\"%\"", dataPoints: dps});
chart.data[1].set("axisYType", "secondary", false);
chart.axisY[0].set("maximum", yTotal);
chart.axisY2[0].set("maximum", 100);
}
}
</script>
暂无答案!
目前还没有任何答案,快来回答吧!