私はchartJsとラインチャットをしようとしています。MySQLとPHPのchartJs
PHPを使用してMySQLデータをchartJsにプッシュしたいとします。
MySQLのテーブル
id | page_views | visitors | month |
------------------------------------|
1 | 200 | 20 | Jan |
2 | 100 | 10 | Feb |
3 | 500 | 30 | March |
------------------------------------|
chartJs
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のループを適用したいです。
誰も私に簡単な例を教えてもらえますか?
それは、JSONとAjaxのを介してデータを取得して動作していましたか? – st2erw2od
@ st2erw2odはい、ありました。ありがとうございました。 – max