我正在使用莫里斯图表从数据库中获取值。我希望来自数据库的标签也是动态的
$(function() {
$(window).on("load", GetAllProperties);
function GetAllProperties() {
$.ajax({
url: "today_attendance.php",
dataType: 'JSON',
type: 'POST',
success: function(response)
{ var i=0;
Morris.Bar({
element: 'morris-bar',
data: response,
xkey: 'x',
ykeys: ['y', 'z'],
labels: [response[3].a, response[4].b]
});
}
});
今天的出勤代码是
<?php
require_once("../../assets/db_connect.php");
require_once("../../assets/connection.php");
//Get Today Data
$Str = array();
$Res_ = mysqli_query($con,"SELECT batch, mod1, mod2, label1, label2 from
tbl_attendance_chart_data where chart_day = 1");
while($Row_ = mysqli_fetch_array($Res_)){
$string = array(
x => $Row_[0],
y => $Row_[1],
z => $Row_[2],
a => $Row_[3],
b => $Row_[4]
);
$Str[] = $string;
}
echo json_encode($Str);
?>
当我回显一个查询然后显示出来
SELECT batch, mod1, mod2, label1, label2 from tbl_attendance_chart_data where chart_day = 1[{"x":"B3","y":"0","z":"0","a":"M11","b":""},{"x":"B4","y":"43","z":"0","a":"M7","b":"M11"},{"x":"B5","y":"54","z":"0","a":"M7","b":"M11"},{"x":"B6","y":"0","z":"23","a":"M6","b":"M15"},{"x":"B7","y":"0","z":"0","a":"M6","b":""},{"x":"B8","y":"0","z":"0","a":"M10","b":"M6"},{"x":"B9","y":"0","z":"22","a":"M5B1","b":"M4B1"},{"x":"B10","y":"86","z":"88","a":"M3","b":"M4B1"},{"x":"B11","y":"0","z":"0","a":"M3","b":"M8"},{"x":"B12","y":"0","z":"0","a":"","b":""}]