Bars and a line on one chart, turned on its side: income as horizontal bars, expenses as a line that climbs through the years. In 2025, expenses overtook income.
Turning a combined chart on its side lets the categories run down the page, which suits a narrow panel on a dashboard or long category names. The line still links one measure across the categories, so it needs an order, like years, to mean anything.
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, // the plot doesn't pan when dragged
panY: false,
wheelX: "panX", // a horizontal wheel or trackpad swipe pans the values
wheelY: "zoomX", // the vertical wheel zooms in on the values
// room on the left for the year axis tooltip
paddingLeft: 15,
layout: root.verticalLayout
}));
var data = [{
"year": "2021",
"income": 23.5,
"expenses": 18.1
}, {
"year": "2022",
"income": 26.2,
"expenses": 22.8
}, {
"year": "2023",
"income": 30.1,
"expenses": 23.9
}, {
"year": "2024",
"income": 29.5,
"expenses": 25.1
}, {
"year": "2025",
"income": 24.6,
"expenses": 25
}];
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var yRenderer = am5xy.AxisRendererY.new(root, {
// the gap between years: each year's bar takes the middle 80% of its row
cellStartLocation: 0.1,
cellEndLocation: 0.9,
minorGridEnabled: true // a grid line for every year, even one whose label is skipped
});
// draw each grid line at the end of its year's row instead of at its start
yRenderer.grid.template.set("location", 1);
var yAxis = chart.yAxes.push(
am5xy.CategoryAxis.new(root, {
categoryField: "year",
renderer: yRenderer,
tooltip: am5.Tooltip.new(root, {}) // the cursor shows the year on the axis
})
);
yAxis.data.setAll(data);
var xAxis = chart.xAxes.push(
am5xy.ValueAxis.new(root, {
min: 0, // the bars start at zero
renderer: am5xy.AxisRendererX.new(root, {
strokeOpacity: 0.1, // a faint axis line
minGridDistance:70 // at least 70px between labels; on narrow screens some are skipped
})
})
);
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
var series1 = chart.series.push(am5xy.ColumnSeries.new(root, {
name: "Income",
xAxis: xAxis,
yAxis: yAxis,
valueXField: "income",
categoryYField: "year",
sequencedInterpolation: true, // the bars grow one after another
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal", // the tooltip points sideways at the bar
labelText: "[bold]{name}[/]\n{categoryY}: {valueX}" // the series name in bold, then the year and the value
})
}));
series1.columns.template.setAll({
height: am5.percent(70) // each bar takes 70% of its year's cell
});
var series2 = chart.series.push(am5xy.LineSeries.new(root, {
name: "Expenses",
xAxis: xAxis,
yAxis: yAxis,
valueXField: "expenses",
categoryYField: "year",
sequencedInterpolation: true, // the line's points animate one after another
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal",
labelText: "[bold]{name}[/]\n{categoryY}: {valueX}"
})
}));
series2.strokes.template.setAll({
strokeWidth: 2, // a 2px line
});
// a circle on each point of the line
series2.bullets.push(function () {
return am5.Bullet.new(root, {
locationY: 0.5, // in the middle of the year's row
sprite: am5.Circle.new(root, {
radius: 5, // 5px
stroke: series2.get("stroke"), // outlined in the line's color...
strokeWidth: 2, // ...2px wide
fill: root.interfaceColors.get("background") // filled with the background color, so it looks hollow
})
});
});
// Add legend, in the bottom right corner of the plot area, its items one under the other
// https://www.amcharts.com/docs/v5/charts/xy-chart/legend-xy-series/
var legend = chart.plotContainer.children.push(am5.Legend.new(root, {
x: am5.p100,
centerX: am5.p100,
y: am5.p100,
centerY: am5.p100,
layout: root.verticalLayout,
paddingRight: 10, // 10px in from the corner
paddingBottom: 10
}));
legend.data.setAll(chart.series.values);
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
// drag up or down across the plot to zoom into those years
behavior: "zoomY"
}));
cursor.lineX.set("visible", false); // no vertical cursor line, only the horizontal one
series1.data.setAll(data);
series2.data.setAll(data);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series1.appear();
series2.appear();
chart.appear(1000, 100);
{
"type": "XYChart",
"settings": {
"panX": false,
"panY": false,
"wheelX": "panX",
"wheelY": "zoomX",
"paddingLeft": 15,
"layout": {
"type": "VerticalLayout"
},
"cursor": {
"type": "XYCursor",
"settings": {
"behavior": "zoomY"
},
"properties": {
"lineX": {
"settings": {
"visible": false
}
}
}
}
},
"properties": {
"series": [
"#series-0",
"#series-1"
],
"xAxes": [
"#axis-0"
],
"yAxes": [
"#axis-1"
],
"plotContainer": {
"children": [
{
"type": "Legend",
"settings": {
"x": {
"type": "Percent",
"value": 100
},
"centerX": {
"type": "Percent",
"value": 100
},
"y": {
"type": "Percent",
"value": 100
},
"centerY": {
"type": "Percent",
"value": 100
},
"layout": {
"type": "VerticalLayout"
},
"paddingRight": 10,
"paddingBottom": 10
},
"properties": {
"data": [
"#series-0",
"#series-1"
]
},
"index": 5
}
]
}
},
"refs": [
{
"data-0": [
{
"year": "2021",
"income": 23.5,
"expenses": 18.1
},
{
"year": "2022",
"income": 26.2,
"expenses": 22.8
},
{
"year": "2023",
"income": 30.1,
"expenses": 23.9
},
{
"year": "2024",
"income": 29.5,
"expenses": 25.1
},
{
"year": "2025",
"income": 24.6,
"expenses": 25
}
]
},
{
"axis-0": {
"type": "ValueAxis",
"settings": {
"min": 0,
"renderer": {
"type": "AxisRendererX",
"settings": {
"strokeOpacity": 0.1,
"minGridDistance": 70
}
}
}
}
},
{
"axis-1": {
"type": "CategoryAxis",
"settings": {
"categoryField": "year",
"renderer": {
"type": "AxisRendererY",
"settings": {
"cellStartLocation": 0.1,
"cellEndLocation": 0.9,
"minorGridEnabled": true
},
"properties": {
"grid": {
"properties": {
"template": {
"settings": {
"location": 1
}
}
}
}
}
},
"tooltip": {
"type": "Tooltip"
}
},
"properties": {
"data": "#data-0"
}
}
},
{
"series-0": {
"type": "ColumnSeries",
"settings": {
"name": "Income",
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueXField": "income",
"categoryYField": "year",
"sequencedInterpolation": true,
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "[bold]{name}[/]\n{categoryY}: {valueX}"
}
}
},
"properties": {
"data": "#data-0",
"columns": {
"properties": {
"template": {
"settings": {
"height": {
"type": "Percent",
"value": 70
}
}
}
}
}
}
}
},
{
"series-1": {
"type": "LineSeries",
"settings": {
"name": "Expenses",
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueXField": "expenses",
"categoryYField": "year",
"sequencedInterpolation": true,
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "[bold]{name}[/]\n{categoryY}: {valueX}"
}
}
},
"properties": {
"data": "#data-0",
"strokes": {
"properties": {
"template": {
"settings": {
"strokeWidth": 2
}
}
}
},
"bullets": [
{
"type": "Bullet",
"settings": {
"locationY": 0.5,
"sprite": {
"type": "Circle",
"settings": {
"radius": 5,
"stroke": "@series.get('stroke')",
"strokeWidth": 2,
"fill": "@root.interfaceColors.get('background')"
}
}
}
}
]
}
}
}
]
}