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 the map chart // https://docs.amcharts.com/v5/charts/map-chart/ const chart = root.container.children.push(am5map.MapChart.new(root, { panX: "rotateX", // dragging sideways spins the globe... panY: "rotateY", // ...and dragging up or down tilts it projection: am5map.geoOrthographic(), // a globe paddingBottom: 20, // 20 px of room on every side, between the globe and the chart's edges paddingTop: 20, paddingLeft: 20, paddingRight: 20 })); // Create series for background fill // https://docs.amcharts.com/v5/charts/map-chart/map-polygon-series/#background-polygon const backgroundSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {})); backgroundSeries.mapPolygons.template.setAll({ fill: root.interfaceColors.get("alternativeBackground"), // black on a light theme... fillOpacity: 0.1, // ...faded to a light grey disc for the sea strokeOpacity: 0 // no outline }); backgroundSeries.data.push({ geometry: am5map.getGeoRectangle(90, 180, -90, -180) // one polygon over the whole earth }); // Create main polygon series for countries. clickZoom zooms to the clicked // country; on a map that pans by rotating, it turns the globe to it as well // https://docs.amcharts.com/v5/charts/map-chart/map-polygon-series/ const polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, { geoJSON: am5geodata_worldLow, clickZoom: true // a second click on the country, or one on the water, zooms back out })); polygonSeries.mapPolygons.template.setAll({ tooltipText: "{name}", // the country's name, which comes with the map data interactive: true // the countries react to the pointer: hover and click }); // the country under the pointer takes the theme's hover color polygonSeries.mapPolygons.template.states.create("hover", { fill: root.interfaceColors.get("primaryButtonHover") }); // The country zoomed to is active polygonSeries.mapPolygons.template.states.create("active", { fill: root.interfaceColors.get("primaryButtonActive") // green in the default theme }); // Accessibility: keyboard and screen reader support // https://docs.amcharts.com/v5/concepts/accessibility/ chart.setAll({ focusable: true, // Tab reaches the globe, and a screen reader names it ariaLabel: "Globe of the world's countries. Tab to the countries, move between them with the up and down arrow keys, and press Enter to turn the globe to one and zoom in, or back out" }); // 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);