我正在使用ChartJS制作折线图。我无法从我的数据库的成员表中检索到买家和卖家的编号。
根据此查询SELECT memberID, username, memberType, COUNT(memberID) AS 'count' FROM member,current output始终显示成员表中的总行
下面是我的js:
$(document).ready(function() {
$.ajax({
url : "../api/data.php",
type : "GET",
success : function(data){
console.log(data);
var count = {
B : [],
S : []
};
var len = data.length;
for (var i = 0; i < len; i++) {
if (data[i].memberType == "B") {
count.B.push(data[i].count);
}
else if (data[i].memberType == "S") {
count.S.push(data[i].count);
}
}
//get canvas
var ctx = $("#line-chartcanvas");
var data = {
labels : ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JULY", "AUG", "SEPT", "OCT", "NOV", "DEC"],
datasets : [
{
label : "Buyer",
data : count.B,
backgroundColor : "blue",
borderColor : "lightblue",
fill : false,
lineTension : 0,
pointRadius : 5
},
{
label : "Seller",
data : count.S,
backgroundColor : "red",
borderColor : "lightred",
fill : false,
lineTension : 0,
pointRadius : 5
}
]
};
var options = {
title : {
display : true,
position : "top",
text : "Line Graph",
fontSize : 18,
fontColor : "#111"
},
legend : {
display : true,
position : "bottom"
}
};
var chart = new Chart( ctx, {
type : "line",
data : data,
options : options
} );
},
error : function(data) {
console.log(data);
}
});
});如何根据所选年份和月份区分和显示买卖双方的数量?这就是我想要做的。
发布于 2018-12-15 16:42:24
我认为问题在于"count.b“变量必须是一段时间内的记录数组。也就是说,就像这样:
var count = {
B: [1,2,3,4,5,6,7,8,9,10,11,12],
S: [1,2,3,4,5,6,7,8,9,10,11,12]
};如果你只有一个固定的数字,它会理解它指的是第一个月。
https://stackoverflow.com/questions/53790547
复制相似问题