-
Notifications
You must be signed in to change notification settings - Fork 0
/
cities.html
59 lines (52 loc) · 1.68 KB
/
cities.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Artworks Bar Chart</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
</head>
<body>
<canvas id="artworksChart"></canvas>
</body>
<script>
fetch('jsons/data.json')
.then(response => response.json())
.then(data => {
const cityArtworkCounts = {};
data.forEach(artist => {
artist.cities.forEach(city => {
const cityName = city.city_name;
const artworkCount = city.city_holders.length;
cityArtworkCounts[cityName] = (cityArtworkCounts[cityName] || 0) + artworkCount;
});
});
const sortedCities = Object.entries(cityArtworkCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 30);
const cityLabels = sortedCities.map(entry => entry[0]);
const artworkCounts = sortedCities.map(entry => entry[1]);
const ctx = document.getElementById('artworksChart').getContext('2d');
new Chart(ctx, {
type: 'horizontalBar',
data: {
labels: cityLabels,
datasets: [{
label: '# of Artworks',
data: artworkCounts,
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
},
options: {
scales: {
xAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
});
</script>
</html>