@amcharts/amcharts5-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitmodules +3 -0
- package/README.md +82 -0
- package/amcharts5-skill/README.md +50 -0
- package/amcharts5-skill/amcharts5-skill/SKILL.md +667 -0
- package/amcharts5-skill/amcharts5-skill/references/flow.md +523 -0
- package/amcharts5-skill/amcharts5-skill/references/gantt.md +410 -0
- package/amcharts5-skill/amcharts5-skill/references/hierarchy.md +568 -0
- package/amcharts5-skill/amcharts5-skill/references/map.md +574 -0
- package/amcharts5-skill/amcharts5-skill/references/pie.md +663 -0
- package/amcharts5-skill/amcharts5-skill/references/radar.md +584 -0
- package/amcharts5-skill/amcharts5-skill/references/stock.md +664 -0
- package/amcharts5-skill/amcharts5-skill/references/timeline.md +449 -0
- package/amcharts5-skill/amcharts5-skill/references/ui-elements.md +393 -0
- package/amcharts5-skill/amcharts5-skill/references/venn.md +368 -0
- package/amcharts5-skill/amcharts5-skill/references/wordcloud.md +339 -0
- package/amcharts5-skill/amcharts5-skill/references/xy.md +1150 -0
- package/amcharts5-skill/cursorrules +820 -0
- package/package.json +27 -0
- package/src/index.js +329 -0
- package/test.js +153 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
# Map Charts — Geographic Visualizations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Required imports
|
|
5
|
+
|
|
6
|
+
### ES modules
|
|
7
|
+
```ts
|
|
8
|
+
import * as am5 from "@amcharts/amcharts5";
|
|
9
|
+
import * as am5map from "@amcharts/amcharts5/map";
|
|
10
|
+
import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
|
|
11
|
+
import am5geodata_worldLow from "@amcharts/amcharts5-geodata/worldLow";
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### CDN
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
17
|
+
<script src="https://cdn.amcharts.com/lib/5/map.js"></script>
|
|
18
|
+
<script src="https://cdn.amcharts.com/lib/5/geodata/worldLow.js"></script>
|
|
19
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Geodata (map files)
|
|
23
|
+
|
|
24
|
+
NPM: `@amcharts/amcharts5-geodata`
|
|
25
|
+
CDN: `https://cdn.amcharts.com/lib/5/geodata/{mapName}.js`
|
|
26
|
+
|
|
27
|
+
| Map | ES import | CDN global |
|
|
28
|
+
|-----|----------|-----------|
|
|
29
|
+
| World (low detail) | `@amcharts/amcharts5-geodata/worldLow` | `am5geodata_worldLow` |
|
|
30
|
+
| World (high detail) | `@amcharts/amcharts5-geodata/worldHigh` | `am5geodata_worldHigh` |
|
|
31
|
+
| USA (low) | `@amcharts/amcharts5-geodata/usaLow` | `am5geodata_usaLow` |
|
|
32
|
+
| USA (high) | `@amcharts/amcharts5-geodata/usaHigh` | `am5geodata_usaHigh` |
|
|
33
|
+
| France (low) | `@amcharts/amcharts5-geodata/franceLow` | `am5geodata_franceLow` |
|
|
34
|
+
| Continents | `@amcharts/amcharts5-geodata/continentsLow` | `am5geodata_continentsLow` |
|
|
35
|
+
|
|
36
|
+
Pattern: camelCase country name + detail level. E.g. `germanyLow`, `canadaHigh`, `chinaLow`.
|
|
37
|
+
|
|
38
|
+
**IMPORTANT — regional/continent geodata:**
|
|
39
|
+
- Individual country maps: `geodata/{countryName}Low.js` → global `am5geodata_{countryName}Low`
|
|
40
|
+
- **There are NO continent-level maps** like `europeLow.js` or `asiaLow.js` at the top-level CDN path
|
|
41
|
+
- Regional maps are in subdirectories: `geodata/region/world/{regionName}Low.js`
|
|
42
|
+
- CDN: `https://cdn.amcharts.com/lib/5/geodata/region/world/europeLow.js`
|
|
43
|
+
- Global: `am5geodata_region_world_europeLow`
|
|
44
|
+
- For a map of European countries, use `worldLow.js` and filter with `include: ["DE", "FR", "IT", ...]`
|
|
45
|
+
- US congressional districts: `geodata/usaCongressionalLow.js` (may not be available on all CDN versions)
|
|
46
|
+
|
|
47
|
+
## Core setup
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const root = am5.Root.new("chartdiv");
|
|
51
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
52
|
+
|
|
53
|
+
const chart = root.container.children.push(
|
|
54
|
+
am5map.MapChart.new(root, {
|
|
55
|
+
panX: "rotateX", // "translateX", "rotateX", "none"
|
|
56
|
+
panY: "translateY", // "translateY", "rotateY", "none"
|
|
57
|
+
projection: am5map.geoMercator(),
|
|
58
|
+
// homeGeoPoint: { latitude: 48.8566, longitude: 2.3522 },
|
|
59
|
+
// homeZoomLevel: 5
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Polygon series (countries/regions)
|
|
64
|
+
const polygonSeries = chart.series.push(
|
|
65
|
+
am5map.MapPolygonSeries.new(root, {
|
|
66
|
+
geoJSON: am5geodata_worldLow,
|
|
67
|
+
exclude: ["AQ"] // exclude Antarctica
|
|
68
|
+
// include: ["US", "CA", "MX"] // show only these
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
chart.appear(1000, 100);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Available projections
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
am5map.geoMercator() // most common, rectangular
|
|
79
|
+
am5map.geoNaturalEarth1() // rounded, good for world maps
|
|
80
|
+
am5map.geoAlbersUsa() // USA with Alaska/Hawaii repositioned
|
|
81
|
+
am5map.geoOrthographic() // globe
|
|
82
|
+
am5map.geoEqualEarth() // equal-area
|
|
83
|
+
am5map.geoEquirectangular() // simple lat/long grid
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Series types
|
|
87
|
+
|
|
88
|
+
### MapPolygonSeries (countries, regions)
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
const polygonSeries = chart.series.push(
|
|
92
|
+
am5map.MapPolygonSeries.new(root, {
|
|
93
|
+
geoJSON: am5geodata_worldLow,
|
|
94
|
+
exclude: ["AQ"],
|
|
95
|
+
valueField: "value", // for choropleth coloring
|
|
96
|
+
calculateAggregates: true // needed for heat rules
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Polygon appearance
|
|
101
|
+
polygonSeries.mapPolygons.template.setAll({
|
|
102
|
+
tooltipText: "{name}",
|
|
103
|
+
interactive: true,
|
|
104
|
+
fill: am5.color(0xdadada),
|
|
105
|
+
strokeWidth: 0.5
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Hover state
|
|
109
|
+
polygonSeries.mapPolygons.template.states.create("hover", {
|
|
110
|
+
fill: am5.color(0x297373)
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Supplement geodata with custom values
|
|
114
|
+
polygonSeries.data.setAll([
|
|
115
|
+
{ id: "US", name: "United States", value: 331 },
|
|
116
|
+
{ id: "CN", name: "China", value: 1411 },
|
|
117
|
+
{ id: "IN", name: "India", value: 1380 }
|
|
118
|
+
]);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Choropleth (heat map) via heat rules
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
polygonSeries.set("heatRules", [{
|
|
125
|
+
target: polygonSeries.mapPolygons.template,
|
|
126
|
+
dataField: "value",
|
|
127
|
+
min: am5.color(0xf7e9b9),
|
|
128
|
+
max: am5.color(0x5a1d6e),
|
|
129
|
+
key: "fill"
|
|
130
|
+
}]);
|
|
131
|
+
|
|
132
|
+
// Heat legend
|
|
133
|
+
const heatLegend = chart.children.push(am5.HeatLegend.new(root, {
|
|
134
|
+
orientation: "horizontal",
|
|
135
|
+
startColor: am5.color(0xf7e9b9),
|
|
136
|
+
endColor: am5.color(0x5a1d6e),
|
|
137
|
+
startText: "Low",
|
|
138
|
+
endText: "High",
|
|
139
|
+
stepCount: 5
|
|
140
|
+
}));
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### MapPointSeries (markers, bubbles, labels)
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
const pointSeries = chart.series.push(
|
|
147
|
+
am5map.MapPointSeries.new(root, {
|
|
148
|
+
latitudeField: "latitude",
|
|
149
|
+
longitudeField: "longitude"
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// Define bullet appearance
|
|
154
|
+
pointSeries.bullets.push(function() {
|
|
155
|
+
return am5.Bullet.new(root, {
|
|
156
|
+
sprite: am5.Circle.new(root, {
|
|
157
|
+
radius: 5,
|
|
158
|
+
fill: am5.color(0xff0000),
|
|
159
|
+
tooltipText: "{name}"
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Add points via data — requires latitudeField/longitudeField on the series
|
|
165
|
+
pointSeries.data.setAll([
|
|
166
|
+
{ latitude: 48.8566, longitude: 2.3522, name: "Paris" },
|
|
167
|
+
{ latitude: 40.7128, longitude: -74.0060, name: "New York" },
|
|
168
|
+
{ latitude: 35.6762, longitude: 139.6503, name: "Tokyo" }
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
// OR: place points at polygon centers using polygonIdField
|
|
172
|
+
const pointSeries2 = chart.series.push(
|
|
173
|
+
am5map.MapPointSeries.new(root, { polygonIdField: "polygonId" })
|
|
174
|
+
);
|
|
175
|
+
pointSeries2.data.setAll([
|
|
176
|
+
{ polygonId: "US", name: "USA" },
|
|
177
|
+
{ polygonId: "FR", name: "France" }
|
|
178
|
+
]);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### MapLineSeries (connections, routes)
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
const lineSeries = chart.series.push(
|
|
185
|
+
am5map.MapLineSeries.new(root, {})
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
lineSeries.mapLines.template.setAll({
|
|
189
|
+
stroke: am5.color(0xff0000),
|
|
190
|
+
strokeWidth: 2,
|
|
191
|
+
strokeOpacity: 0.5
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Using point data items for connections
|
|
195
|
+
const pointSeries = chart.series.push(am5map.MapPointSeries.new(root, {}));
|
|
196
|
+
const nyc = pointSeries.pushDataItem({ latitude: 40.71, longitude: -74.01 });
|
|
197
|
+
const london = pointSeries.pushDataItem({ latitude: 51.47, longitude: -0.45 });
|
|
198
|
+
|
|
199
|
+
lineSeries.pushDataItem({
|
|
200
|
+
pointsToConnect: [nyc, london]
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// OR using GeoJSON geometry
|
|
204
|
+
lineSeries.pushDataItem({
|
|
205
|
+
geometry: {
|
|
206
|
+
type: "LineString",
|
|
207
|
+
coordinates: [[-74.01, 40.71], [-0.45, 51.47]] // [lng, lat] pairs
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Zoom controls
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
chart.set("zoomControl", am5map.ZoomControl.new(root, {}));
|
|
216
|
+
|
|
217
|
+
// Programmatic zoom
|
|
218
|
+
chart.zoomToGeoPoint({ latitude: 48.86, longitude: 2.35 }, 5); // zoom level 5
|
|
219
|
+
|
|
220
|
+
// Zoom to a polygon
|
|
221
|
+
polygonSeries.mapPolygons.template.events.on("click", function(ev) {
|
|
222
|
+
polygonSeries.zoomToDataItem(ev.target.dataItem);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Home button
|
|
226
|
+
chart.chartContainer.children.push(am5.Button.new(root, {
|
|
227
|
+
label: am5.Label.new(root, { text: "Home" })
|
|
228
|
+
})).events.on("click", function() {
|
|
229
|
+
chart.goHome();
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Globe (orthographic projection)
|
|
234
|
+
|
|
235
|
+
```js
|
|
236
|
+
var chart = root.container.children.push(am5map.MapChart.new(root, {
|
|
237
|
+
projection: am5map.geoOrthographic(),
|
|
238
|
+
panX: "rotateX", // drag to rotate horizontally
|
|
239
|
+
panY: "rotateY", // drag to rotate vertically
|
|
240
|
+
rotationX: -70, // initial longitude center
|
|
241
|
+
rotationY: -30 // initial latitude center
|
|
242
|
+
}));
|
|
243
|
+
|
|
244
|
+
// Rotate to a specific country
|
|
245
|
+
chart.animate({ key: "rotationX", to: -2.35, duration: 1500, easing: am5.ease.out(am5.ease.cubic) });
|
|
246
|
+
chart.animate({ key: "rotationY", to: -48.86, duration: 1500, easing: am5.ease.out(am5.ease.cubic) });
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## GraticuleSeries (grid lines / ocean background)
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
// Background (ocean)
|
|
253
|
+
var backgroundSeries = chart.series.unshift(am5map.MapPolygonSeries.new(root, {}));
|
|
254
|
+
backgroundSeries.mapPolygons.template.setAll({
|
|
255
|
+
fill: am5.color(0xddeeff),
|
|
256
|
+
stroke: am5.color(0xddeeff)
|
|
257
|
+
});
|
|
258
|
+
backgroundSeries.data.push({
|
|
259
|
+
geometry: am5map.getGeoRectangle(90, 180, -90, -180) // full globe background
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// Grid lines (graticule)
|
|
263
|
+
chart.series.push(am5map.GraticuleSeries.new(root, {}));
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Drill-down map (country → states)
|
|
267
|
+
|
|
268
|
+
```js
|
|
269
|
+
// World-level polygons
|
|
270
|
+
var worldSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {
|
|
271
|
+
geoJSON: am5geodata_worldLow
|
|
272
|
+
}));
|
|
273
|
+
|
|
274
|
+
// Country-level polygons (initially hidden)
|
|
275
|
+
var countrySeries = chart.series.push(am5map.MapPolygonSeries.new(root, {}));
|
|
276
|
+
|
|
277
|
+
// Click a country to drill down
|
|
278
|
+
worldSeries.mapPolygons.template.events.on("click", function(ev) {
|
|
279
|
+
var country = ev.target.dataItem.dataContext.id; // ISO alpha-2 code, e.g., "US"
|
|
280
|
+
// Load country geodata dynamically
|
|
281
|
+
import("@amcharts/amcharts5-geodata/usaLow").then(function(geodata) {
|
|
282
|
+
countrySeries.set("geoJSON", geodata.default);
|
|
283
|
+
chart.zoomToDataItem(ev.target.dataItem);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Back button
|
|
288
|
+
chart.chartContainer.children.push(am5.Button.new(root, {
|
|
289
|
+
label: am5.Label.new(root, { text: "Back" })
|
|
290
|
+
})).events.on("click", function() {
|
|
291
|
+
countrySeries.set("geoJSON", undefined);
|
|
292
|
+
chart.goHome();
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Additional MapChart settings
|
|
297
|
+
|
|
298
|
+
```js
|
|
299
|
+
am5map.MapChart.new(root, {
|
|
300
|
+
maxZoomLevel: 32, // max zoom
|
|
301
|
+
minZoomLevel: 1, // min zoom
|
|
302
|
+
maxPanOut: 0.4, // how far user can pan beyond map (0-1)
|
|
303
|
+
rotationX: 0, // center longitude
|
|
304
|
+
rotationY: 0, // center latitude
|
|
305
|
+
rotationZ: 0, // tilt
|
|
306
|
+
wheelY: "zoom", // "zoom", "none"
|
|
307
|
+
wheelSensitivity: 1, // zoom speed multiplier
|
|
308
|
+
})
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Polygon IDs** use ISO 3166-1 alpha-2 codes (e.g., `"US"`, `"CN"`, `"DE"`, `"FR"`).
|
|
312
|
+
|
|
313
|
+
## Events on map elements
|
|
314
|
+
|
|
315
|
+
```js
|
|
316
|
+
// Polygon click
|
|
317
|
+
polygonSeries.mapPolygons.template.events.on("click", function(ev) {
|
|
318
|
+
var id = ev.target.dataItem.dataContext.id; // "US", "CN", etc.
|
|
319
|
+
var name = ev.target.dataItem.dataContext.name; // "United States"
|
|
320
|
+
console.log("Clicked:", name, id);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// Point/marker click
|
|
324
|
+
pointSeries.bullets.push(function(root, series, dataItem) {
|
|
325
|
+
var circle = am5.Circle.new(root, { radius: 5, fill: am5.color(0xff0000) });
|
|
326
|
+
circle.events.on("click", function() {
|
|
327
|
+
console.log("Marker:", dataItem.dataContext);
|
|
328
|
+
});
|
|
329
|
+
return am5.Bullet.new(root, { sprite: circle });
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Map zoom — use settings watch, NOT events (there is no "zoomlevelchanged" event)
|
|
333
|
+
chart.on("zoomLevel", function(zoomLevel) {
|
|
334
|
+
console.log("Zoom:", zoomLevel);
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Disposal
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
root.dispose();
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
# amCharts 5 Map Charts — Working Examples
|
|
348
|
+
|
|
349
|
+
## Example 1: World choropleth map
|
|
350
|
+
|
|
351
|
+
```html
|
|
352
|
+
<!DOCTYPE html>
|
|
353
|
+
<html>
|
|
354
|
+
<head>
|
|
355
|
+
<meta charset="UTF-8">
|
|
356
|
+
<title>World Choropleth Map</title>
|
|
357
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
358
|
+
<script src="https://cdn.amcharts.com/lib/5/map.js"></script>
|
|
359
|
+
<script src="https://cdn.amcharts.com/lib/5/geodata/worldLow.js"></script>
|
|
360
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
361
|
+
<style>#chartdiv { width: 100%; height: 500px; }</style>
|
|
362
|
+
</head>
|
|
363
|
+
<body>
|
|
364
|
+
<div id="chartdiv"></div>
|
|
365
|
+
<script>
|
|
366
|
+
var root = am5.Root.new("chartdiv");
|
|
367
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
368
|
+
|
|
369
|
+
var chart = root.container.children.push(am5map.MapChart.new(root, {
|
|
370
|
+
panX: "rotateX",
|
|
371
|
+
panY: "translateY",
|
|
372
|
+
projection: am5map.geoNaturalEarth1()
|
|
373
|
+
}));
|
|
374
|
+
|
|
375
|
+
var polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {
|
|
376
|
+
geoJSON: am5geodata_worldLow,
|
|
377
|
+
exclude: ["AQ"],
|
|
378
|
+
valueField: "value",
|
|
379
|
+
calculateAggregates: true
|
|
380
|
+
}));
|
|
381
|
+
|
|
382
|
+
polygonSeries.mapPolygons.template.setAll({
|
|
383
|
+
tooltipText: "{name}: {value}",
|
|
384
|
+
interactive: true
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
polygonSeries.mapPolygons.template.states.create("hover", {
|
|
388
|
+
fill: am5.color(0x677935)
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Heat rules for choropleth coloring
|
|
392
|
+
polygonSeries.set("heatRules", [{
|
|
393
|
+
target: polygonSeries.mapPolygons.template,
|
|
394
|
+
dataField: "value",
|
|
395
|
+
min: am5.color(0xcee8c0),
|
|
396
|
+
max: am5.color(0x1d6e04),
|
|
397
|
+
key: "fill"
|
|
398
|
+
}]);
|
|
399
|
+
|
|
400
|
+
// Sample data — population in millions
|
|
401
|
+
polygonSeries.data.setAll([
|
|
402
|
+
{ id: "US", value: 331 }, { id: "CN", value: 1411 },
|
|
403
|
+
{ id: "IN", value: 1380 }, { id: "BR", value: 213 },
|
|
404
|
+
{ id: "RU", value: 146 }, { id: "JP", value: 126 },
|
|
405
|
+
{ id: "DE", value: 83 }, { id: "GB", value: 67 },
|
|
406
|
+
{ id: "FR", value: 67 }, { id: "AU", value: 26 }
|
|
407
|
+
]);
|
|
408
|
+
|
|
409
|
+
// Heat legend
|
|
410
|
+
var heatLegend = chart.children.push(am5.HeatLegend.new(root, {
|
|
411
|
+
orientation: "horizontal",
|
|
412
|
+
startColor: am5.color(0xcee8c0),
|
|
413
|
+
endColor: am5.color(0x1d6e04),
|
|
414
|
+
startText: "Low",
|
|
415
|
+
endText: "High",
|
|
416
|
+
stepCount: 5
|
|
417
|
+
}));
|
|
418
|
+
|
|
419
|
+
chart.set("zoomControl", am5map.ZoomControl.new(root, {}));
|
|
420
|
+
chart.appear(1000, 100);
|
|
421
|
+
</script>
|
|
422
|
+
</body>
|
|
423
|
+
</html>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## Example 2: Map with point markers (bubble map)
|
|
427
|
+
|
|
428
|
+
```html
|
|
429
|
+
<!DOCTYPE html>
|
|
430
|
+
<html>
|
|
431
|
+
<head>
|
|
432
|
+
<meta charset="UTF-8">
|
|
433
|
+
<title>Bubble Map</title>
|
|
434
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
435
|
+
<script src="https://cdn.amcharts.com/lib/5/map.js"></script>
|
|
436
|
+
<script src="https://cdn.amcharts.com/lib/5/geodata/worldLow.js"></script>
|
|
437
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
438
|
+
<style>#chartdiv { width: 100%; height: 500px; }</style>
|
|
439
|
+
</head>
|
|
440
|
+
<body>
|
|
441
|
+
<div id="chartdiv"></div>
|
|
442
|
+
<script>
|
|
443
|
+
var root = am5.Root.new("chartdiv");
|
|
444
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
445
|
+
|
|
446
|
+
var chart = root.container.children.push(am5map.MapChart.new(root, {
|
|
447
|
+
panX: "translateX",
|
|
448
|
+
panY: "translateY",
|
|
449
|
+
projection: am5map.geoMercator()
|
|
450
|
+
}));
|
|
451
|
+
|
|
452
|
+
// Background polygons
|
|
453
|
+
var polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {
|
|
454
|
+
geoJSON: am5geodata_worldLow,
|
|
455
|
+
exclude: ["AQ"]
|
|
456
|
+
}));
|
|
457
|
+
polygonSeries.mapPolygons.template.setAll({
|
|
458
|
+
fill: am5.color(0xdddddd),
|
|
459
|
+
strokeWidth: 0.5,
|
|
460
|
+
stroke: am5.color(0xffffff)
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// Point series with scaled bubbles
|
|
464
|
+
var pointSeries = chart.series.push(am5map.MapPointSeries.new(root, {
|
|
465
|
+
latitudeField: "latitude",
|
|
466
|
+
longitudeField: "longitude"
|
|
467
|
+
}));
|
|
468
|
+
|
|
469
|
+
var cities = [
|
|
470
|
+
{ name: "New York", latitude: 40.71, longitude: -74.01, population: 8.3 },
|
|
471
|
+
{ name: "London", latitude: 51.51, longitude: -0.13, population: 9.0 },
|
|
472
|
+
{ name: "Tokyo", latitude: 35.68, longitude: 139.69, population: 13.5 },
|
|
473
|
+
{ name: "Paris", latitude: 48.86, longitude: 2.35, population: 2.2 },
|
|
474
|
+
{ name: "Sydney", latitude: -33.87, longitude: 151.21, population: 5.3 }
|
|
475
|
+
];
|
|
476
|
+
|
|
477
|
+
// Scale bubble size by population
|
|
478
|
+
pointSeries.bullets.push(function(root, series, dataItem) {
|
|
479
|
+
var value = dataItem.dataContext.population;
|
|
480
|
+
return am5.Bullet.new(root, {
|
|
481
|
+
sprite: am5.Circle.new(root, {
|
|
482
|
+
radius: Math.sqrt(value) * 4,
|
|
483
|
+
fill: am5.color(0xff5733),
|
|
484
|
+
fillOpacity: 0.5,
|
|
485
|
+
strokeWidth: 1,
|
|
486
|
+
stroke: am5.color(0xffffff),
|
|
487
|
+
tooltipText: "{name}\nPopulation: {population}M"
|
|
488
|
+
})
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
pointSeries.data.setAll(cities);
|
|
493
|
+
|
|
494
|
+
chart.set("zoomControl", am5map.ZoomControl.new(root, {}));
|
|
495
|
+
chart.appear(1000, 100);
|
|
496
|
+
</script>
|
|
497
|
+
</body>
|
|
498
|
+
</html>
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## Example 3: US map with connection lines
|
|
502
|
+
|
|
503
|
+
```html
|
|
504
|
+
<!DOCTYPE html>
|
|
505
|
+
<html>
|
|
506
|
+
<head>
|
|
507
|
+
<meta charset="UTF-8">
|
|
508
|
+
<title>US Flight Routes</title>
|
|
509
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
510
|
+
<script src="https://cdn.amcharts.com/lib/5/map.js"></script>
|
|
511
|
+
<script src="https://cdn.amcharts.com/lib/5/geodata/usaLow.js"></script>
|
|
512
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
513
|
+
<style>#chartdiv { width: 100%; height: 500px; }</style>
|
|
514
|
+
</head>
|
|
515
|
+
<body>
|
|
516
|
+
<div id="chartdiv"></div>
|
|
517
|
+
<script>
|
|
518
|
+
var root = am5.Root.new("chartdiv");
|
|
519
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
520
|
+
|
|
521
|
+
var chart = root.container.children.push(am5map.MapChart.new(root, {
|
|
522
|
+
panX: "translateX",
|
|
523
|
+
panY: "translateY",
|
|
524
|
+
projection: am5map.geoAlbersUsa()
|
|
525
|
+
}));
|
|
526
|
+
|
|
527
|
+
// State polygons
|
|
528
|
+
var polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {
|
|
529
|
+
geoJSON: am5geodata_usaLow
|
|
530
|
+
}));
|
|
531
|
+
polygonSeries.mapPolygons.template.setAll({
|
|
532
|
+
fill: am5.color(0xdadada),
|
|
533
|
+
stroke: am5.color(0xffffff),
|
|
534
|
+
strokeWidth: 1,
|
|
535
|
+
tooltipText: "{name}"
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// Point series for airports
|
|
539
|
+
var pointSeries = chart.series.push(am5map.MapPointSeries.new(root, {}));
|
|
540
|
+
pointSeries.bullets.push(function() {
|
|
541
|
+
return am5.Bullet.new(root, {
|
|
542
|
+
sprite: am5.Circle.new(root, {
|
|
543
|
+
radius: 4,
|
|
544
|
+
fill: am5.color(0x3355ff),
|
|
545
|
+
stroke: am5.color(0xffffff),
|
|
546
|
+
strokeWidth: 1,
|
|
547
|
+
tooltipText: "{name}"
|
|
548
|
+
})
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
var jfk = pointSeries.pushDataItem({ latitude: 40.64, longitude: -73.78, name: "JFK" });
|
|
553
|
+
var lax = pointSeries.pushDataItem({ latitude: 33.94, longitude: -118.41, name: "LAX" });
|
|
554
|
+
var ord = pointSeries.pushDataItem({ latitude: 41.97, longitude: -87.91, name: "ORD" });
|
|
555
|
+
var atl = pointSeries.pushDataItem({ latitude: 33.64, longitude: -84.43, name: "ATL" });
|
|
556
|
+
|
|
557
|
+
// Line series for routes
|
|
558
|
+
var lineSeries = chart.series.push(am5map.MapLineSeries.new(root, {}));
|
|
559
|
+
lineSeries.mapLines.template.setAll({
|
|
560
|
+
stroke: am5.color(0x3355ff),
|
|
561
|
+
strokeOpacity: 0.6,
|
|
562
|
+
strokeWidth: 2
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
lineSeries.pushDataItem({ pointsToConnect: [jfk, lax] });
|
|
566
|
+
lineSeries.pushDataItem({ pointsToConnect: [jfk, ord] });
|
|
567
|
+
lineSeries.pushDataItem({ pointsToConnect: [ord, atl] });
|
|
568
|
+
lineSeries.pushDataItem({ pointsToConnect: [atl, lax] });
|
|
569
|
+
|
|
570
|
+
chart.appear(1000, 100);
|
|
571
|
+
</script>
|
|
572
|
+
</body>
|
|
573
|
+
</html>
|
|
574
|
+
```
|