A word cloud of whole phrases, each in its own colored box and sized by how often it comes up. Here, what a café’s customers say most in their reviews.
Single words lose their meaning out of context: "line" or "loud" say little alone. Short phrases keep it, and their boxes make each one easy to pick out. It works for a handful of phrases, such as the themes found in reviews or a survey.
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 element
// https://www.amcharts.com/docs/v5/getting-started/#Root_element
var root = am5.Root.new("chartdiv");
// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root.setThemes([
am5themes_Animated.new(root),
am5themes_Responsive.new(root)
]);
// Add series
// https://www.amcharts.com/docs/v5/charts/word-cloud/
var chart = root.container.children.push(am5.SerialChartContainer.new(root, {}));
var series = chart.series.push(am5wc.WordCloud.new(root, {
minFontSize: am5.percent(6), // the smallest text: 6% of the chart's shorter side...
maxFontSize: am5.percent(8), // ...the biggest 8%, so even the longest sentences fit
// every sentence stays horizontal
angles: [0],
// pack whole boxes, so a sentence's colored box never slides into the gaps of another
allowNesting: false
}));
var colorSet = am5.ColorSet.new(root, { step: 1 }); // a color set that hands out its colors one by one
// Configure labels
series.labels.template.setAll({
paddingTop: 5, // 5px of colored box around the text on each side
paddingBottom: 5,
paddingLeft: 5,
paddingRight: 5,
fontFamily: "Courier New", // a typewriter font
tooltipText: "Said in {value} reviews" // hover a sentence for how many reviews said it
});
// setup runs once for each new label: it gets a box in the next color of the set
series.labels.template.setup = function(label) {
label.set("background", am5.RoundedRectangle.new(root, { fillOpacity: 1, fill: colorSet.next() }))
}
// What a café's customers say in their reviews, and in how many: the more often, the bigger
series.data.setAll([
{ category: "Best flat white\nin town", value: 64 },
{ category: "Friendly staff\nwho remember\nyour order", value: 52 },
{ category: "Long line on\nweekend mornings", value: 47 },
{ category: "Pastries sell out\nby noon", value: 45 },
{ category: "Cozy corner\nto work in", value: 38 },
{ category: "Great place\nto meet friends", value: 36 },
{ category: "Fair prices", value: 31 },
{ category: "Music a bit\ntoo loud", value: 27 }
]);
{
"type": "SerialChartContainer",
"properties": {
"series": [
"#series-0"
]
},
"refs": [
{
"data-0": [
{
"category": "Best flat white\nin town",
"value": 64
},
{
"category": "Friendly staff\nwho remember\nyour order",
"value": 52
},
{
"category": "Long line on\nweekend mornings",
"value": 47
},
{
"category": "Pastries sell out\nby noon",
"value": 45
},
{
"category": "Cozy corner\nto work in",
"value": 38
},
{
"category": "Great place\nto meet friends",
"value": 36
},
{
"category": "Fair prices",
"value": 31
},
{
"category": "Music a bit\ntoo loud",
"value": 27
}
]
},
{
"series-0": {
"type": "WordCloud",
"settings": {
"minFontSize": {
"type": "Percent",
"value": 6
},
"maxFontSize": {
"type": "Percent",
"value": 8
},
"angles": [
0
],
"allowNesting": false
},
"properties": {
"data": "#data-0",
"labels": {
"properties": {
"template": {
"settings": {
"paddingTop": 5,
"paddingBottom": 5,
"paddingLeft": 5,
"paddingRight": 5,
"fontFamily": "Courier New",
"tooltipText": "Said in {value} reviews"
}
}
}
}
}
}
}
]
}