import * as am5 from "@amcharts/amcharts5"; import * as am5venn from "@amcharts/amcharts5/venn"; 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 wrapper container // https://docs.amcharts.com/v5/charts/venn/#additional-controls const container = root.container.children.push(am5.Container.new(root, { width: am5.p100, // fills the chart div height: am5.p100, layout: root.verticalLayout // the diagram on top, the legend below it })); // Create series // https://docs.amcharts.com/v5/charts/venn/#venn-series const series = container.children.push(am5venn.Venn.new(root, { categoryField: "name", valueField: "value", intersectionsField: "sets", paddingTop: 40, // 40 px of room around the circles on every side paddingBottom: 40, paddingLeft: 40, paddingRight: 40 })); // Set tooltip content // https://docs.amcharts.com/v5/charts/venn/#tooltips series.slices.template.set("tooltipText", "{category}: {value}"); // Set up hover appearance // https://docs.amcharts.com/v5/charts/venn/#hovers // hoverGraphics is drawn over the hovered circle or overlap, outlining its exact shape series.hoverGraphics.setAll({ strokeDasharray: [3, 3], // dashed: 3 px dash, 3 px gap stroke: root.interfaceColors.get("background"), // the page color, so it shows on the fills strokeWidth: 2 }); // Set data: an item with sets is the intersection of those circles // https://docs.amcharts.com/v5/charts/venn/#setting-data // the values set the circles' areas and, as near as the layout can, the overlaps' series.data.setAll([ { name: "A", value: 10 }, { name: "B", value: 10 }, { name: "C", value: 5 }, { name: "X", value: 4, sets: ["A", "B"] }, { name: "Y", value: 2, sets: ["A", "C"] }, { name: "Z", value: 2, sets: ["B", "C"] }, { name: "Q", value: 1, sets: ["A", "B", "C"] } ]); // Add legend // https://docs.amcharts.com/v5/charts/venn/#legend const legend = container.children.push(am5.Legend.new(root, { centerX: am5.p50, // centered under the diagram x: am5.p50 })); legend.data.setAll(series.dataItems); // Accessibility: keyboard and screen reader support // https://docs.amcharts.com/v5/concepts/accessibility/ container.setAll({ focusable: true, // Tab reaches the diagram, and a screen reader names it ariaLabel: "Venn diagram of three sets, A, B and C, and their overlaps X, Y, Z and Q, each area sized by its value. Tab to the areas, then move between them with the up and down arrow keys" }); // the circles and overlaps: one Tab stop, the up and down arrow keys step through them series.slices.template.setAll({ focusable: true, focusableGroup: "areas", hoverOnFocus: true, // the focused area shows its tooltip ariaLabel: "{category}: {value}" }); // the legend: one Tab stop, after the areas legend.itemContainers.template.setAll({ focusableGroup: "legend", tabindexOrder: 10 // focus runs from low to high (0 if not set) }); // Play initial series animation // https://docs.amcharts.com/v5/concepts/animations/#animation-of-series series.appear(1000, 100);