【发布时间】:2016-08-03 01:24:33
【问题描述】:
我正在尝试与 chartJs 进行在线聊天。
我想使用 php 将 MySQL 数据推送到 chartJs。
MySQL 表
id | page_views | visitors | month |
------------------------------------|
1 | 200 | 20 | Jan |
2 | 100 | 10 | Feb |
3 | 500 | 30 | March |
------------------------------------|
图表
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var lineChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
label: "My First dataset",
fillColor : "rgba(220,220,220,0.2)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
},
{
label: "My Second dataset",
fillColor : "rgba(151,187,205,0.2)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(151,187,205,1)",
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
});
}
我想为此应用 MySQL 循环。
谁能给我一个简单的例子如何做到这一点?
【问题讨论】:
-
它是否适用于通过 ajax 和 json 获取数据?
-
@st2erw2od 是的。谢谢。
标签: javascript php jquery json mysqli