how to use chart js with mysql database

Solutions on MaxInterview for how to use chart js with mysql database by the best coders in the world

showing results for - "how to use chart js with mysql database"
Delfina
19 Jul 2017
1$(document).ready(function(){
2  $.ajax({
3    url: "http://localhost/chartjs/data.php",
4    method: "GET",
5    success: function(data) {
6      console.log(data);
7      var player = [];
8      var score = [];
9
10      for(var i in data) {
11        player.push("Player " + data[i].playerid);
12        score.push(data[i].score);
13      }
14
15      var chartdata = {
16        labels: player,
17        datasets : [
18          {
19            label: 'Player Score',
20            backgroundColor: 'rgba(200, 200, 200, 0.75)',
21            borderColor: 'rgba(200, 200, 200, 0.75)',
22            hoverBackgroundColor: 'rgba(200, 200, 200, 1)',
23            hoverBorderColor: 'rgba(200, 200, 200, 1)',
24            data: score
25          }
26        ]
27      };
28
29      var ctx = $("#mycanvas");
30
31      var barGraph = new Chart(ctx, {
32        type: 'bar',
33        data: chartdata
34      });
35    },
36    error: function(data) {
37      console.log(data);
38    }
39  });
40});
41