-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathalbers.html
57 lines (55 loc) · 1.6 KB
/
albers.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
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.9.1/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>
<body>
<div style="width: 75%; border: 1px solid black">
<canvas id="canvas"></canvas>
</div>
<script>
fetch('https://unpkg.com/us-atlas/states-10m.json')
.then((r) => r.json())
.then((us) => {
const nation = ChartGeo.topojson.feature(us, us.objects.nation).features[0];
const states = ChartGeo.topojson.feature(us, us.objects.states).features;
const chart = new Chart(document.getElementById('canvas').getContext('2d'), {
type: 'choropleth',
data: {
labels: states.map((d) => d.properties.name),
datasets: [
{
label: 'States',
outline: nation,
data: states.map((d) => ({
feature: d,
value: Math.random() * 11,
})),
},
],
},
options: {
plugins: {
legend: {
display: false,
},
},
scales: {
xy: {
projection: 'albersUsa',
},
color: {
quantize: 5,
legend: {
position: 'bottom-right',
align: 'right',
},
},
},
},
});
});
</script>
</body>
</html>