【发布时间】:2018-12-15 07:50:09
【问题描述】:
我正在使用 ChartJS 制作折线图。我无法从数据库中的成员表中检索买家和卖家的数量。
current output 始终显示基于此查询的成员表中的总行数,SELECT memberID, username, memberType, COUNT(memberID) AS 'count' FROM member
这是我的 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);
}
});
});
如何根据所选年份和月份区分和显示买家和卖家的数量?这就是我想做的。
【问题讨论】:
标签: javascript chart.js linegraph