A clock with a dial inside a dial: hours and minutes on the outer face, seconds on a small inner face, and today’s date in the middle.
An inner dial adds a second scale without a second chart: here the seconds, but it could be a stopwatch or a second time zone. Each dial is its own axis with its own radius, so the two can count in different units.
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/radar-chart/
var chart = root.container.children.push(am5radar.RadarChart.new(root, {
panX: false, // the clock doesn't pan when dragged
panY: false
}));
// Create axis and its renderer
// https://www.amcharts.com/docs/v5/charts/radar-chart/gauge-charts/#Axes
var axisRenderer = am5radar.AxisRendererCircular.new(root, {
innerRadius: -10, // the grid lines are 10px marks in from the rim
strokeOpacity: 1, // a solid rim...
strokeWidth: 8, // ...8px thick
minGridDistance: 10 // a mark and a number for every hour, down to 10px apart
});
var xAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, {
maxDeviation: 0, // the scale can't be panned past its ends
min: 0, // the dial runs from 0...
max: 12, // ...to 12 hours
strictMinMax: true, // exactly, not rounded out
renderer: axisRenderer,
maxPrecision: 0 // whole numbers only
}));
// second axis
// https://www.amcharts.com/docs/v5/charts/radar-chart/gauge-charts/#Axes
// the small seconds dial, at 40% of the clock's radius: a 0 to 60 scale shown only by its ticks
var secondAxisRenderer = am5radar.AxisRendererCircular.new(root, {
innerRadius: -10,
radius: am5.percent(40),
strokeOpacity: 0, // no rim line
minGridDistance: 1 // a tick for every second
});
var secondXAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, {
maxDeviation: 0,
min: 0, // the seconds dial runs from 0...
max: 60, // ...to 60
strictMinMax: true,
renderer: secondAxisRenderer,
maxPrecision: 0 // whole numbers only
}));
// hides 0 value
axisRenderer.labels.template.setAll({
minPosition: 0.02,
textType: "adjusted", // upright numbers, kept clear of the rim
inside: true, // inside the rim...
radius: 25 // ...25px in from it
});
axisRenderer.grid.template.set("strokeOpacity", 1); // solid hour marks
secondAxisRenderer.labels.template.setAll({
forceHidden: true // no numbers on the seconds dial...
});
secondAxisRenderer.grid.template.setAll({
forceHidden: true // ...and no grid lines
});
secondAxisRenderer.ticks.template.setAll({
strokeOpacity: 1, // solid ticks
minPosition: 0.01, // no tick at 0, where it would sit on 60's
visible: true, // ticks are hidden by default
inside: true, // pointing inward
length: 10 // 10px long
});
// Add clock hands
// https://www.amcharts.com/docs/v5/charts/radar-chart/gauge-charts/#Clock_hands
// hour
var hourDataItem = xAxis.makeDataItem({});
var hourHand = am5radar.ClockHand.new(root, {
radius: am5.percent(70), // the short hand...
topWidth: 14, // ...14px wide
bottomWidth: 14, // all along its length
// the hand starts just outside the seconds dial
innerRadius: am5.percent(43),
pinRadius: 0, // no pin in the middle
layer: 5 // drawn on a layer above the rest of the chart
})
hourDataItem.set("bullet", am5xy.AxisBullet.new(root, {
sprite: hourHand
}));
xAxis.createAxisRange(hourDataItem);
hourDataItem.get("grid").set("visible", false); // hide the range's own grid line
// minutes
var minutesDataItem = xAxis.makeDataItem({});
var minutesHand = am5radar.ClockHand.new(root, {
radius: am5.percent(85), // longer than the hour hand...
topWidth: 10, // ...and thinner
bottomWidth: 10,
innerRadius: am5.percent(43),
pinRadius: 0,
layer: 5
})
minutesDataItem.set("bullet", am5xy.AxisBullet.new(root, {
sprite: minutesHand
}));
xAxis.createAxisRange(minutesDataItem);
minutesDataItem.get("grid").set("visible", false); // hide the range's own grid line
// seconds
var secondsDataItem = xAxis.makeDataItem({});
var secondsHand = am5radar.ClockHand.new(root, {
radius: am5.percent(40), // reaches the seconds dial's ticks...
innerRadius: -10, // ...and is just their 10px length
topWidth: 5, // 5px wide
bottomWidth: 5,
pinRadius: 0,
layer: 5
})
secondsHand.hand.set("fill", am5.color(0xff0000)); // red
secondsHand.pin.set("fill", am5.color(0xff0000));
secondsDataItem.set("bullet", am5xy.AxisBullet.new(root, {
sprite: secondsHand
}));
xAxis.createAxisRange(secondsDataItem);
secondsDataItem.get("grid").set("visible", false); // hide the range's own grid line
// date label, in the middle of the seconds dial
var label = chart.radarContainer.children.push(am5.Label.new(root, {
fontSize: "1.5em", // 1.5 times the chart's text size
centerX: am5.p50, // centered on the dial's center
centerY: am5.p50,
oversizedBehavior: "fit" // shrinks to fit its maxWidth
}));
// On a small clock, shrink the date to fit inside the seconds dial
chart.plotContainer.events.on("boundschanged", function() {
// the dial is 40% of the clock's radius; leave room for its ticks
label.set("maxWidth", chart.getPrivate("radius", 0) * 0.8 - 30);
});
// move the hands every second
setInterval(function() {
updateHands(300) // the seconds hand takes 0.3 seconds to step
}, 1000);
// point the hands at the current time; duration is the seconds hand's step
function updateHands(duration) {
// get current date
var date = new Date();
// 0 to 11: the axis stops at 12, so 12:30 (12.5) would not be drawn
var hours = date.getHours() % 12;
var minutes = date.getMinutes();
var seconds = date.getSeconds();
// set hours
hourDataItem.set("value", hours + minutes / 60 + seconds / 60 / 60);
// set minutes
// all hands sit on the 12-hour axis, so minutes and seconds are scaled to 0-12
minutesDataItem.set("value", 12 * (minutes + seconds / 60) / 60);
// set seconds
var current = secondsDataItem.get("value");
var value = 12 * date.getSeconds() / 60;
// otherwise animation will go from 59 to 0 and the hand will move backwards
if (value == 0) {
value = 11.999;
}
// if it's more than 11.99, set it to 0
if (current > 11.99) {
current = 0;
}
secondsDataItem.animate({
key: "value",
from: current,
to: value,
duration: duration
});
label.set("text", chart.getDateFormatter().format(date, "MMM dd")) // the date, like Oct 07
}
updateHands(0); // set the hands at once on load
// Make stuff animate on load
chart.appear(1000, 100);
// Set the hands straight away when the page is shown again: timers slow down in a background tab
function onVisibilityChange() {
if (root.isDisposed()) {
// the chart is gone: stop listening
document.removeEventListener("visibilitychange", onVisibilityChange);
} else {
updateHands(0);
}
}
document.addEventListener("visibilitychange", onVisibilityChange);
{
"type": "RadarChart",
"settings": {
"panX": false,
"panY": false
},
"properties": {
"xAxes": [
"#axis-0",
"#axis-1"
],
"radarContainer": {
"children": [
{
"type": "Label",
"settings": {
"fontSize": "1.5em",
"centerX": {
"type": "Percent",
"value": 50
},
"centerY": {
"type": "Percent",
"value": 50
},
"oversizedBehavior": "fit",
"text": "Oct 05",
"maxWidth": 131.28000000000003
}
}
]
}
},
"refs": [
{
"axis-0": {
"type": "ValueAxis",
"settings": {
"maxDeviation": 0,
"min": 0,
"max": 12,
"strictMinMax": true,
"renderer": {
"type": "AxisRendererCircular",
"settings": {
"innerRadius": -10,
"strokeOpacity": 1,
"strokeWidth": 8,
"minGridDistance": 10
},
"properties": {
"labels": {
"properties": {
"template": {
"settings": {
"minPosition": 0.02,
"textType": "adjusted",
"inside": true,
"radius": 25
}
}
}
},
"grid": {
"properties": {
"template": {
"settings": {
"strokeOpacity": 1
}
}
}
}
}
},
"maxPrecision": 0
}
}
},
{
"axis-1": {
"type": "ValueAxis",
"settings": {
"maxDeviation": 0,
"min": 0,
"max": 60,
"strictMinMax": true,
"renderer": {
"type": "AxisRendererCircular",
"settings": {
"innerRadius": -10,
"radius": {
"type": "Percent",
"value": 40
},
"strokeOpacity": 0,
"minGridDistance": 1
},
"properties": {
"labels": {
"properties": {
"template": {
"settings": {
"forceHidden": true
}
}
}
},
"grid": {
"properties": {
"template": {
"settings": {
"forceHidden": true
}
}
}
},
"ticks": {
"properties": {
"template": {
"settings": {
"strokeOpacity": 1,
"minPosition": 0.01,
"visible": true,
"inside": true,
"length": 10
}
}
}
}
}
},
"maxPrecision": 0
}
}
},
{
"axisRange-0": {
"axis": "#axis-0",
"settings": {
"bullet": {
"type": "AxisBullet",
"settings": {
"sprite": {
"type": "ClockHand",
"settings": {
"radius": {
"type": "Percent",
"value": 70
},
"topWidth": 14,
"bottomWidth": 14,
"innerRadius": {
"type": "Percent",
"value": 43
},
"pinRadius": 0,
"layer": 5
}
}
}
},
"label": {
"type": "AxisLabelRadial",
"settings": {
"centerX": {
"type": "Percent",
"value": 50
},
"centerY": {
"type": "Percent",
"value": 50
},
"x": -168.48039250386654,
"y": -52.93314029738914
}
},
"grid": {
"type": "Grid",
"settings": {
"visible": false
}
},
"value": 9.581388888888888
},
"__parseLogic": "axisRange"
}
},
{
"axisRange-1": {
"axis": "#axis-0",
"settings": {
"bullet": {
"type": "AxisBullet",
"settings": {
"sprite": {
"type": "ClockHand",
"settings": {
"radius": {
"type": "Percent",
"value": 85
},
"topWidth": 10,
"bottomWidth": 10,
"innerRadius": {
"type": "Percent",
"value": 43
},
"pinRadius": 0,
"layer": 5
}
}
}
},
"label": {
"type": "AxisLabelRadial",
"settings": {
"centerX": {
"type": "Percent",
"value": 50
},
"centerY": {
"type": "Percent",
"value": 50
},
"x": -86.42494097884627,
"y": 154.0074335115125
}
},
"grid": {
"type": "Grid",
"settings": {
"visible": false
}
},
"value": 6.9766666666666675
},
"__parseLogic": "axisRange"
}
},
{
"axisRange-2": {
"axis": "#axis-0",
"settings": {
"bullet": {
"type": "AxisBullet",
"settings": {
"sprite": {
"type": "ClockHand",
"settings": {
"radius": {
"type": "Percent",
"value": 40
},
"innerRadius": -10,
"topWidth": 5,
"bottomWidth": 5,
"pinRadius": 0,
"layer": 5
},
"properties": {
"hand": {
"settings": {
"fill": {
"type": "Color",
"value": "#ff0000"
}
}
},
"pin": {
"settings": {
"fill": {
"type": "Color",
"value": "#ff0000"
}
}
}
}
}
}
},
"label": {
"type": "AxisLabelRadial",
"settings": {
"centerX": {
"type": "Percent",
"value": 50
},
"centerY": {
"type": "Percent",
"value": 50
},
"x": -118.16846508297436,
"y": -131.23937617930787
}
},
"grid": {
"type": "Grid",
"settings": {
"visible": false
}
},
"value": 10.6
},
"__parseLogic": "axisRange"
}
}
]
}