A line chart with two trend lines drawn over it: green along a rise, red along a fall. Each trend line is simply its own line series with two points.
A trend line turns a run of ups and downs into one direction you can see at a glance. Placing them yourself, as here, lets you mark the stretches that matter, like a growth phase and the slide after it.
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)
]);
var data = [
{
date: "2026-01-01",
value: 8
},
{
date: "2026-01-02",
value: 10
},
{
date: "2026-01-03",
value: 12
},
{
date: "2026-01-04",
value: 14
},
{
date: "2026-01-05",
value: 11
},
{
date: "2026-01-06",
value: 6
},
{
date: "2026-01-07",
value: 7
},
{
date: "2026-01-08",
value: 9
},
{
date: "2026-01-09",
value: 13
},
{
date: "2026-01-10",
value: 15
},
{
date: "2026-01-11",
value: 19
},
{
date: "2026-01-12",
value: 21
},
{
date: "2026-01-13",
value: 22
},
{
date: "2026-01-14",
value: 20
},
{
date: "2026-01-15",
value: 18
},
{
date: "2026-01-16",
value: 14
},
{
date: "2026-01-17",
value: 16
},
{
date: "2026-01-18",
value: 18
},
{
date: "2026-01-19",
value: 17
},
{
date: "2026-01-20",
value: 15
},
{
date: "2026-01-21",
value: 12
},
{
date: "2026-01-22",
value: 10
},
{
date: "2026-01-23",
value: 8
}
];
// Create chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/
var chart = root.container.children.push(
am5xy.XYChart.new(root, {
focusable: true, // the chart can be reached with the Tab key
panX: true, // drag the plot to pan sideways...
panY: true, // ...and up and down
wheelX: "panX", // a horizontal wheel or trackpad swipe pans
wheelY: "zoomX", // the vertical wheel zooms in on the dates
pinchZoomX: true, // pinch on a touch screen to zoom the dates
paddingLeft: 0 // the value labels sit at the chart's left edge
})
);
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var xAxis = chart.xAxes.push(
am5xy.DateAxis.new(root, {
// the axis can be panned up to half its length past the first or last date
maxDeviation: 0.5,
groupData: false, // every day stays its own point, never grouped into weeks
baseInterval: { // one point per day
timeUnit: "day",
count: 1
},
renderer: am5xy.AxisRendererX.new(root, {
// drag along the axis labels to zoom the axis
pan: "zoom",
minGridDistance: 70, // at least 70px between date labels
minorGridEnabled: true // fainter grid lines between the labeled ones
}),
tooltip: am5.Tooltip.new(root, {}) // shows the cursor's date on the axis
})
);
var yAxis = chart.yAxes.push(
am5xy.ValueAxis.new(root, {
maxDeviation: 1, // can be panned up to its whole height past the values
renderer: am5xy.AxisRendererY.new(root, { pan: "zoom" }) // drag along the value labels to zoom
})
);
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
var series = chart.series.push(
am5xy.LineSeries.new(root, {
// bullets hide when the points get closer than 10px, as when zoomed out
minBulletDistance: 10,
xAxis: xAxis,
yAxis: yAxis,
valueYField: "value",
valueXField: "date",
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal", // the tooltip points sideways at the line
labelText: "{valueY}" // just the value
})
})
);
// Set up data processor to parse string dates
// https://www.amcharts.com/docs/v5/concepts/data/#Pre_processing_data
series.data.processor = am5.DataProcessor.new(root, {
dateFormat: "yyyy-MM-dd",
dateFields: ["date"]
});
series.data.setAll(data);
// All bullets share one template, so setting its radius resizes them at once
var bulletTemplate = am5.Template.new({
radius: 4
});
series.bullets.push(function () {
var circle = am5.Circle.new(root, {
fill: series.get("fill"), // the line's color
stroke: root.interfaceColors.get("background"), // a ring in the background color sets the dot off the line
strokeWidth: 2
}, bulletTemplate);
return am5.Bullet.new(root, {
sprite: circle
});
});
// a rising trend from January 2 to 11, in the theme's positive color (green)
createTrendLine(
[
{ date: "2026-01-02", value: 10 },
{ date: "2026-01-11", value: 19 }
],
root.interfaceColors.get("positive")
);
// a falling trend from January 17 to 22, in the theme's negative color (red)
createTrendLine(
[
{ date: "2026-01-17", value: 16 },
{ date: "2026-01-22", value: 10 }
],
root.interfaceColors.get("negative")
);
// a trend line is a separate line series with two points: where it starts and where it ends
function createTrendLine(data, color) {
var series = chart.series.push(
am5xy.LineSeries.new(root, {
xAxis: xAxis,
yAxis: yAxis,
valueXField: "date",
stroke: color, // the trend line's own color
valueYField: "value"
})
);
series.data.processor = am5.DataProcessor.new(root, {
dateFormat: "yyyy-MM-dd",
dateFields: ["date"]
});
series.data.setAll(data);
series.appear(1000, 100);
}
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
xAxis: xAxis
}));
cursor.lineY.set("visible", false); // no horizontal cursor line
// add scrollbar
chart.set("scrollbarX", am5.Scrollbar.new(root, {
orientation: "horizontal"
}));
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series.appear(1000, 100);
chart.appear(1000, 100);
{
"type": "XYChart",
"settings": {
"focusable": true,
"panX": true,
"panY": true,
"wheelX": "panX",
"wheelY": "zoomX",
"pinchZoomX": true,
"paddingLeft": 0,
"cursor": {
"type": "XYCursor",
"settings": {
"xAxis": "#axis-0"
},
"properties": {
"lineY": {
"settings": {
"visible": false
}
}
}
},
"scrollbarX": {
"type": "Scrollbar",
"settings": {
"orientation": "horizontal"
}
}
},
"properties": {
"series": [
"#series-0",
"#series-1",
"#series-2"
],
"xAxes": [
"#axis-0"
],
"yAxes": [
"#axis-1"
]
},
"refs": [
{
"data-0": [
{
"date": 1767218400000,
"value": 8
},
{
"date": 1767304800000,
"value": 10
},
{
"date": 1767391200000,
"value": 12
},
{
"date": 1767477600000,
"value": 14
},
{
"date": 1767564000000,
"value": 11
},
{
"date": 1767650400000,
"value": 6
},
{
"date": 1767736800000,
"value": 7
},
{
"date": 1767823200000,
"value": 9
},
{
"date": 1767909600000,
"value": 13
},
{
"date": 1767996000000,
"value": 15
},
{
"date": 1768082400000,
"value": 19
},
{
"date": 1768168800000,
"value": 21
},
{
"date": 1768255200000,
"value": 22
},
{
"date": 1768341600000,
"value": 20
},
{
"date": 1768428000000,
"value": 18
},
{
"date": 1768514400000,
"value": 14
},
{
"date": 1768600800000,
"value": 16
},
{
"date": 1768687200000,
"value": 18
},
{
"date": 1768773600000,
"value": 17
},
{
"date": 1768860000000,
"value": 15
},
{
"date": 1768946400000,
"value": 12
},
{
"date": 1769032800000,
"value": 10
},
{
"date": 1769119200000,
"value": 8
}
]
},
{
"data-1": [
{
"date": 1767304800000,
"value": 10
},
{
"date": 1768082400000,
"value": 19
}
]
},
{
"data-2": [
{
"date": 1768600800000,
"value": 16
},
{
"date": 1769032800000,
"value": 10
}
]
},
{
"template-0": {
"type": "Template",
"settings": {
"radius": 4
}
}
},
{
"axis-0": {
"type": "DateAxis",
"settings": {
"maxDeviation": 0.5,
"groupData": false,
"baseInterval": {
"timeUnit": "day",
"count": 1
},
"renderer": {
"type": "AxisRendererX",
"settings": {
"pan": "zoom",
"minGridDistance": 70,
"minorGridEnabled": true
}
},
"tooltip": {
"type": "Tooltip"
}
}
}
},
{
"axis-1": {
"type": "ValueAxis",
"settings": {
"maxDeviation": 1,
"renderer": {
"type": "AxisRendererY",
"settings": {
"pan": "zoom"
}
}
}
}
},
{
"series-0": {
"type": "LineSeries",
"settings": {
"minBulletDistance": 10,
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueYField": "value",
"valueXField": "date",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "{valueY}"
}
}
},
"properties": {
"data": "#data-0",
"bullets": [
{
"type": "Bullet",
"settings": {
"sprite": {
"type": "Circle",
"settings": {
"fill": "@series.get('fill')",
"stroke": "@root.interfaceColors.get('background')",
"strokeWidth": 2
},
"properties": {
"template": "#template-0"
}
}
}
}
]
}
}
},
{
"series-1": {
"type": "LineSeries",
"settings": {
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueXField": "date",
"stroke": "@root.interfaceColors.get('positive')",
"valueYField": "value"
},
"properties": {
"data": "#data-1"
}
}
},
{
"series-2": {
"type": "LineSeries",
"settings": {
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueXField": "date",
"stroke": "@root.interfaceColors.get('negative')",
"valueYField": "value"
},
"properties": {
"data": "#data-2"
}
}
}
]
}