A gauge shows one value as a needle on a dial. Here the dial is one arc fading from green to red, so you see at once how close the value is to its maximum.
A gradient scale suits values that get gradually better or worse, like load, temperature or risk, where there is no sharp line between good and bad. The eye reads the color under the needle before the number. When fixed thresholds matter, use separate bands instead.
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, // no dragging
panY: false,
// a half circle, open at the bottom
startAngle: 180,
endAngle: 360
})
);
// A color on the theme's scale from its color for negative values (red, 0) through its warning color (yellow, 0.5) to
// its positive one (green, 1), so the arc follows the theme and dark mode
function scaleColor(position) {
return am5.Color.interpolateColors(position, [
root.interfaceColors.get("negative"),
root.interfaceColors.get("warning"),
root.interfaceColors.get("positive")
]);
}
// 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 axis line itself, 15px wide with a gradient, is the colored arc
strokeOpacity: 1,
strokeWidth: 15,
strokeGradient: am5.LinearGradient.new(root, {
rotation: 0, // left to right: green to red
stops: [
{ color: scaleColor(1) },
{ color: scaleColor(0.67) },
{ color: scaleColor(0.33) },
{ color: scaleColor(0) }
]
})
});
var xAxis = chart.xAxes.push(
am5xy.ValueAxis.new(root, {
maxDeviation: 0,
min: 0, // the scale runs from 0...
max: 100, // ...to 100...
strictMinMax: true, // ...exactly, not rounded out
renderer: axisRenderer
})
);
// Add clock hand
// https://www.amcharts.com/docs/v5/charts/radar-chart/gauge-charts/#Clock_hands
var axisDataItem = xAxis.makeDataItem({});
axisDataItem.set("value", 0); // the hand starts at 0
var bullet = axisDataItem.set("bullet", am5xy.AxisBullet.new(root, {
sprite: am5radar.ClockHand.new(root, {
radius: am5.percent(99) // the hand reaches almost to the outer edge
})
}));
xAxis.createAxisRange(axisDataItem);
// the hand's axis range would also draw a grid line at its value; hide it
axisDataItem.get("grid").set("visible", false);
// every two seconds, the hand moves to a random value from 0 to 100
setInterval(() => {
axisDataItem.animate({
key: "value",
to: Math.round(Math.random() * 100),
duration: 800,
easing: am5.ease.out(am5.ease.cubic) // fast start, slow finish
});
}, 2000);
// Make stuff animate on load
chart.appear(1000, 100);
{
"type": "RadarChart",
"settings": {
"panX": false,
"panY": false,
"startAngle": 180,
"endAngle": 360
},
"properties": {
"xAxes": [
"#axis-0"
]
},
"refs": [
{
"axis-0": {
"type": "ValueAxis",
"settings": {
"maxDeviation": 0,
"min": 0,
"max": 100,
"strictMinMax": true,
"renderer": {
"type": "AxisRendererCircular",
"settings": {
"innerRadius": -10,
"strokeOpacity": 1,
"strokeWidth": 15,
"strokeGradient": {
"type": "LinearGradient",
"settings": {
"rotation": 0,
"stops": [
{
"color": {
"type": "Color",
"value": "#50b300"
},
"opacity": 1,
"opacityInherited": true
},
{
"color": {
"type": "Color",
"value": "#babc1f"
},
"opacity": 1,
"opacityInherited": true
},
{
"color": {
"type": "Color",
"value": "#dc801f"
},
"opacity": 1,
"opacityInherited": true
},
{
"color": {
"type": "Color",
"value": "#b30000"
},
"opacity": 1,
"opacityInherited": true
}
]
}
}
}
}
}
}
},
{
"axisRange-0": {
"axis": "#axis-0",
"settings": {
"value": 83.88187714467189,
"bullet": {
"type": "AxisBullet",
"settings": {
"sprite": {
"type": "ClockHand",
"settings": {
"radius": {
"type": "Percent",
"value": 99
}
}
}
}
},
"grid": {
"type": "Grid",
"settings": {
"visible": false
}
}
},
"__parseLogic": "axisRange"
}
}
]
}