A bar chart split into groups along its axis: sales in the 48 mainland states and DC, grouped into four regions. Each region has its own color and its name on a line across the axis.
Grouping the bars by region, and sorting them within each group, answers two questions at once: which states sell most, and how the regions compare. The lines across the axis keep each group together, even where the colors are hard to tell apart. With values this uneven, a log scale shows the small states a plain scale squashes.
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)
]);
// Create chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/
var chart = root.container.children.push(am5xy.XYChart.new(root, {
panX: false, // no dragging to pan...
panY: false, // ...in either direction...
wheelX: "none", // ...and no wheel zooming...
wheelY: "none", // ...at all
layout: root.verticalLayout, // the legend and the plot stacked top to bottom
paddingLeft: 0, // the state names sit at the chart's left edge
paddingRight: 25 // room for the last sales label, centered on the axis end
}));
// Add legend above the chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/legend-xy-series/
var legendData = []; // filled by createRange() below
var legend = chart.children.unshift(
// a legend of plain data (names and colors), not series; its items don't react to clicks
am5.Legend.new(root, {
nameField: "name", // item names from the data's name field...
fillField: "color", // ...and marker colors from its color field
strokeField: "color",
centerX: am5.p50, // the legend's middle...
x: am5.p50, // ...at the middle of the chart's width
marginBottom: 15, // 15px above the plot
clickTarget: "none"
})
);
var data = [{
region: "Central",
state: "North Dakota",
sales: 920
}, {
region: "Central",
state: "South Dakota",
sales: 1317
}, {
region: "Central",
state: "Kansas",
sales: 2916
}, {
region: "Central",
state: "Iowa",
sales: 4577
}, {
region: "Central",
state: "Nebraska",
sales: 7464
}, {
region: "Central",
state: "Oklahoma",
sales: 19686
}, {
region: "Central",
state: "Missouri",
sales: 22207
}, {
region: "Central",
state: "Minnesota",
sales: 29865
}, {
region: "Central",
state: "Wisconsin",
sales: 32125
}, {
region: "Central",
state: "Indiana",
sales: 53549
}, {
region: "Central",
state: "Michigan",
sales: 76281
}, {
region: "Central",
state: "Illinois",
sales: 80162
}, {
region: "Central",
state: "Texas",
sales: 170187
}, {
region: "East",
state: "West Virginia",
sales: 1209
}, {
region: "East",
state: "Maine",
sales: 1270
}, {
region: "East",
state: "District of Columbia",
sales: 2866
}, {
region: "East",
state: "New Hampshire",
sales: 7294
}, {
region: "East",
state: "Vermont",
sales: 8929
}, {
region: "East",
state: "Connecticut",
sales: 13386
}, {
region: "East",
state: "Rhode Island",
sales: 22629
}, {
region: "East",
state: "Maryland",
sales: 23707
}, {
region: "East",
state: "Delaware",
sales: 27453
}, {
region: "East",
state: "Massachusetts",
sales: 28639
}, {
region: "East",
state: "New Jersey",
sales: 35763
}, {
region: "East",
state: "Ohio",
sales: 78253
}, {
region: "East",
state: "Pennsylvania",
sales: 116522
}, {
region: "East",
state: "New York",
sales: 310914
}, {
region: "South",
state: "South Carolina",
sales: 8483
}, {
region: "South",
state: "Louisiana",
sales: 9219
}, {
region: "South",
state: "Mississippi",
sales: 10772
}, {
region: "South",
state: "Arkansas",
sales: 11678
}, {
region: "South",
state: "Alabama",
sales: 19511
}, {
region: "South",
state: "Tennessee",
sales: 30662
}, {
region: "South",
state: "Kentucky",
sales: 36598
}, {
region: "South",
state: "Georgia",
sales: 49103
}, {
region: "South",
state: "North Carolina",
sales: 55604
}, {
region: "South",
state: "Virginia",
sales: 70641
}, {
region: "South",
state: "Florida",
sales: 89479
}, {
region: "West",
state: "Wyoming",
sales: 1603
}, {
region: "West",
state: "Idaho",
sales: 4380
}, {
region: "West",
state: "New Mexico",
sales: 4779
}, {
region: "West",
state: "Montana",
sales: 5589
}, {
region: "West",
state: "Utah",
sales: 11223
}, {
region: "West",
state: "Nevada",
sales: 16729
}, {
region: "West",
state: "Oregon",
sales: 17431
}, {
region: "West",
state: "Colorado",
sales: 32110
}, {
region: "West",
state: "Arizona",
sales: 35283
}, {
region: "West",
state: "Washington",
sales: 138656
}, {
region: "West",
state: "California",
sales: 457731
}];
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var yAxis = chart.yAxes.push(am5xy.CategoryAxis.new(root, {
categoryField: "state",
renderer: am5xy.AxisRendererY.new(root, {
minGridDistance: 10, // labels as close as 10px apart, so every state fits
minorGridEnabled: true // fainter grid lines between the labeled ones
}),
tooltip: am5.Tooltip.new(root, {}) // a state label follows the cursor along the axis
}));
yAxis.get("renderer").labels.template.setAll({
fontSize: 12, // small labels...
location: 0.5 // ...in the middle of each state's row
})
yAxis.data.setAll(data);
var xAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, {
renderer: am5xy.AxisRendererX.new(root, {}),
tooltip: am5.Tooltip.new(root, {}) // a sales label follows the cursor along the axis
}));
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
var series = chart.series.push(am5xy.ColumnSeries.new(root, {
xAxis: xAxis,
yAxis: yAxis,
valueXField: "sales",
categoryYField: "state",
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal" // the tooltip sits beside the bar
})
}));
series.columns.template.setAll({
tooltipText: "{categoryY}: [bold]{valueX}[/]", // the state and its sales on hover
height: am5.percent(80), // each bar fills 80% of its row
strokeOpacity: 0, // no outline
templateField: "columnSettings" // the fill color from the data's columnSettings
});
// Each bar takes its region's color, through the columnSettings field in its data
var regionColors = {
Central: chart.get("colors").getIndex(0),
East: chart.get("colors").getIndex(1),
South: chart.get("colors").getIndex(2),
West: chart.get("colors").getIndex(3)
};
am5.array.each(data, function(item) {
item.columnSettings = { fill: regionColors[item.region] };
});
series.data.setAll(data);
// a line after a region's last state, with a tick and the region's name 130px out to the left
function createRange(label, category, color) {
var rangeDataItem = yAxis.makeDataItem({
category: category // the region's last state
});
var range = yAxis.createAxisRange(rangeDataItem);
rangeDataItem.get("label").setAll({
fill: color, // in the region's color...
text: label,
location: 1, // ...at the far edge of the state's row...
fontWeight: "bold", // ...in bold...
dx: -130 // ...130px out to the left
});
rangeDataItem.get("grid").setAll({
stroke: color, // a solid line in the region's color...
strokeOpacity: 1,
location: 1 // ...on the edge between the regions
});
rangeDataItem.get("tick").setAll({
stroke: color, // a tick in the region's color...
strokeOpacity: 1,
location: 1,
visible: true, // ...shown (ticks are hidden by default)...
length: 130 // ...130px long, out to the region's name
});
legendData.push({ name: label, color: color }); // a legend item for the region
}
createRange("Central", "Texas", regionColors.Central);
createRange("East", "New York", regionColors.East);
createRange("South", "Florida", regionColors.South);
createRange("West", "California", regionColors.West);
legend.data.setAll(legendData);
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
xAxis: xAxis,
yAxis: yAxis // the cursor snaps to the states
}));
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series.appear();
chart.appear(1000, 100);
{
"type": "XYChart",
"settings": {
"panX": false,
"panY": false,
"wheelX": "none",
"wheelY": "none",
"layout": {
"type": "VerticalLayout"
},
"paddingLeft": 0,
"paddingRight": 25,
"cursor": {
"type": "XYCursor",
"settings": {
"xAxis": "#axis-0",
"yAxis": "#axis-1"
}
}
},
"properties": {
"series": [
"#series-0"
],
"xAxes": [
"#axis-0"
],
"yAxes": [
"#axis-1"
]
},
"children": [
{
"type": "Legend",
"settings": {
"nameField": "name",
"fillField": "color",
"strokeField": "color",
"centerX": {
"type": "Percent",
"value": 50
},
"x": {
"type": "Percent",
"value": 50
},
"marginBottom": 15,
"clickTarget": "none"
},
"properties": {
"data": [
{
"name": "Central",
"color": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
{
"name": "East",
"color": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
{
"name": "South",
"color": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
{
"name": "West",
"color": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
}
]
},
"index": 0
}
],
"refs": [
{
"data-0": [
{
"region": "Central",
"state": "North Dakota",
"sales": 920,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "South Dakota",
"sales": 1317,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Kansas",
"sales": 2916,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Iowa",
"sales": 4577,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Nebraska",
"sales": 7464,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Oklahoma",
"sales": 19686,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Missouri",
"sales": 22207,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Minnesota",
"sales": 29865,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Wisconsin",
"sales": 32125,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Indiana",
"sales": 53549,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Michigan",
"sales": 76281,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Illinois",
"sales": 80162,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "Central",
"state": "Texas",
"sales": 170187,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "West Virginia",
"sales": 1209,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Maine",
"sales": 1270,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "District of Columbia",
"sales": 2866,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "New Hampshire",
"sales": 7294,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Vermont",
"sales": 8929,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Connecticut",
"sales": 13386,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Rhode Island",
"sales": 22629,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Maryland",
"sales": 23707,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Delaware",
"sales": 27453,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Massachusetts",
"sales": 28639,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "New Jersey",
"sales": 35763,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Ohio",
"sales": 78253,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "Pennsylvania",
"sales": 116522,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "East",
"state": "New York",
"sales": 310914,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6794dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "South Carolina",
"sales": 8483,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Louisiana",
"sales": 9219,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Mississippi",
"sales": 10772,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Arkansas",
"sales": 11678,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Alabama",
"sales": 19511,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Tennessee",
"sales": 30662,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Kentucky",
"sales": 36598,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Georgia",
"sales": 49103,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "North Carolina",
"sales": 55604,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Virginia",
"sales": 70641,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "South",
"state": "Florida",
"sales": 89479,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#6771dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Wyoming",
"sales": 1603,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Idaho",
"sales": 4380,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "New Mexico",
"sales": 4779,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Montana",
"sales": 5589,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Utah",
"sales": 11223,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Nevada",
"sales": 16729,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Oregon",
"sales": 17431,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Colorado",
"sales": 32110,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Arizona",
"sales": 35283,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "Washington",
"sales": 138656,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
},
{
"region": "West",
"state": "California",
"sales": 457731,
"columnSettings": {
"fill": {
"type": "Color",
"value": "#8067dc"
},
"__parse": true
},
"__parse": true
}
]
},
{
"axis-0": {
"type": "ValueAxis",
"settings": {
"renderer": {
"type": "AxisRendererX"
},
"tooltip": {
"type": "Tooltip"
}
}
}
},
{
"axis-1": {
"type": "CategoryAxis",
"settings": {
"categoryField": "state",
"renderer": {
"type": "AxisRendererY",
"settings": {
"minGridDistance": 10,
"minorGridEnabled": true
},
"properties": {
"labels": {
"properties": {
"template": {
"settings": {
"fontSize": 12,
"location": 0.5
}
}
}
}
}
},
"tooltip": {
"type": "Tooltip"
}
},
"properties": {
"data": "#data-0"
}
}
},
{
"series-0": {
"type": "ColumnSeries",
"settings": {
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueXField": "sales",
"categoryYField": "state",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal"
}
}
},
"properties": {
"data": "#data-0",
"columns": {
"properties": {
"template": {
"settings": {
"tooltipText": "{categoryY}: [bold]{valueX}[/]",
"height": {
"type": "Percent",
"value": 80
},
"strokeOpacity": 0,
"templateField": "columnSettings"
}
}
}
}
}
}
},
{
"axisRange-0": {
"axis": "#axis-1",
"settings": {
"category": "Texas",
"label": {
"type": "AxisLabel",
"settings": {
"location": 1,
"text": "Central",
"fill": {
"type": "Color",
"value": "#67b7dc"
},
"fontWeight": "bold",
"dx": -130
}
},
"grid": {
"type": "Grid",
"settings": {
"location": 1,
"strokeOpacity": 1,
"stroke": {
"type": "Color",
"value": "#67b7dc"
}
}
},
"tick": {
"type": "AxisTick",
"settings": {
"location": 1,
"strokeOpacity": 1,
"visible": true,
"stroke": {
"type": "Color",
"value": "#67b7dc"
},
"length": 130
}
}
},
"__parseLogic": "axisRange"
}
},
{
"axisRange-1": {
"axis": "#axis-1",
"settings": {
"category": "New York",
"label": {
"type": "AxisLabel",
"settings": {
"location": 1,
"text": "East",
"fill": {
"type": "Color",
"value": "#6794dc"
},
"fontWeight": "bold",
"dx": -130
}
},
"grid": {
"type": "Grid",
"settings": {
"location": 1,
"strokeOpacity": 1,
"stroke": {
"type": "Color",
"value": "#6794dc"
}
}
},
"tick": {
"type": "AxisTick",
"settings": {
"location": 1,
"strokeOpacity": 1,
"visible": true,
"stroke": {
"type": "Color",
"value": "#6794dc"
},
"length": 130
}
}
},
"__parseLogic": "axisRange"
}
},
{
"axisRange-2": {
"axis": "#axis-1",
"settings": {
"category": "Florida",
"label": {
"type": "AxisLabel",
"settings": {
"location": 1,
"text": "South",
"fill": {
"type": "Color",
"value": "#6771dc"
},
"fontWeight": "bold",
"dx": -130
}
},
"grid": {
"type": "Grid",
"settings": {
"location": 1,
"strokeOpacity": 1,
"stroke": {
"type": "Color",
"value": "#6771dc"
}
}
},
"tick": {
"type": "AxisTick",
"settings": {
"location": 1,
"strokeOpacity": 1,
"visible": true,
"stroke": {
"type": "Color",
"value": "#6771dc"
},
"length": 130
}
}
},
"__parseLogic": "axisRange"
}
},
{
"axisRange-3": {
"axis": "#axis-1",
"settings": {
"category": "California",
"label": {
"type": "AxisLabel",
"settings": {
"location": 1,
"text": "West",
"fill": {
"type": "Color",
"value": "#8067dc"
},
"fontWeight": "bold",
"dx": -130
}
},
"grid": {
"type": "Grid",
"settings": {
"location": 1,
"strokeOpacity": 1,
"stroke": {
"type": "Color",
"value": "#8067dc"
}
}
},
"tick": {
"type": "AxisTick",
"settings": {
"location": 1,
"strokeOpacity": 1,
"visible": true,
"stroke": {
"type": "Color",
"value": "#8067dc"
},
"length": 130
}
}
},
"__parseLogic": "axisRange"
}
}
]
}