Gauge Chart

A flexible and composable gauge chart (like a speedometer) built with D3.js and styled using Tailwind.

Example

70
Completed
Pending
Current Value: 70

Installation

./components/charts/GaugeChart.tsx

How It Works

The GaugeChart uses a compound component pattern for flexibility and composability. It is built using d3.scaleLinear to map values to angles and d3.arc to draw the SVG arcs.

The main components are:

  • GaugeChart.Container - The main container that provides context and layout for all child components
  • GaugeChart.Arc - Renders the gauge arcs (background and data segments)
  • GaugeChart.Needle - Renders the needle indicating the current value
  • GaugeChart.Label - Displays a central value label
  • GaugeChart.Legend - Optional legend showing segment labels and colors

Each segment can have its own color and label. The arcs and needle are animated using the useD3Transition hook. The chart automatically scales based on the defined min and max values.