Skip to content

Commit 1d54898

Browse files
committed
feat: add basic example
1 parent 10b846d commit 1d54898

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

samples/geo.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
5+
<script src="../build/index.umd.js"></script>
6+
</head>
7+
8+
<body>
9+
<div>
10+
<canvas id="canvas"></canvas>
11+
</div>
12+
<script>
13+
fetch('https://cdn.jsdelivr.net/npm/us-atlas/states-10m.json')
14+
.then((r) => r.json())
15+
.then((states10m) => {
16+
const nation = ChartGeo.topojson.feature(states10m, states10m.objects.nation).features[0];
17+
const states = ChartGeo.topojson.feature(states10m, states10m.objects.states).features;
18+
const chart = new Chart(document.getElementById('canvas').getContext('2d'), {
19+
type: 'choropleth',
20+
data: {
21+
labels: states.map((d) => d.properties.name),
22+
datasets: [
23+
{
24+
label: 'States',
25+
outline: nation,
26+
data: states.map((d) => ({
27+
feature: d,
28+
value: Math.random() * 11,
29+
})),
30+
},
31+
],
32+
},
33+
options: {
34+
lscales: {
35+
projection: {
36+
axis: 'x',
37+
projection: 'albersUsa',
38+
},
39+
color: {
40+
axis: 'x',
41+
quantize: 5,
42+
legend: {
43+
position: 'bottom-right',
44+
align: 'right',
45+
},
46+
},
47+
},
48+
},
49+
});
50+
});
51+
</script>
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)