-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts.php
172 lines (162 loc) · 5.95 KB
/
charts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
require 'lastfm.php';
$user = $_GET["user"];
if ($_GET["user"] == NULL) {
$user = 'devonbarks';
}
$lastfm = new LastFM("092d316884d8385f35ad8b84f5f42ef8");
$topArtists = $lastfm->getTopArtists($user);
$topTracks = $lastfm->getTopTracks($user);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<div class="container">
<canvas id="artists" height="40vh" width="80vw"></canvas>
</div>
<div class="container">
<canvas id="tracks" height="40vh" width="80vw"></canvas>
</div>
<script id="top-artist">
let artists = document.getElementById('artists').getContext('2d');
let topArtists = new Chart(artists, {
type: 'bar',
data: {
labels: [
<?php foreach ($topArtists->artist as $k=>$v): ?>
'<?= $v->name ?>',
<?php endforeach; ?>
],
datasets: [{
label: 'Top 10 Artists',
data: [
<?php foreach ($topArtists->artist as $k=>$v): ?>
'<?= $v->playcount ?>',
<?php endforeach; ?>
],
backgroundColor: [
'#4e79a7',
'#59a14f',
'#9c755f',
'#f28e2b',
'#edc958',
'#bab0ac',
'#e15759',
'#b07aa1',
'#76b7b2',
'#ff9da7'
]
}]
},
options: {
title: {
display: true,
text: 'Top 10 Played Artists',
fontSize: 25
},
legend: {
display: true,
position: 'right'
}
}
})
</script>
<script id="top-artist2">
let tracks = document.getElementById('tracks').getContext('2d');
let topTracks = new Chart(tracks, {
type: 'doughnut',
data: {
labels: [
<?php foreach ($topTracks->track as $k=>$v): ?>
"<?= $v->name ?>",
<?php endforeach; ?>
],
datasets: [{
label: 'Top 10 Artists',
data: [
<?php foreach ($topTracks->track as $k=>$v): ?>
'<?= $v->playcount ?>',
<?php endforeach; ?>
],
backgroundColor: [
'#4e79a7',
'#59a14f',
'#9c755f',
'#f28e2b',
'#edc958',
'#bab0ac',
'#e15759',
'#b07aa1',
'#76b7b2',
'#ff9da7'
]
}]
},
options: {
title: {
display: true,
text: 'Top 10 Played Songs',
fontSize: 25
},
legend: {
display: true,
position: 'right'
}
}
})
</script>
<script id="top-songs">
let songs = document.getElementById('songs').getContext('2d');
let topSongs = new Chart(songs, {
type: 'pie',
data: {
labels: [
<?php foreach ($topTracks->track as $k=>$v): ?>
'<?= $v->name ?>',
<?php endforeach; ?>
],
datasets: [{
label: 'Top 10 Artists',
data: [
<?php foreach ($topTracks->track as $k=>$v): ?>
'<?= $v->playcount ?>',
<?php endforeach; ?>
],
backgroundColor: [
'#4e79a7',
'#59a14f',
'#9c755f',
'#f28e2b',
'#edc958',
'#bab0ac',
'#e15759',
'#b07aa1',
'#76b7b2',
'#ff9da7'
]
}]
},
options: {
title: {
display: true,
text: 'Top 10 Played Artists',
fontSize: 25
},
legend: {
display: true,
position: 'right'
}
}
})
</script>
</body>
</html>