A Venn diagram with four circles for coffee’s ingredients, and the drinks where they overlap: espresso and milk make a flat white, espresso and water an Americano, espresso, milk and foam a cappuccino or a latte.
A Venn diagram with several circles shows which combinations exist, not just how two groups overlap: here, which ingredients make which drink. Up to four circles stay readable; beyond that, some overlaps can’t be drawn with circles at all.
Built with amCharts 5, a JavaScript library. The JavaScript includes your theme and renderer (canvas or SVG); the JSON also follows the changes you make with the controls.
npm install @amcharts/amcharts5. See Getting started.
The same chart as a JSON config. Chart Maker reads and writes this format, the library's JSON parser turns it into a chart, and the <am5-chart> element puts it on a page with no code."type" is the class to create and "settings" what you would pass to its new() in code; "properties" fill in its parts, lists such as series and axes or templates such as columns.template; "refs" holds objects used in more than one place ("#series-0" stands for the one named series-0); a string starting with "@" takes a value from another object, such as "@series.get('fill')".
A complete page. Save it as an .html file and open it in a browser.
Paste this into an AI coding assistant to build the chart from scratch. More in amCharts & AI.
// Create root and chart
var root = am5.Root.new("chartdiv");
root.setThemes([
am5themes_Animated.new(root),
am5themes_Responsive.new(root)
]);
// Create wrapper container
var chart = root.container.children.push(
am5.SerialChartContainer.new(root, {
width: am5.p100, // the container fills the whole chart area
height: am5.p100,
layout: root.verticalLayout
})
);
// Create venn series
var series = chart.series.push(
am5venn.Venn.new(root, {
categoryField: "name",
valueField: "value",
// a row with a "sets" list is the overlap of the circles it names
intersectionsField: "sets",
paddingTop: 40, // 40px of room around the circles
paddingBottom: 40,
paddingLeft: 40,
paddingRight: 40
})
);
// Set tooltip content. The outlines are in the background color, but hidden: the areas meet edge to edge
series.slices.template.setAll({
tooltipText: "{category}", // the area's name
stroke: root.interfaceColors.get("background"),
strokeWidth: 3,
strokeOpacity: 0,
templateField: "sliceSettings" // each area's fill from its sliceSettings
});
// Dark labels on the light areas, white on espresso (in labelSettings), whatever the theme
series.labels.template.setAll({
textAlign: "center", // two-line names centered
fill: am5.color(0x2b1a10),
templateField: "labelSettings" // a label color from labelSettings, where a row has one
});
// Set up hover appearance: a dashed outline in a color that shows on the light areas and on espresso
series.hoverGraphics.setAll({
strokeDasharray: [3, 3],
stroke: am5.color(0xe8743b),
strokeWidth: 3
});
// Set data
series.data.setAll([
{ name: "Milk", value: 10, sliceSettings: { fill: am5.color(0xcecbc6) } },
{ name: "Milk foam", value: 10, sliceSettings: { fill: am5.color(0xd1d0ce) } },
{ name: "Espresso", value: 20, sliceSettings: { fill: am5.color(0x441702) }, labelSettings: { fill: am5.color(0xffffff) } },
{ name: "Water", value: 8, sliceSettings: { fill: am5.color(0xbbcdd7) } },
// milk and foam alone make no drink: no label and no tooltip for their overlap
{ name: "", value: 2, sets: ["Milk", "Milk foam"], sliceSettings: { fill: am5.color(0xd2d2d2), tooltipText: "" } },
{ name: "Flat white", value: 4, sets: ["Milk", "Espresso"], sliceSettings: { fill: am5.color(0xa18b80) } },
{ name: "Macchiato", value: 4, sets: ["Milk foam", "Espresso"], sliceSettings: { fill: am5.color(0xaba09c) } },
{ name: "Cappuccino\nLatte", value: 2, sets: ["Milk", "Milk foam", "Espresso"], sliceSettings: { fill: am5.color(0xd1d0ce) } },
{ name: "Americano", value: 4, sets: ["Water", "Espresso"], sliceSettings: { fill: am5.color(0xa2a19f) } }
]);
{
"type": "SerialChartContainer",
"settings": {
"width": {
"type": "Percent",
"value": 100
},
"height": {
"type": "Percent",
"value": 100
},
"layout": {
"type": "VerticalLayout"
}
},
"properties": {
"series": [
"#series-0"
]
},
"refs": [
{
"data-0": [
{
"name": "Milk",
"value": 10,
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#cecbc6"
},
"__parse": true
},
"__parse": true
},
{
"name": "Milk foam",
"value": 10,
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#d1d0ce"
},
"__parse": true
},
"__parse": true
},
{
"name": "Espresso",
"value": 20,
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#441702"
},
"__parse": true
},
"labelSettings": {
"fill": {
"type": "Color",
"value": "#ffffff"
},
"__parse": true
},
"__parse": true
},
{
"name": "Water",
"value": 8,
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#bbcdd7"
},
"__parse": true
},
"__parse": true
},
{
"name": "",
"value": 2,
"sets": [
"Milk",
"Milk foam"
],
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#d2d2d2"
},
"tooltipText": "",
"__parse": true
},
"__parse": true
},
{
"name": "Flat white",
"value": 4,
"sets": [
"Milk",
"Espresso"
],
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#a18b80"
},
"__parse": true
},
"__parse": true
},
{
"name": "Macchiato",
"value": 4,
"sets": [
"Milk foam",
"Espresso"
],
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#aba09c"
},
"__parse": true
},
"__parse": true
},
{
"name": "Cappuccino\nLatte",
"value": 2,
"sets": [
"Milk",
"Milk foam",
"Espresso"
],
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#d1d0ce"
},
"__parse": true
},
"__parse": true
},
{
"name": "Americano",
"value": 4,
"sets": [
"Water",
"Espresso"
],
"sliceSettings": {
"fill": {
"type": "Color",
"value": "#a2a19f"
},
"__parse": true
},
"__parse": true
}
]
},
{
"series-0": {
"type": "Venn",
"settings": {
"categoryField": "name",
"valueField": "value",
"intersectionsField": "sets",
"paddingTop": 40,
"paddingBottom": 40,
"paddingLeft": 40,
"paddingRight": 40
},
"properties": {
"data": "#data-0",
"slices": {
"properties": {
"template": {
"settings": {
"tooltipText": "{category}",
"stroke": "@root.interfaceColors.get('background')",
"strokeWidth": 3,
"strokeOpacity": 0,
"templateField": "sliceSettings"
}
}
}
},
"labels": {
"properties": {
"template": {
"settings": {
"textAlign": "center",
"fill": {
"type": "Color",
"value": "#2b1a10"
},
"templateField": "labelSettings"
}
}
}
}
}
}
}
]
}