A stacked area chart with soft curves and a grain texture: cars, motorcycles and bicycles from 2014 to 2025. Each layer’s thickness is its value.
Stacking shows two things at once: how the total moves, and what it is made of. It reads best with the largest, steadiest layer at the bottom, as cars are here. The layers above ride on everything below them, so their own ups and downs are harder to judge.
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, {
// a drag zooms (the cursor's behavior), so the chart itself doesn't pan
panX: false,
panY: false,
wheelX: "panX", // a horizontal wheel or trackpad swipe pans...
wheelY: "zoomX", // ...and the vertical wheel zooms in on the years
pinchZoomX: true // pinch to zoom the years on a touch screen
}));
// every second color of the theme, so the layers next to each other differ more
chart.get("colors").set("step", 2);
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
// drag across the plot to zoom in on those years
behavior: "zoomX"
}));
cursor.lineY.set("visible", false); // no horizontal cursor line, only the vertical one
// Add scrollbar
// https://www.amcharts.com/docs/v5/charts/xy-chart/scrollbars/
chart.set("scrollbarX", am5.Scrollbar.new(root, { orientation: "horizontal" }));
// The data
var data = [{
"year": "2014",
"cars": 1298,
"motorcycles": 680,
"bicycles": 101
}, {
"year": "2015",
"cars": 1275,
"motorcycles": 664,
"bicycles": 97
}, {
"year": "2016",
"cars": 1246,
"motorcycles": 648,
"bicycles": 93
}, {
"year": "2017",
"cars": 1318,
"motorcycles": 697,
"bicycles": 111
}, {
"year": "2018",
"cars": 1213,
"motorcycles": 633,
"bicycles": 87
}, {
"year": "2019",
"cars": 1199,
"motorcycles": 521,
"bicycles": 145
}, {
"year": "2020",
"cars": 1110,
"motorcycles": 310,
"bicycles": 91
}, {
"year": "2021",
"cars": 1165,
"motorcycles": 425,
"bicycles": 120
}, {
"year": "2022",
"cars": 1145,
"motorcycles": 319,
"bicycles": 102
}, {
"year": "2023",
"cars": 1163,
"motorcycles": 201,
"bicycles": 145
}, {
"year": "2024",
"cars": 1180,
"motorcycles": 285,
"bicycles": 100
}, {
"year": "2025",
"cars": 1159,
"motorcycles": 255,
"bicycles": 122
}];
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
categoryField: "year",
// the axis starts and ends in the middle of the first and last year, so no half cells stay empty
startLocation: 0.5,
endLocation: 0.5,
renderer: am5xy.AxisRendererX.new(root, {
minorGridEnabled: true, // fainter grid lines between the labeled years
minGridDistance: 70 // at least 70px between the labels
}),
tooltip: am5.Tooltip.new(root, {}) // shows the cursor's year on the axis
}));
xAxis.data.setAll(data);
var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
// Start at zero, so each layer's thickness shows its true value
min: 0,
renderer: am5xy.AxisRendererY.new(root, {})
}));
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
// adds one smoothed layer for a field of the data
function createSeries(name, field) {
var series = chart.series.push(am5xy.SmoothedXLineSeries.new(root, {
name: name,
xAxis: xAxis,
yAxis: yAxis,
valueYField: field,
categoryXField: "year",
stacked: true, // the main trick: each layer sits on top of the ones before it
// borders in the background color part the layers in light and dark mode
stroke: root.interfaceColors.get("background"),
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal", // the tooltip points sideways at the layer
labelText: "[bold]{name}[/]\n{categoryX}: {valueY}" // the layer's name, then the year and its value
})
}));
series.strokes.template.setAll({
strokeWidth: 4, // 4px borders...
strokeOpacity: 1, // ...fully opaque
shadowBlur: 2, // a soft shadow...
shadowOffsetX: 2, // ...2px to the right...
shadowOffsetY: 2, // ...and 2px down...
shadowColor: am5.color(0x000000), // ...in black...
shadowOpacity: 0.1 // ...at 10% opacity
})
series.fills.template.setAll({
fillOpacity: 1, // a solid fill...
visible: true, // ...turned on: line series have none by default
// a faint grain texture of dark and light specks over the fill
fillPattern: am5.GrainPattern.new(root, {
maxOpacity: 0.15, // each speck at most 15% opaque...
density: 0.5, // ...on about half of the pixels
// each speck takes a random color from the list: two dark specks for every light one
colors: [am5.color(0x000000), am5.color(0x000000), am5.color(0xffffff)]
})
});
series.data.setAll(data);
series.appear(1000);
}
createSeries("Cars", "cars");
createSeries("Motorcycles", "motorcycles");
createSeries("Bicycles", "bicycles");
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
chart.appear(1000, 100);
{
"type": "XYChart",
"settings": {
"panX": false,
"panY": false,
"wheelX": "panX",
"wheelY": "zoomX",
"pinchZoomX": true,
"cursor": {
"type": "XYCursor",
"settings": {
"behavior": "zoomX"
},
"properties": {
"lineY": {
"settings": {
"visible": false
}
}
}
},
"scrollbarX": {
"type": "Scrollbar",
"settings": {
"orientation": "horizontal"
}
},
"colors": {
"type": "ColorSet",
"settings": {
"step": 2,
"passOptions": {
"hue": 0.05,
"saturation": 0,
"lightness": 0
},
"colors": [
{
"type": "Color",
"value": "#67b7dc"
},
{
"type": "Color",
"value": "#6794dc"
},
{
"type": "Color",
"value": "#6771dc"
},
{
"type": "Color",
"value": "#8067dc"
},
{
"type": "Color",
"value": "#a367dc"
}
],
"reuse": false,
"startIndex": 0,
"stateAnimationDuration": 600
}
}
},
"properties": {
"series": [
"#series-0",
"#series-1",
"#series-2"
],
"xAxes": [
"#axis-0"
],
"yAxes": [
"#axis-1"
]
},
"refs": [
{
"data-0": [
{
"year": "2014",
"cars": 1298,
"motorcycles": 680,
"bicycles": 101
},
{
"year": "2015",
"cars": 1275,
"motorcycles": 664,
"bicycles": 97
},
{
"year": "2016",
"cars": 1246,
"motorcycles": 648,
"bicycles": 93
},
{
"year": "2017",
"cars": 1318,
"motorcycles": 697,
"bicycles": 111
},
{
"year": "2018",
"cars": 1213,
"motorcycles": 633,
"bicycles": 87
},
{
"year": "2019",
"cars": 1199,
"motorcycles": 521,
"bicycles": 145
},
{
"year": "2020",
"cars": 1110,
"motorcycles": 310,
"bicycles": 91
},
{
"year": "2021",
"cars": 1165,
"motorcycles": 425,
"bicycles": 120
},
{
"year": "2022",
"cars": 1145,
"motorcycles": 319,
"bicycles": 102
},
{
"year": "2023",
"cars": 1163,
"motorcycles": 201,
"bicycles": 145
},
{
"year": "2024",
"cars": 1180,
"motorcycles": 285,
"bicycles": 100
},
{
"year": "2025",
"cars": 1159,
"motorcycles": 255,
"bicycles": 122
}
]
},
{
"axis-0": {
"type": "CategoryAxis",
"settings": {
"categoryField": "year",
"startLocation": 0.5,
"endLocation": 0.5,
"renderer": {
"type": "AxisRendererX",
"settings": {
"minorGridEnabled": true,
"minGridDistance": 70
}
},
"tooltip": {
"type": "Tooltip"
}
},
"properties": {
"data": "#data-0"
}
}
},
{
"axis-1": {
"type": "ValueAxis",
"settings": {
"min": 0,
"renderer": {
"type": "AxisRendererY"
}
}
}
},
{
"series-0": {
"type": "SmoothedXLineSeries",
"settings": {
"name": "Cars",
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueYField": "cars",
"categoryXField": "year",
"stacked": true,
"stroke": "@root.interfaceColors.get('background')",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "[bold]{name}[/]\n{categoryX}: {valueY}"
}
}
},
"properties": {
"data": "#data-0",
"strokes": {
"properties": {
"template": {
"settings": {
"strokeWidth": 4,
"strokeOpacity": 1,
"shadowBlur": 2,
"shadowOffsetX": 2,
"shadowOffsetY": 2,
"shadowColor": {
"type": "Color",
"value": "#000000"
},
"shadowOpacity": 0.1
}
}
}
},
"fills": {
"properties": {
"template": {
"settings": {
"fillOpacity": 1,
"visible": true,
"fillPattern": {
"type": "GrainPattern",
"settings": {
"maxOpacity": 0.15,
"density": 0.5,
"colors": [
{
"type": "Color",
"value": "#000000"
},
{
"type": "Color",
"value": "#000000"
},
{
"type": "Color",
"value": "#ffffff"
}
]
}
}
}
}
}
}
}
}
},
{
"series-1": {
"type": "SmoothedXLineSeries",
"settings": {
"name": "Motorcycles",
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueYField": "motorcycles",
"categoryXField": "year",
"stacked": true,
"stroke": "@root.interfaceColors.get('background')",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "[bold]{name}[/]\n{categoryX}: {valueY}"
}
}
},
"properties": {
"data": "#data-0",
"strokes": {
"properties": {
"template": {
"settings": {
"strokeWidth": 4,
"strokeOpacity": 1,
"shadowBlur": 2,
"shadowOffsetX": 2,
"shadowOffsetY": 2,
"shadowColor": {
"type": "Color",
"value": "#000000"
},
"shadowOpacity": 0.1
}
}
}
},
"fills": {
"properties": {
"template": {
"settings": {
"fillOpacity": 1,
"visible": true,
"fillPattern": {
"type": "GrainPattern",
"settings": {
"maxOpacity": 0.15,
"density": 0.5,
"colors": [
{
"type": "Color",
"value": "#000000"
},
{
"type": "Color",
"value": "#000000"
},
{
"type": "Color",
"value": "#ffffff"
}
]
}
}
}
}
}
}
}
}
},
{
"series-2": {
"type": "SmoothedXLineSeries",
"settings": {
"name": "Bicycles",
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueYField": "bicycles",
"categoryXField": "year",
"stacked": true,
"stroke": "@root.interfaceColors.get('background')",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "[bold]{name}[/]\n{categoryX}: {valueY}"
}
}
},
"properties": {
"data": "#data-0",
"strokes": {
"properties": {
"template": {
"settings": {
"strokeWidth": 4,
"strokeOpacity": 1,
"shadowBlur": 2,
"shadowOffsetX": 2,
"shadowOffsetY": 2,
"shadowColor": {
"type": "Color",
"value": "#000000"
},
"shadowOpacity": 0.1
}
}
}
},
"fills": {
"properties": {
"template": {
"settings": {
"fillOpacity": 1,
"visible": true,
"fillPattern": {
"type": "GrainPattern",
"settings": {
"maxOpacity": 0.15,
"density": 0.5,
"colors": [
{
"type": "Color",
"value": "#000000"
},
{
"type": "Color",
"value": "#000000"
},
{
"type": "Color",
"value": "#ffffff"
}
]
}
}
}
}
}
}
}
}
}
]
}