Loading...
A gauge chart is a semicircular or circular visualization that displays data within a specified range. It uses a pointer and scale to simulate physical gauges (such as speedometers or pressure gauges), intuitively expressing the relationship between the data value and target values or thresholds.
Gauge charts are particularly suitable for displaying progress, completion rates, or single values within a certain range. Different value ranges can be distinguished by colors, enhancing data readability and warning effects.
In data visualization, gauge charts are commonly used to represent key performance indicators (KPIs), goal achievement, system status monitoring, etc., helping users quickly understand how data performs against preset targets.
Other Names: Dial Chart, Speedometer Chart
Chart Type | Basic Gauge Chart |
---|---|
Suitable Data | Single value data: current value, target/total value, optional thresholds |
Function | Display data position within a specified range using pointer and scale |
Data-to-Visual Mapping | Current value maps to pointer position Total value defines scale range Optional thresholds map to color sections |
Suitable Scenarios | Expressing completion degree or status of a single metric within a target range |
Example 1: Suitable for showing goal completion progress
The gauge chart below shows the completion status of a scoring metric, with a current score of 120 out of a total of 400.
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',autoFit: true,});chart.options({type: 'gauge',data: {value: {target: 120,total: 400,name: 'score',},},legend: false});chart.render();
Explanation:
target
represents the current score, mapped to the pointer position on the gaugetotal
represents the total score, defining the scale range of the gaugename
represents the name of this metricExample 2: Suitable for multi-threshold status monitoring
Gauge charts can clearly show which range the data falls into by setting multiple thresholds and different colors, suitable for system status monitoring, performance evaluation, and other scenarios.
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',autoFit: true,});chart.options({type: 'gauge',data: {value: {target: 159,total: 400,name: 'score',thresholds: [100, 200, 400],},},scale: {color: {range: ['#F4664A', '#FAAD14', 'green'],},},style: {textContent: (target, total) => `Score: ${target}\nPercentage: ${(target / total * 100).toFixed(0)}%`,},legend: false});chart.render();
Explanation:
thresholds
: 0-100, 100-200, and 200-400Example 3: Customizing gauge chart styles
Gauge charts support highly customizable styles that can be adjusted based on business requirements.
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',autoFit: true,});chart.options({type: 'gauge',data: {value: {target: 159,total: 400,name: 'score',thresholds: [100, 200, 400],},},scale: {color: {range: ['#F4664A', '#FAAD14', 'green'],},},style: {arcShape: 'round',arcLineWidth: 2,arcStroke: '#fff',textContent: (target, total) => `Score: ${target}\nPercentage: ${(target / total * 100).toFixed(0)}%`,},legend: false});chart.render();
Explanation:
arcShape: 'round'
sets the arc shape to have rounded cornersarcLineWidth
and arcStroke
set the line width and border color of the arcExample 1: Not suitable for multi-dimensional data comparison
Gauge charts are primarily suitable for displaying a single metric value within a certain range and are not suitable for direct comparison of multi-dimensional data. If you need to compare data across multiple categories or dimensions, bar charts or radar charts might be better choices.
Example 2: Not suitable for time-series trends
Gauge charts display static data at a specific moment and cannot effectively express how data changes over time. For data that needs to show changes over time, line charts or area charts are more appropriate.
Gauge charts support customizing the pointer shape, allowing you to adjust the pointer style according to business scenarios, making the chart more personalized.
import { Chart } from '@antv/g2';import { Path } from '@antv/g';const chart = new Chart({container: 'container',autoFit: true});function getOrigin(points) {if (points.length === 1) return points[0];const [[x0, y0, z0 = 0], [x2, y2, z2 = 0]] = points;return [(x0 + x2) / 2, (y0 + y2) / 2, (z0 + z2) / 2];}// Custom pointer shapeconst customShape = (style) => {return (points, value, coordinate, theme) => {// Get the center coordinates of geometric pointsconst [x, y] = getOrigin(points);const [cx, cy] = coordinate.getCenter();// Calculate pointer direction angleconst angle = Math.atan2(y - cy, x - cx);const length = 100; // Pointer lengthconst width = 8; // Pointer base width// Construct triangular pointer pathreturn new Path({style: {d: [['M', cx + Math.cos(angle) * length, cy + Math.sin(angle) * length], // Top point['L',cx + Math.cos(angle + Math.PI / 2) * width,cy + Math.sin(angle + Math.PI / 2) * width,], // Bottom left point['L',cx + Math.cos(angle - Math.PI / 2) * width,cy + Math.sin(angle - Math.PI / 2) * width,], // Bottom right point['Z'], // Close path],fill: '#30BF78', // Fill color},});};};chart.options({type: 'gauge',data: {value: {target: 159,total: 424,name: 'score',},},style: {pointerShape: customShape,pinShape: false,textContent: (target, total) => {return `Score: ${target}\nPercentage: ${(target / total * 100).toFixed(0)}%`;},}});chart.render();
Explanation:
pointerShape
customizes the gauge pointer shape as a trianglepinShape: false
removes the circle at the center of the pointer