Hourly readings and daily averages on one chart: the line has a point for every hour, each column the average of that day. Two date axes keep them in step.
Daily figures show the overall trend; hourly ones show what happened within each day. Drawing both on one value scale shows how far single hours stray from their day’s average, without switching between two charts.
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, {
focusable: true, // the chart can be reached with the Tab key
panX: true, // drag the plot sideways to pan through the days
panY: true, // and up and down
wheelX: "panX", // a horizontal wheel or trackpad swipe pans...
wheelY: "zoomX", // ...and the vertical wheel zooms in on the days
pinchZoomX: true // pinch with two fingers to zoom on a touch screen
})
);
// Generate random data: a value for every hour of the last ten days,
// and the average of each day's 24 values
var hourlyData = [];
var dailyData = [];
var firstDate = new Date();
firstDate.setDate(firstDate.getDate() - 10); // ten days ago...
firstDate.setHours(0, 0, 0, 0); // ...at midnight
var value = 10; // the starting value
for (var day = 0; day < 10; day++) {
var sum = 0;
for (var hour = 0; hour < 24; hour++) {
// each hour the value moves up or down by up to 10%
value = Math.round(value * (0.9 + Math.random() * 0.2) * 100) / 100;
sum += value; // for the day's average
var date = new Date(firstDate);
date.setDate(date.getDate() + day);
date.setHours(hour);
hourlyData.push({ date: date.getTime(), value: value });
}
var dayDate = new Date(firstDate);
dayDate.setDate(dayDate.getDate() + day);
// the day's average, rounded to 2 decimals
dailyData.push({ date: dayDate.getTime(), value: Math.round(sum / 24 * 100) / 100 });
}
// Add scrollbar, hidden at first
// https://www.amcharts.com/docs/v5/charts/xy-chart/scrollbars/
chart.set("scrollbarX", am5.Scrollbar.new(root, { orientation: "horizontal", forceHidden: true }));
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
// One value axis, shared by the hourly line and the daily columns
var yAxis = chart.yAxes.push(
am5xy.ValueAxis.new(root, {
maxDeviation: 0.1, // pans at most 10% past the value range
renderer: am5xy.AxisRendererY.new(root, {})
})
);
// Hourly date axis for the line. Its labels and grid are hidden:
// the daily axis below shows the dates.
var xAxis1 = chart.xAxes.push(
am5xy.DateAxis.new(root, {
maxDeviation: 0.1, // pans up to 10% past the first and last hour
tooltipDateFormat: "MMM d, HH:00", // the axis tooltip shows the date and the hour
baseInterval: { timeUnit: "hour", count: 1 }, // one point per hour
renderer: am5xy.AxisRendererX.new(root, {
minGridDistance: 50
}),
tooltip: am5.Tooltip.new(root, {}) // a date and hour label follows the cursor along the axis
})
);
xAxis1.get("renderer").labels.template.set("forceHidden", true);
xAxis1.get("renderer").grid.template.set("forceHidden", true);
// Daily date axis for the columns
var xAxis2 = chart.xAxes.push(
am5xy.DateAxis.new(root, {
maxDeviation: 0.1, // pans up to 10% past the first and last day
baseInterval: { timeUnit: "day", count: 1 }, // one column per day
renderer: am5xy.AxisRendererX.new(root, {
minGridDistance: 50 // at least 50px between the date labels
})
})
);
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
var series1 = chart.series.push(
am5xy.LineSeries.new(root, {
xAxis: xAxis1,
yAxis: yAxis,
valueYField: "value",
valueXField: "date",
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal", // the tooltip sits beside the point
labelText: "Hourly: {valueY}" // the hour's value
})
})
);
series1.strokes.template.setAll({
strokeWidth: 2 // a 2px line
});
series1.data.setAll(hourlyData);
// unshift() puts the columns first, so they are drawn behind the line
var series2 = chart.series.unshift(
am5xy.ColumnSeries.new(root, {
xAxis: xAxis2,
yAxis: yAxis,
valueYField: "value",
valueXField: "date",
tooltip: am5.Tooltip.new(root, {
pointerOrientation: "horizontal", // the tooltip sits beside the column
labelText: "Daily average: {valueY}" // the day's average
})
})
);
// no outline: the columns are only their fill, so a fading fill fades all of them
series2.columns.template.set("strokeOpacity", 0);
series2.data.setAll(dailyData);
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
// the cursor snaps to the hours of the line's axis
xAxis: xAxis1
}));
cursor.lineY.set("visible", false); // only the vertical cursor line, no horizontal one
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series1.appear(1000, 100);
series2.appear(1000, 100);
chart.appear(1000, 100);
{
"type": "XYChart",
"settings": {
"focusable": true,
"panX": true,
"panY": true,
"wheelX": "panX",
"wheelY": "zoomX",
"pinchZoomX": true,
"scrollbarX": {
"type": "Scrollbar",
"settings": {
"orientation": "horizontal",
"forceHidden": true
}
},
"cursor": {
"type": "XYCursor",
"settings": {
"xAxis": "#axis-0"
},
"properties": {
"lineY": {
"settings": {
"visible": false
}
}
}
}
},
"properties": {
"series": [
"#series-0",
"#series-1"
],
"xAxes": [
"#axis-0",
"#axis-1"
],
"yAxes": [
"#axis-2"
]
},
"refs": [
{
"data-0": [
{
"date": 1790542800000,
"value": 7.92
},
{
"date": 1790629200000,
"value": 9.38
},
{
"date": 1790715600000,
"value": 9.36
},
{
"date": 1790802000000,
"value": 7.66
},
{
"date": 1790888400000,
"value": 5.51
},
{
"date": 1790974800000,
"value": 5.08
},
{
"date": 1791061200000,
"value": 5.21
},
{
"date": 1791147600000,
"value": 5.31
},
{
"date": 1791234000000,
"value": 3.28
},
{
"date": 1791320400000,
"value": 3.85
}
]
},
{
"data-1": [
{
"date": 1790542800000,
"value": 10.01
},
{
"date": 1790546400000,
"value": 9.14
},
{
"date": 1790550000000,
"value": 8.27
},
{
"date": 1790553600000,
"value": 8.29
},
{
"date": 1790557200000,
"value": 8.57
},
{
"date": 1790560800000,
"value": 8.49
},
{
"date": 1790564400000,
"value": 7.7
},
{
"date": 1790568000000,
"value": 7.99
},
{
"date": 1790571600000,
"value": 7.42
},
{
"date": 1790575200000,
"value": 6.99
},
{
"date": 1790578800000,
"value": 7.4
},
{
"date": 1790582400000,
"value": 6.91
},
{
"date": 1790586000000,
"value": 7.43
},
{
"date": 1790589600000,
"value": 6.98
},
{
"date": 1790593200000,
"value": 7.3
},
{
"date": 1790596800000,
"value": 7.02
},
{
"date": 1790600400000,
"value": 6.98
},
{
"date": 1790604000000,
"value": 7.36
},
{
"date": 1790607600000,
"value": 8.03
},
{
"date": 1790611200000,
"value": 8.69
},
{
"date": 1790614800000,
"value": 7.88
},
{
"date": 1790618400000,
"value": 7.95
},
{
"date": 1790622000000,
"value": 8.63
},
{
"date": 1790625600000,
"value": 8.75
},
{
"date": 1790629200000,
"value": 9.17
},
{
"date": 1790632800000,
"value": 9.26
},
{
"date": 1790636400000,
"value": 9.38
},
{
"date": 1790640000000,
"value": 10
},
{
"date": 1790643600000,
"value": 9.56
},
{
"date": 1790647200000,
"value": 9.64
},
{
"date": 1790650800000,
"value": 10.2
},
{
"date": 1790654400000,
"value": 11.11
},
{
"date": 1790658000000,
"value": 10.37
},
{
"date": 1790661600000,
"value": 9.77
},
{
"date": 1790665200000,
"value": 10.65
},
{
"date": 1790668800000,
"value": 9.77
},
{
"date": 1790672400000,
"value": 10.15
},
{
"date": 1790676000000,
"value": 9.36
},
{
"date": 1790679600000,
"value": 8.62
},
{
"date": 1790683200000,
"value": 8.03
},
{
"date": 1790686800000,
"value": 8.18
},
{
"date": 1790690400000,
"value": 8.19
},
{
"date": 1790694000000,
"value": 9
},
{
"date": 1790697600000,
"value": 8.78
},
{
"date": 1790701200000,
"value": 8.73
},
{
"date": 1790704800000,
"value": 9.4
},
{
"date": 1790708400000,
"value": 9.18
},
{
"date": 1790712000000,
"value": 8.72
},
{
"date": 1790715600000,
"value": 8.87
},
{
"date": 1790719200000,
"value": 8.94
},
{
"date": 1790722800000,
"value": 9.21
},
{
"date": 1790726400000,
"value": 8.68
},
{
"date": 1790730000000,
"value": 8.84
},
{
"date": 1790733600000,
"value": 9.52
},
{
"date": 1790737200000,
"value": 9.6
},
{
"date": 1790740800000,
"value": 9.75
},
{
"date": 1790744400000,
"value": 10.72
},
{
"date": 1790748000000,
"value": 11.29
},
{
"date": 1790751600000,
"value": 10.4
},
{
"date": 1790755200000,
"value": 9.42
},
{
"date": 1790758800000,
"value": 9.31
},
{
"date": 1790762400000,
"value": 9.61
},
{
"date": 1790766000000,
"value": 9.73
},
{
"date": 1790769600000,
"value": 9.84
},
{
"date": 1790773200000,
"value": 9.06
},
{
"date": 1790776800000,
"value": 8.28
},
{
"date": 1790780400000,
"value": 7.93
},
{
"date": 1790784000000,
"value": 8.72
},
{
"date": 1790787600000,
"value": 9.05
},
{
"date": 1790791200000,
"value": 9.36
},
{
"date": 1790794800000,
"value": 9.57
},
{
"date": 1790798400000,
"value": 8.92
},
{
"date": 1790802000000,
"value": 8.44
},
{
"date": 1790805600000,
"value": 8.05
},
{
"date": 1790809200000,
"value": 7.53
},
{
"date": 1790812800000,
"value": 7.07
},
{
"date": 1790816400000,
"value": 6.86
},
{
"date": 1790820000000,
"value": 6.84
},
{
"date": 1790823600000,
"value": 7.04
},
{
"date": 1790827200000,
"value": 7.29
},
{
"date": 1790830800000,
"value": 7.92
},
{
"date": 1790834400000,
"value": 7.75
},
{
"date": 1790838000000,
"value": 8.17
},
{
"date": 1790841600000,
"value": 8.97
},
{
"date": 1790845200000,
"value": 9.78
},
{
"date": 1790848800000,
"value": 9.21
},
{
"date": 1790852400000,
"value": 9.17
},
{
"date": 1790856000000,
"value": 8.6
},
{
"date": 1790859600000,
"value": 8.1
},
{
"date": 1790863200000,
"value": 7.3
},
{
"date": 1790866800000,
"value": 6.99
},
{
"date": 1790870400000,
"value": 6.69
},
{
"date": 1790874000000,
"value": 6.83
},
{
"date": 1790877600000,
"value": 6.26
},
{
"date": 1790881200000,
"value": 6.22
},
{
"date": 1790884800000,
"value": 6.7
},
{
"date": 1790888400000,
"value": 6.5
},
{
"date": 1790892000000,
"value": 5.88
},
{
"date": 1790895600000,
"value": 5.69
},
{
"date": 1790899200000,
"value": 5.38
},
{
"date": 1790902800000,
"value": 5.73
},
{
"date": 1790906400000,
"value": 5.9
},
{
"date": 1790910000000,
"value": 5.68
},
{
"date": 1790913600000,
"value": 5.84
},
{
"date": 1790917200000,
"value": 5.93
},
{
"date": 1790920800000,
"value": 5.61
},
{
"date": 1790924400000,
"value": 5.38
},
{
"date": 1790928000000,
"value": 5.56
},
{
"date": 1790931600000,
"value": 5.84
},
{
"date": 1790935200000,
"value": 5.36
},
{
"date": 1790938800000,
"value": 5.44
},
{
"date": 1790942400000,
"value": 5.42
},
{
"date": 1790946000000,
"value": 5.18
},
{
"date": 1790949600000,
"value": 5.53
},
{
"date": 1790953200000,
"value": 5.27
},
{
"date": 1790956800000,
"value": 5
},
{
"date": 1790960400000,
"value": 5
},
{
"date": 1790964000000,
"value": 5.16
},
{
"date": 1790967600000,
"value": 5.17
},
{
"date": 1790971200000,
"value": 4.69
},
{
"date": 1790974800000,
"value": 5.12
},
{
"date": 1790978400000,
"value": 5.05
},
{
"date": 1790982000000,
"value": 5.23
},
{
"date": 1790985600000,
"value": 5.06
},
{
"date": 1790989200000,
"value": 4.8
},
{
"date": 1790992800000,
"value": 4.37
},
{
"date": 1790996400000,
"value": 4.65
},
{
"date": 1791000000000,
"value": 4.51
},
{
"date": 1791003600000,
"value": 4.82
},
{
"date": 1791007200000,
"value": 4.94
},
{
"date": 1791010800000,
"value": 4.53
},
{
"date": 1791014400000,
"value": 4.71
},
{
"date": 1791018000000,
"value": 5.14
},
{
"date": 1791021600000,
"value": 4.96
},
{
"date": 1791025200000,
"value": 5.29
},
{
"date": 1791028800000,
"value": 5.75
},
{
"date": 1791032400000,
"value": 6.03
},
{
"date": 1791036000000,
"value": 5.82
},
{
"date": 1791039600000,
"value": 5.77
},
{
"date": 1791043200000,
"value": 5.27
},
{
"date": 1791046800000,
"value": 4.97
},
{
"date": 1791050400000,
"value": 5.01
},
{
"date": 1791054000000,
"value": 5.02
},
{
"date": 1791057600000,
"value": 5.1
},
{
"date": 1791061200000,
"value": 4.7
},
{
"date": 1791064800000,
"value": 4.98
},
{
"date": 1791068400000,
"value": 5.28
},
{
"date": 1791072000000,
"value": 4.97
},
{
"date": 1791075600000,
"value": 4.65
},
{
"date": 1791079200000,
"value": 4.85
},
{
"date": 1791082800000,
"value": 5.22
},
{
"date": 1791086400000,
"value": 4.97
},
{
"date": 1791090000000,
"value": 5.06
},
{
"date": 1791093600000,
"value": 5.41
},
{
"date": 1791097200000,
"value": 5.09
},
{
"date": 1791100800000,
"value": 5.5
},
{
"date": 1791104400000,
"value": 5.66
},
{
"date": 1791108000000,
"value": 5.84
},
{
"date": 1791111600000,
"value": 5.55
},
{
"date": 1791115200000,
"value": 5.39
},
{
"date": 1791118800000,
"value": 5.09
},
{
"date": 1791122400000,
"value": 4.97
},
{
"date": 1791126000000,
"value": 4.95
},
{
"date": 1791129600000,
"value": 5.35
},
{
"date": 1791133200000,
"value": 5.37
},
{
"date": 1791136800000,
"value": 4.97
},
{
"date": 1791140400000,
"value": 5.45
},
{
"date": 1791144000000,
"value": 5.79
},
{
"date": 1791147600000,
"value": 5.84
},
{
"date": 1791151200000,
"value": 6.18
},
{
"date": 1791154800000,
"value": 6.54
},
{
"date": 1791158400000,
"value": 6.02
},
{
"date": 1791162000000,
"value": 6.46
},
{
"date": 1791165600000,
"value": 5.88
},
{
"date": 1791169200000,
"value": 6.27
},
{
"date": 1791172800000,
"value": 6.33
},
{
"date": 1791176400000,
"value": 6.33
},
{
"date": 1791180000000,
"value": 6
},
{
"date": 1791183600000,
"value": 5.58
},
{
"date": 1791187200000,
"value": 5.27
},
{
"date": 1791190800000,
"value": 5.02
},
{
"date": 1791194400000,
"value": 4.8
},
{
"date": 1791198000000,
"value": 4.49
},
{
"date": 1791201600000,
"value": 4.45
},
{
"date": 1791205200000,
"value": 4.62
},
{
"date": 1791208800000,
"value": 5.07
},
{
"date": 1791212400000,
"value": 4.68
},
{
"date": 1791216000000,
"value": 4.78
},
{
"date": 1791219600000,
"value": 4.55
},
{
"date": 1791223200000,
"value": 4.22
},
{
"date": 1791226800000,
"value": 3.85
},
{
"date": 1791230400000,
"value": 4.15
},
{
"date": 1791234000000,
"value": 4.11
},
{
"date": 1791237600000,
"value": 3.88
},
{
"date": 1791241200000,
"value": 3.73
},
{
"date": 1791244800000,
"value": 3.82
},
{
"date": 1791248400000,
"value": 3.65
},
{
"date": 1791252000000,
"value": 3.94
},
{
"date": 1791255600000,
"value": 4.29
},
{
"date": 1791259200000,
"value": 3.93
},
{
"date": 1791262800000,
"value": 3.54
},
{
"date": 1791266400000,
"value": 3.23
},
{
"date": 1791270000000,
"value": 3.23
},
{
"date": 1791273600000,
"value": 3.09
},
{
"date": 1791277200000,
"value": 2.82
},
{
"date": 1791280800000,
"value": 2.86
},
{
"date": 1791284400000,
"value": 2.82
},
{
"date": 1791288000000,
"value": 2.6
},
{
"date": 1791291600000,
"value": 2.61
},
{
"date": 1791295200000,
"value": 2.75
},
{
"date": 1791298800000,
"value": 2.76
},
{
"date": 1791302400000,
"value": 2.95
},
{
"date": 1791306000000,
"value": 2.76
},
{
"date": 1791309600000,
"value": 3.02
},
{
"date": 1791313200000,
"value": 3.06
},
{
"date": 1791316800000,
"value": 3.19
},
{
"date": 1791320400000,
"value": 3.18
},
{
"date": 1791324000000,
"value": 3.45
},
{
"date": 1791327600000,
"value": 3.49
},
{
"date": 1791331200000,
"value": 3.66
},
{
"date": 1791334800000,
"value": 3.54
},
{
"date": 1791338400000,
"value": 3.85
},
{
"date": 1791342000000,
"value": 4.14
},
{
"date": 1791345600000,
"value": 4.53
},
{
"date": 1791349200000,
"value": 4.14
},
{
"date": 1791352800000,
"value": 3.93
},
{
"date": 1791356400000,
"value": 3.81
},
{
"date": 1791360000000,
"value": 4.13
},
{
"date": 1791363600000,
"value": 4.42
},
{
"date": 1791367200000,
"value": 3.99
},
{
"date": 1791370800000,
"value": 3.75
},
{
"date": 1791374400000,
"value": 3.74
},
{
"date": 1791378000000,
"value": 3.97
},
{
"date": 1791381600000,
"value": 4.33
},
{
"date": 1791385200000,
"value": 3.99
},
{
"date": 1791388800000,
"value": 3.77
},
{
"date": 1791392400000,
"value": 3.52
},
{
"date": 1791396000000,
"value": 3.7
},
{
"date": 1791399600000,
"value": 3.77
},
{
"date": 1791403200000,
"value": 3.51
}
]
},
{
"axis-0": {
"type": "DateAxis",
"settings": {
"maxDeviation": 0.1,
"tooltipDateFormat": "MMM d, HH:00",
"baseInterval": {
"timeUnit": "hour",
"count": 1
},
"renderer": {
"type": "AxisRendererX",
"settings": {
"minGridDistance": 50
},
"properties": {
"labels": {
"properties": {
"template": {
"settings": {
"forceHidden": true
}
}
}
},
"grid": {
"properties": {
"template": {
"settings": {
"forceHidden": true
}
}
}
}
}
},
"tooltip": {
"type": "Tooltip"
}
}
}
},
{
"axis-1": {
"type": "DateAxis",
"settings": {
"maxDeviation": 0.1,
"baseInterval": {
"timeUnit": "day",
"count": 1
},
"renderer": {
"type": "AxisRendererX",
"settings": {
"minGridDistance": 50
}
}
}
}
},
{
"axis-2": {
"type": "ValueAxis",
"settings": {
"maxDeviation": 0.1,
"renderer": {
"type": "AxisRendererY"
}
}
}
},
{
"series-0": {
"type": "ColumnSeries",
"settings": {
"xAxis": "#axis-1",
"yAxis": "#axis-2",
"valueYField": "value",
"valueXField": "date",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "Daily average: {valueY}"
}
}
},
"properties": {
"data": "#data-0",
"columns": {
"properties": {
"template": {
"settings": {
"strokeOpacity": 0
}
}
}
}
}
}
},
{
"series-1": {
"type": "LineSeries",
"settings": {
"xAxis": "#axis-0",
"yAxis": "#axis-2",
"valueYField": "value",
"valueXField": "date",
"tooltip": {
"type": "Tooltip",
"settings": {
"pointerOrientation": "horizontal",
"labelText": "Hourly: {valueY}"
}
}
},
"properties": {
"data": "#data-1",
"strokes": {
"properties": {
"template": {
"settings": {
"strokeWidth": 2
}
}
}
}
}
}
}
]
}