A line chart of weekdays only: Saturdays and Sundays have no values, so the axis leaves them out and Friday sits right next to Monday, with no empty gap.
Markets, offices and schools have no figures on weekends. A normal date axis still makes room for those days, so the line runs straight across empty gaps; an evenly spaced axis gives every data point the same width and skips the rest. This demo uses the older CategoryDateAxis; for new charts, use GaplessDateAxis, which works like a regular date axis.
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: true, // drag the plot sideways to pan
panY: false,
wheelX: "panX", // a horizontal wheel or trackpad swipe pans...
wheelY: "zoomX", // ...and the vertical wheel zooms in on the dates
pinchZoomX:true // pinch with two fingers to zoom on touch screens
}));
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
behavior: "none" // a drag over the plot pans the chart instead of zooming
}));
cursor.lineY.set("visible", false); // no horizontal cursor line
// Generate random data
var date = new Date();
date.setHours(0, 0, 0, 0);
var value = 1;
// the next weekday's data point, a few points up or down from the last
function generateData() {
value = Math.round((Math.random() * 10 - 5) + value);
// weekdays only: step over Saturdays and Sundays, so Friday is followed by Monday
do {
am5.time.add(date, "day", 1);
} while (date.getDay() == 0 || date.getDay() == 6);
return {
date: date.getTime(),
value: value
};
}
// count weekdays of data in a row
function generateDatas(count) {
var data = [];
for (var i = 0; i < count; ++i) {
data.push(generateData());
}
return data;
}
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/category-date-axis/
var xRenderer = am5xy.AxisRendererX.new(root, {});
// hide a label that would be cut off at either end of the axis
xRenderer.labels.template.set("minPosition", 0.01);
xRenderer.labels.template.set("maxPosition", 0.99);
// each date in the data gets an equal slot, so the skipped weekends leave no gaps
var xAxis = chart.xAxes.push(
am5xy.CategoryDateAxis.new(root, {
categoryField: "date",
baseInterval: { // one category per day
timeUnit: "day",
count: 1
},
renderer: xRenderer,
// Show the weekday in the axis tooltip, so you can see Friday is followed by Monday
tooltipDateFormat: "EEE, MMM d",
tooltip: am5.Tooltip.new(root, {}) // the axis tooltip, at the cursor
})
);
var yAxis = chart.yAxes.push(
am5xy.ValueAxis.new(root, {
renderer: am5xy.AxisRendererY.new(root, {})
})
);
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
var series = chart.series.push(am5xy.LineSeries.new(root, {
name: "Series",
xAxis: xAxis,
yAxis: yAxis,
valueYField: "value",
categoryXField: "date"
}));
var tooltip = series.set("tooltip", am5.Tooltip.new(root, {}));
tooltip.label.set("text", "{valueY}"); // the hovered value
// Add scrollbar
// https://www.amcharts.com/docs/v5/charts/xy-chart/scrollbars/
chart.set("scrollbarX", am5.Scrollbar.new(root, {
orientation: "horizontal" // a scrollbar above the plot, to zoom and pan the dates
}));
// Set data
var data = generateDatas(200);
series.data.setAll(data);
xAxis.data.setAll(data);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series.appear(1000);
chart.appear(1000, 100);
{
"type": "XYChart",
"settings": {
"panX": true,
"panY": false,
"wheelX": "panX",
"wheelY": "zoomX",
"pinchZoomX": true,
"cursor": {
"type": "XYCursor",
"settings": {
"behavior": "none"
},
"properties": {
"lineY": {
"settings": {
"visible": false
}
}
}
},
"scrollbarX": {
"type": "Scrollbar",
"settings": {
"orientation": "horizontal"
}
}
},
"properties": {
"series": [
"#series-0"
],
"xAxes": [
"#axis-0"
],
"yAxes": [
"#axis-1"
]
},
"refs": [
{
"data-0": [
{
"date": 1791493200000,
"value": 2
},
{
"date": 1791752400000,
"value": -3
},
{
"date": 1791838800000,
"value": -8
},
{
"date": 1791925200000,
"value": -10
},
{
"date": 1792011600000,
"value": -8
},
{
"date": 1792098000000,
"value": -4
},
{
"date": 1792357200000,
"value": -8
},
{
"date": 1792443600000,
"value": -4
},
{
"date": 1792530000000,
"value": -5
},
{
"date": 1792616400000,
"value": -9
},
{
"date": 1792702800000,
"value": -9
},
{
"date": 1792965600000,
"value": -6
},
{
"date": 1793052000000,
"value": -8
},
{
"date": 1793138400000,
"value": -8
},
{
"date": 1793224800000,
"value": -6
},
{
"date": 1793311200000,
"value": -11
},
{
"date": 1793570400000,
"value": -12
},
{
"date": 1793656800000,
"value": -15
},
{
"date": 1793743200000,
"value": -15
},
{
"date": 1793829600000,
"value": -14
},
{
"date": 1793916000000,
"value": -9
},
{
"date": 1794175200000,
"value": -9
},
{
"date": 1794261600000,
"value": -13
},
{
"date": 1794348000000,
"value": -17
},
{
"date": 1794434400000,
"value": -19
},
{
"date": 1794520800000,
"value": -16
},
{
"date": 1794780000000,
"value": -21
},
{
"date": 1794866400000,
"value": -25
},
{
"date": 1794952800000,
"value": -27
},
{
"date": 1795039200000,
"value": -30
},
{
"date": 1795125600000,
"value": -26
},
{
"date": 1795384800000,
"value": -28
},
{
"date": 1795471200000,
"value": -32
},
{
"date": 1795557600000,
"value": -35
},
{
"date": 1795644000000,
"value": -38
},
{
"date": 1795730400000,
"value": -36
},
{
"date": 1795989600000,
"value": -41
},
{
"date": 1796076000000,
"value": -41
},
{
"date": 1796162400000,
"value": -44
},
{
"date": 1796248800000,
"value": -42
},
{
"date": 1796335200000,
"value": -39
},
{
"date": 1796594400000,
"value": -35
},
{
"date": 1796680800000,
"value": -32
},
{
"date": 1796767200000,
"value": -27
},
{
"date": 1796853600000,
"value": -22
},
{
"date": 1796940000000,
"value": -19
},
{
"date": 1797199200000,
"value": -23
},
{
"date": 1797285600000,
"value": -22
},
{
"date": 1797372000000,
"value": -19
},
{
"date": 1797458400000,
"value": -16
},
{
"date": 1797544800000,
"value": -16
},
{
"date": 1797804000000,
"value": -16
},
{
"date": 1797890400000,
"value": -13
},
{
"date": 1797976800000,
"value": -12
},
{
"date": 1798063200000,
"value": -11
},
{
"date": 1798149600000,
"value": -6
},
{
"date": 1798408800000,
"value": -7
},
{
"date": 1798495200000,
"value": -3
},
{
"date": 1798581600000,
"value": -3
},
{
"date": 1798668000000,
"value": -7
},
{
"date": 1798754400000,
"value": -7
},
{
"date": 1799013600000,
"value": -9
},
{
"date": 1799100000000,
"value": -13
},
{
"date": 1799186400000,
"value": -10
},
{
"date": 1799272800000,
"value": -9
},
{
"date": 1799359200000,
"value": -13
},
{
"date": 1799618400000,
"value": -10
},
{
"date": 1799704800000,
"value": -7
},
{
"date": 1799791200000,
"value": -5
},
{
"date": 1799877600000,
"value": -7
},
{
"date": 1799964000000,
"value": -4
},
{
"date": 1800223200000,
"value": -8
},
{
"date": 1800309600000,
"value": -10
},
{
"date": 1800396000000,
"value": -7
},
{
"date": 1800482400000,
"value": -9
},
{
"date": 1800568800000,
"value": -10
},
{
"date": 1800828000000,
"value": -9
},
{
"date": 1800914400000,
"value": -12
},
{
"date": 1801000800000,
"value": -12
},
{
"date": 1801087200000,
"value": -13
},
{
"date": 1801173600000,
"value": -12
},
{
"date": 1801432800000,
"value": -9
},
{
"date": 1801519200000,
"value": -13
},
{
"date": 1801605600000,
"value": -16
},
{
"date": 1801692000000,
"value": -17
},
{
"date": 1801778400000,
"value": -18
},
{
"date": 1802037600000,
"value": -14
},
{
"date": 1802124000000,
"value": -18
},
{
"date": 1802210400000,
"value": -21
},
{
"date": 1802296800000,
"value": -25
},
{
"date": 1802383200000,
"value": -26
},
{
"date": 1802642400000,
"value": -26
},
{
"date": 1802728800000,
"value": -29
},
{
"date": 1802815200000,
"value": -29
},
{
"date": 1802901600000,
"value": -32
},
{
"date": 1802988000000,
"value": -33
},
{
"date": 1803247200000,
"value": -34
},
{
"date": 1803333600000,
"value": -33
},
{
"date": 1803420000000,
"value": -31
},
{
"date": 1803506400000,
"value": -34
},
{
"date": 1803592800000,
"value": -31
},
{
"date": 1803852000000,
"value": -30
},
{
"date": 1803938400000,
"value": -33
},
{
"date": 1804024800000,
"value": -31
},
{
"date": 1804111200000,
"value": -33
},
{
"date": 1804197600000,
"value": -30
},
{
"date": 1804456800000,
"value": -30
},
{
"date": 1804543200000,
"value": -27
},
{
"date": 1804629600000,
"value": -27
},
{
"date": 1804716000000,
"value": -28
},
{
"date": 1804802400000,
"value": -25
},
{
"date": 1805061600000,
"value": -26
},
{
"date": 1805148000000,
"value": -24
},
{
"date": 1805234400000,
"value": -24
},
{
"date": 1805320800000,
"value": -26
},
{
"date": 1805407200000,
"value": -30
},
{
"date": 1805666400000,
"value": -28
},
{
"date": 1805752800000,
"value": -24
},
{
"date": 1805839200000,
"value": -20
},
{
"date": 1805925600000,
"value": -25
},
{
"date": 1806012000000,
"value": -26
},
{
"date": 1806267600000,
"value": -29
},
{
"date": 1806354000000,
"value": -31
},
{
"date": 1806440400000,
"value": -32
},
{
"date": 1806526800000,
"value": -30
},
{
"date": 1806613200000,
"value": -33
},
{
"date": 1806872400000,
"value": -30
},
{
"date": 1806958800000,
"value": -35
},
{
"date": 1807045200000,
"value": -31
},
{
"date": 1807131600000,
"value": -34
},
{
"date": 1807218000000,
"value": -38
},
{
"date": 1807477200000,
"value": -42
},
{
"date": 1807563600000,
"value": -46
},
{
"date": 1807650000000,
"value": -51
},
{
"date": 1807736400000,
"value": -55
},
{
"date": 1807822800000,
"value": -55
},
{
"date": 1808082000000,
"value": -50
},
{
"date": 1808168400000,
"value": -51
},
{
"date": 1808254800000,
"value": -48
},
{
"date": 1808341200000,
"value": -51
},
{
"date": 1808427600000,
"value": -47
},
{
"date": 1808686800000,
"value": -49
},
{
"date": 1808773200000,
"value": -53
},
{
"date": 1808859600000,
"value": -58
},
{
"date": 1808946000000,
"value": -56
},
{
"date": 1809032400000,
"value": -51
},
{
"date": 1809291600000,
"value": -53
},
{
"date": 1809378000000,
"value": -50
},
{
"date": 1809464400000,
"value": -49
},
{
"date": 1809550800000,
"value": -49
},
{
"date": 1809637200000,
"value": -46
},
{
"date": 1809896400000,
"value": -47
},
{
"date": 1809982800000,
"value": -46
},
{
"date": 1810069200000,
"value": -44
},
{
"date": 1810155600000,
"value": -48
},
{
"date": 1810242000000,
"value": -45
},
{
"date": 1810501200000,
"value": -42
},
{
"date": 1810587600000,
"value": -41
},
{
"date": 1810674000000,
"value": -36
},
{
"date": 1810760400000,
"value": -31
},
{
"date": 1810846800000,
"value": -35
},
{
"date": 1811106000000,
"value": -33
},
{
"date": 1811192400000,
"value": -33
},
{
"date": 1811278800000,
"value": -30
},
{
"date": 1811365200000,
"value": -28
},
{
"date": 1811451600000,
"value": -32
},
{
"date": 1811710800000,
"value": -31
},
{
"date": 1811797200000,
"value": -28
},
{
"date": 1811883600000,
"value": -24
},
{
"date": 1811970000000,
"value": -21
},
{
"date": 1812056400000,
"value": -20
},
{
"date": 1812315600000,
"value": -24
},
{
"date": 1812402000000,
"value": -21
},
{
"date": 1812488400000,
"value": -18
},
{
"date": 1812574800000,
"value": -14
},
{
"date": 1812661200000,
"value": -15
},
{
"date": 1812920400000,
"value": -15
},
{
"date": 1813006800000,
"value": -15
},
{
"date": 1813093200000,
"value": -13
},
{
"date": 1813179600000,
"value": -13
},
{
"date": 1813266000000,
"value": -12
},
{
"date": 1813525200000,
"value": -12
},
{
"date": 1813611600000,
"value": -17
},
{
"date": 1813698000000,
"value": -19
},
{
"date": 1813784400000,
"value": -16
},
{
"date": 1813870800000,
"value": -17
},
{
"date": 1814130000000,
"value": -16
},
{
"date": 1814216400000,
"value": -16
},
{
"date": 1814302800000,
"value": -20
},
{
"date": 1814389200000,
"value": -19
},
{
"date": 1814475600000,
"value": -15
},
{
"date": 1814734800000,
"value": -11
},
{
"date": 1814821200000,
"value": -15
},
{
"date": 1814907600000,
"value": -19
},
{
"date": 1814994000000,
"value": -17
},
{
"date": 1815080400000,
"value": -15
},
{
"date": 1815339600000,
"value": -19
},
{
"date": 1815426000000,
"value": -24
},
{
"date": 1815512400000,
"value": -19
},
{
"date": 1815598800000,
"value": -15
}
]
},
{
"axis-0": {
"type": "CategoryDateAxis",
"settings": {
"categoryField": "date",
"baseInterval": {
"timeUnit": "day",
"count": 1
},
"renderer": {
"type": "AxisRendererX",
"properties": {
"labels": {
"properties": {
"template": {
"settings": {
"minPosition": 0.01,
"maxPosition": 0.99
}
}
}
}
}
},
"tooltipDateFormat": "EEE, MMM d",
"tooltip": {
"type": "Tooltip"
}
},
"properties": {
"data": "#data-0"
}
}
},
{
"axis-1": {
"type": "ValueAxis",
"settings": {
"renderer": {
"type": "AxisRendererY"
}
}
}
},
{
"series-0": {
"type": "LineSeries",
"settings": {
"name": "Series",
"xAxis": "#axis-0",
"yAxis": "#axis-1",
"valueYField": "value",
"categoryXField": "date",
"tooltip": {
"type": "Tooltip"
}
},
"properties": {
"data": "#data-0"
}
}
}
]
}