Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new Chart(document.getElementById("line-chart"), {
- type: 'line',
- data: {
- labels: ['2018-10-01','2018-10-02','2018-10-03','2018-10-04','2018-10-05','2018-10-06','2018-10-07','2018-10-08','2018-10-09','2018-10-10','2018-10-11','2018-10-12','2018-10-13','2018-10-14','2018-10-15','2018-10-16','2018-10-17','2018-10-18','2018-10-19',],
- datasets: [{
- data: [181,221,222,209,266,649,725,434,249,232,176,271,418,354,189,154,202,187,222,],
- label: "Карпы",
- borderColor: "#3e95cd",
- fill: false
- },
- {
- data: [100,14,16,247],
- label: "Пескари",
- borderColor: "#333333",
- fill: false
- }
- ]
- }
- });
- $X_date="";
- $Y_du="";
- while($row = $STH->fetch()) {
- $X_date.="'".$row['date']."',";
- $Y_du.=$row['new_users_count'].",";
- }
- echo $data ;
- echo json_encode(array('X_date'=>$X_date, 'Y_dau'=>$Y_dau));
- $.ajax({
- type: "POST",
- dataType:'json',
- url: "serverscript/output.php",
- success: function(json) {
- console.log(json.X_date);
- new Chart(document.getElementById("line-chart"), {
- type: 'line',
- data: {
- labels: [json.X_date],
- datasets: [{
- data: [json.Y_dau],
- label: "Карпы",
- borderColor: "#3e95cd",
- fill: false
- }
- ]
- }
- })
- },
- error: function() {
- console.log("ERROR", this);
- }
- });
- data: {
- labels: [json.X_date],
- datasets: [{
- data: [json.Y_dau],
- label: "Карпы",
- borderColor: "#3e95cd",
- fill: false
- }
- console.log("X_date"+json.X_date);
- console.log("Y_dau"+json.Y_dau);
- X_date'2018-10-01','2018-10-02','2018-10-03','2018-10-04','2018-10-05','2018-10-06','2018-10-07','2018-10-08','2018-10-09','2018-10-10','2018-10-11','2018-10-12','2018-10-13','2018-10-14','2018-10-15','2018-10-16','2018-10-17','2018-10-18','2018-10-19',
- Y_dau181,221,222,209,266,649,725,434,249,232,176,271,418,354,189,154,202,187,222,
- console.log("json.X_date", typeof json.X_date, json.X_date);
- console.log("json.Y_du", typeof json.Y_dau, json.Y_dau);
- json.X_date string '2018-10-01','2018-10-02','2018-10-03','2018-10-04','2018-10-05','2018-10-06','2018-10-07','2018-10-08','2018-10-09','2018-10-10','2018-10-11','2018-10-12','2018-10-13','2018-10-14','2018-10-15','2018-10-16','2018-10-17','2018-10-18','2018-10-19',
- json.Y_du string 181,221,222,209,266,649,725,434,249,232,176,271,418,354,189,154,202,187,222,
- $X_date = array();
- $Y_dau = array();
- while($row = $STH->fetch()) {
- array_push($X_date, $row['date']);
- array_push($Y_dau, $row['new_users_count']);
- }
- json.X_date object ["2018-10-01", "2018-10-02", "2018-10-03", "2018-10-04", "2018-10-05", "2018-10-06", "2018-10-07", "2018-10-08", "2018-10-09", "2018-10-10", "2018-10-11", "2018-10-12", "2018-10-13", "2018-10-14", "2018-10-15", "2018-10-16", "2018-10-17", "2018-10-18", "2018-10-19"]
- json.Y_du object ["181", "221", "222", "209", "266", "649", "725", "434", "249", "232", "176", "271", "418", "354", "189", "154", "202", "187", "222"]
- console.log("json.X_date", typeof json.X_date, json.X_date);
- console.log("json.Y_dau", typeof json.Y_dau, json.Y_dau);
- data: {
- labels: JSON.parse("["+json.X_date+"]"),
- datasets: [{
- data: JSON.parse("["+json.Y_dau+"]"),
- label: "Карпы",
- borderColor: "#3e95cd",
- fill: false
- }
- ]
- }
Add Comment
Please, Sign In to add comment