Semicircle Gauge With Tiny Chart

Description

This component displays a modern semicircular gauge with a value arc, customizable header, and a tiny line chart beneath the gauge. The chart can show recent data points, and each point can be marked with a vertical dotted line. The gauge is highly customizable, supporting color stops, units, tick styling, and more. It’s ideal for dashboards and compact data displays.


Demo page

Download of source with example code

Function Variables Help

Function:
createSemicircleGaugeWithChartSVG(options)

Key Variables (Options):

VariableTypeDefaultDescription
widthNumber220Width of the SVG gauge (in pixels).
heightNumber220Height of the SVG gauge (in pixels).
semicircleHeightNumber90Height of the semicircle arc.
chartHeightNumber36Height of the chart area below the gauge.
semicircleYOffsetNumber70Vertical offset for the semicircle (moves gauge down).
chartYOffsetNumber90Vertical offset for the chart (moves chart down).
startAngleDegNumber180Start angle of the semicircle (degrees).
endAngleDegNumber360End angle of the semicircle (degrees).
valueNumber0Current value to display on the gauge.
minValueNumber0Minimum value of the gauge.
maxValueNumber100Maximum value of the gauge.
frontColorString“#ff5722”Default color for the value arc and chart line.
backColorString“#eee”Color for the background arc.
frontColorStopsArraynullArray of {value, color} for dynamic arc/chart coloring.
getFrontColorFunctionnullFunction to determine color based on value.
headerString“Measurement”Footer label below the gauge.
headerLabelString“Position”Header label at the top of the gauge.
headerLabelFontSizeNumber20Font size for the header label.
headerLabelColorString“#222”Color for the header label text.
headerLabelBgString“#e3e7ed”Background color for the header label area.
headerTopRadiusNumber14Border radius for the top of the header area.
valueFontSizeNumber28Font size for the main value.
headerFontSizeNumber18Font size for the footer label.
strokeWidthNumber14Thickness of the semicircle arc.
unitsString“”Units to display next to the value (e.g., “°C”, “%”).
chartDataArray[]Array of numbers for the chart line.
chartLineColorStringnullColor for the chart line (overrides dynamic color).
chartLineWidthNumber2Thickness of the chart line.
chartMinNumbernullMinimum value for the chart Y axis.
chartMaxNumbernullMaximum value for the chart Y axis.
tickColorString“#888”Color for the vertical y-ticks at each chart point.
tickAlphaNumber0.5Opacity (0-1) for the y-ticks.
tickWidthNumber2Thickness of the y-ticks.
showChartTicksBooleantrueShow or hide the vertical y-ticks.

Usage Example:

createSemicircleGaugeWithChartSVG({
  value: 22,
  minValue: 0,
  maxValue: 40,
  units: "°C",
  header: "Temperature",
  headerLabel: "Living Room",
  chartData: [20, 21, 22, 23, 22, 21, 22],
  frontColorStops: [
    { value: 10, color: "#2196f3" },
    { value: 25, color: "#4caf50" },
    { value: 40, color: "#f44336" }
  ],
  tickColor: "#2196f3",
  tickWidth: 3,
  showChartTicks: true,
  headerTopRadius: 16
});


Dynamical update gauge:

let value = 22;
let chartData = [20, 21, 22, 23, 22, 21, 22];

function updateGauge() {
  semicircleGaugeWithTinyChart("gauge1", {
    value: value,
    units: "°C",
    headerLabel: "Living Room",
    header: "Temperature",
    minValue: 0,
    maxValue: 40,
    frontColorStops: [
      { value: 10, color: "#2196f3" },
      { value: 25, color: "#4caf50" },
      { value: 40, color: "#f44336" }
    ],
    chartData: chartData,
    tickColor: "#2196f3",
    tickWidth: 3,
    headerTopRadius: 16
  });
}

// Initial render
updateGauge();

// Example: update every 2 seconds
setInterval(() => {
  // Simulate new value and chart data
  value = Math.round(15 + Math.random() * 20);
  chartData.push(value);
  if (chartData.length > 10) chartData.shift(); // keep last 10 points
  updateGauge();
}, 2000);

Leave a Reply