import * as am5 from "@amcharts/amcharts5"; import * as am5map from "@amcharts/amcharts5/map"; import am5geodata_worldLow from "@amcharts/amcharts5-geodata/worldLow"; import am5themes_Animated from "@amcharts/amcharts5/themes/Animated"; import am5themes_ResponsiveMax from "@amcharts/amcharts5/themes/ResponsiveMax"; // Create root element // https://docs.amcharts.com/v5/getting-started/#root-element const root = am5.Root.new("chartdiv"); // Set themes // https://docs.amcharts.com/v5/concepts/themes/ root.setThemes([ am5themes_Animated.new(root), am5themes_ResponsiveMax.new(root) // fits the chart to small screens ]); // Create chart: it goes to its home position once it loads // https://docs.amcharts.com/v5/charts/map-chart/map-pan-zoom/#initial-position-and-zoom const chart = root.container.children.push(am5map.MapChart.new(root, { projection: am5map.geoMercator(), // the common flat world map homeGeoPoint: { longitude: 14, latitude: 51 }, // home is centered on central Europe... homeZoomLevel: 3.5, // ...zoomed in 3.5 times, so Europe fills the map autoHome: true // goes there on load, animated by the Animated theme's animationDuration })); // Add zoom control with a home button // https://docs.amcharts.com/v5/charts/map-chart/map-pan-zoom/#zoom-control const zoomControl = chart.set("zoomControl", am5map.ZoomControl.new(root, {})); zoomControl.homeButton.set("visible", true); // hidden by default; a click goes back home // Add countries // https://docs.amcharts.com/v5/charts/map-chart/map-polygon-series/ const polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, { geoJSON: am5geodata_worldLow, exclude: ["AQ"] // no Antarctica, which Mercator stretches across the bottom })); polygonSeries.mapPolygons.template.setAll({ tooltipText: "{name}" // the country's name, which comes with the map data }); // Accessibility: keyboard and screen reader support // https://docs.amcharts.com/v5/concepts/accessibility/ chart.setAll({ focusable: true, // Tab reaches the map, and a screen reader names it ariaLabel: "World map that opens zoomed in on Europe. Tab to the countries, then move between them with the up and down arrow keys" }); // the countries: one Tab stop, the up and down arrow keys step through them polygonSeries.mapPolygons.template.setAll({ focusable: true, focusableGroup: "countries", hoverOnFocus: true, // the focused country shows its tooltip ariaLabel: "{name}" }); // Make stuff animate on load // https://docs.amcharts.com/v5/concepts/animations/#forcing-appearance-animation chart.appear(1000, 100);