Skip to content

Gauge

Creates a gauge (speedometer) from an array of data: a single dial that reads each row’s value against its domain. One row shows its value under the hub; several rows each get a needle (or a progress track), identified by the legend and tooltips.

Each row becomes a dial that reads its value against domain. The default 240° sweep (startAngle -120 to endAngle 120) leaves room for the value under the needle’s hub.

const config = {
  data: [{id: "Speed", value: 72}],
  domain: [0, 100],
};

bands paints colored zones along the track. Each band ends at its max and starts where the previous one ended, so a list of thresholds is enough.

const bands = [
  {max: 60, color: "#2f9e44"},
  {max: 85, color: "#f59f00"},
  {color: "#e03131"},
];

const config = {
  data: [{id: "Engine Temperature", value: 78}],
  domain: [0, 100],
  bands,
};

indicator("progress") fills the track up to the value instead of pointing a needle at it; bands move to a thin strip inside the track.

indicator

How each row shows its value: "needle" (default) points a needle at it; "progress" fills a track from the minimum up to it, with one concentric track per row stepping inward.

Several rows share one dial, with a needle per row in the row’s color. The legend names each needle and its tooltip gives the value. Values outside the domain pin the needle to the nearest end.

const bands = [
  {max: 60, color: "#2f9e44"},
  {max: 85, color: "#f59f00"},
  {color: "#e03131"},
];

const config = {
  data: [
    {id: "North", value: 42},
    {id: "South", value: 77},
    {id: "East", value: 120},
    {id: "West", value: -5},
  ],
  domain: [0, 100],
  bands,
};

With indicator("progress"), each row gets its own track, stepping inward from the outer edge in data order.

indicator

How each row shows its value: "needle" (default) points a needle at it; "progress" fills a track from the minimum up to it, with one concentric track per row stepping inward.

startAngle and endAngle set the sweep in degrees clockwise from 12 o’clock. Without a domain, the range comes from the data, rounded out to line up with the ticks.

const config = {
  data: [{id: "Pressure", value: 3.4}],
  startAngle: -90,
  endAngle: 90,
  ticks: 4,
};

Configuration

import {Gauge} from "@d3plus/core";

Extends Viz.

activefalse | function

The active callback function for highlighting shapes.

axisConfig{shapeConfig: {fill, stroke, strokeWidth, labelConfig}}

Styles the dial: shapeConfig.fill colors the track, shapeConfig.stroke/strokeWidth the tick marks, and shapeConfig.labelConfig (fontColor, fontFamily, fontSize) the tick, value, and name labels. Unset colors follow the chart's background, so the dial reads on light and dark themes alike.

bandsGaugeBand[]Default []

Colored zones along the dial, in order: [{max: 60, color: "#2f9e44"}, {max: 85, color: "#f59f00"}, {color: "#e03131"}]. Each band starts at its own min, else where the previous band ended; it ends at its own max, else the domain's maximum. Bands are drawn on the track behind the needles, or as a thin strip inside the progress tracks.

classNamestring | array.<string> | undefined

CSS classes added to the outermost element this chart or component draws into, next to its fixed d3plus classes, so page CSS can target it: a chart's root <svg class="d3plus-viz"> (its <canvas> with the Canvas renderer) and a standalone component's <svg>. Takes a space-separated string or an array. A new value replaces the classes the previous one added; unset adds none. Tooltips take their own tooltipConfig.className.

colorDefaultscolordefaultsconfig

Overrides the default colors used when assigning fills from data and choosing legible text colors: dark and light (the text colors picked for contrast against a background), missing (null/undefined values), on/off (true/false values), sequential (the anchor hue for magnitude ramps), and scale (the categorical palette, given as a d3 ordinal scale or an array of colors). Keys are merged into the current defaults, and a Viz passes its overrides down to the shapes and components it draws.

configd3plusconfig

Methods that correspond to the key/value pairs and returns this class.

datastring | array.&lt;datapoint&gt; | object

The primary data array used to draw the visualization. The value passed should be an Array of objects or a String representing a filepath or URL to be loaded. The following filetypes are supported: csv, tsv, txt, and json.

If your data URL needs specific headers to be set, an Object with a "url" and "headers" (or any other fetch request option) may also be passed. An Object with any other key is a data row, not a request.

Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final array of obejcts to be used as the primary data array. For example, some JSON APIs return the headers split from the data values to save bandwidth. These would need be joined using a custom formatter.

If you would like to specify certain configuration options based on the yet-to-be-loaded data, you can also return a full config object from the data formatter (including the new data array as a key in the object).

To re-fetch a URL on an interval and redraw when its data changes, set dataPollingInterval; each poll runs the same formatter.

Defaults to an empty array ([]).

domain[number, number]

The [min, max] the dial spans. Either end may be left undefined to come from the data (and any band edges), rounded outward to nice numbers and always including zero. Values outside the domain pin the indicator to the nearest end.

endAngleunknownDefault 120

The angle, in degrees clockwise from 12 o'clock, where the dial ends.

facetstring | false | function

Splits the chart into small multiples: a grid of equally sized panels, one per distinct value of this data key or accessor, each drawing the chart for that value's rows. The panels share one legend, color scale, title, and timeline, color each series the same way, and hover, tooltips, and legend clicks apply across all of them. Pass false to draw a single chart. See facetConfig for the grid's layout and shared scales.

facetConfigfacetconfig

Configuration for small multiples (see facet), merged into the current config: - columns / rows: the grid's shape. Chosen by default to make the panels as large as the chart's shape allows. - padding: the space between panels, in pixels (default 20). - sort: panel order — "ascending" (default), "descending", "data" (first appearance), a comparator over facet values, or an Array of values. - scales: "shared" (default) gives every panel of a chart with axes the same x/y domains; "independent" fits each panel to its own rows. Funnel defaults to "independent" (each panel sized to its own widest stage); "shared" sizes every panel against the widest stage across all panels. PolarArea and RadialBar default to "independent" (each panel's rings and ticks fit its own values); "shared" gives every panel the same value domain. - axes: with shared scales, "outer" (default) labels the axes only along the grid's left and bottom edges; "all" labels every panel. An object sets each axis on its own, as in {x: "all", y: "outer"}: every panel labels its x axis, only the left column labels its y axis, and the panels' plot areas line up. BumpChart defaults to "all", and Marimekko labels its categories on every panel and its 0–100% share axis only along the outer edge, even with independent scales. - title: a (value, data) => string function for each panel's title, or false to hide panel titles. - titleConfig: TextBox config for the panel titles (fontSize, fontWeight, fontColor, textAnchor, padding, …).

fontFamilystring | array.&lt;string&gt;

The font family used throughout the visualization.

groupBystring | function | array.&lt;string | function&gt;

Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.

highlightfalse | function

Persistently emphasizes the data points matching the given predicate: the matching marks keep their color while every other mark is de-emphasized to a neutral gray (the "emphasis" form — highlight one series, gray the rest). Unlike hover/active (transient, opacity-based), highlight is a standing state that survives pointer movement. Pass false to clear it.

hoverfalse | function

The hover callback function for highlighting shapes on mouseover.

indicator"needle" | "progress"Default "needle"

How each row shows its value: "needle" (default) points a needle at it; "progress" fills a track from the minimum up to it, with one concentric track per row stepping inward.

localestring | object

The locale used for all text and number formatting. Supports the locales defined in d3plus-format. The locale can be a complex Object, a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale.

minorTicksunknownDefault true

Whether to draw unlabeled minor ticks between the major ticks.

onstring

Event listener for the specified event typenames. Mirrors the core d3-selection behavior.

parentunknown

Parent config used by the wrapper.

renderfunction

Draws the visualization given the specified configuration.

rendererboolean | "svg" | "canvas"

Selects which @d3plus/render backend paints the visible output. "svg" = SvgRenderer (default), "canvas" = CanvasRenderer. Boolean arguments both normalize to "svg".

selectstring | htmlelement

The SVG container element as a d3 selector or DOM element. Defaults to undefined.

shapeConfigd3plusconfigDefault {stroke: () => chartBackground(viz), strokeWidth: () => viz.schema.indicator === "progress" ? 0 : NEEDLE_OUTLINE}

Configuration object with key/value pairs applied as method calls on each shape.

Outlines each needle (and a single needle's hub) in the chart's background color, so a needle stays distinct over a band of its own color. Progress arcs sit in their own tracks and get no outline. Set shapeConfig.stroke/strokeWidth to override; hovering a needle swaps the outline for the usual darker, wider one.

startAngleunknownDefault -120

The angle, in degrees clockwise from 12 o'clock, where the dial starts.

thicknessunknownDefault 0.2

The track's thickness, as a fraction of the dial's radius.

thresholdnumber | function

The threshold value for bucketing small data points together, as a share of the total. On a stacked Plot, the series whose summed value across every position is under that share of the whole chart's total merge into one series, stacked on top. A bucket needs at least two items, and its tooltips list them. Off (0) by default on Plot charts.

thresholdKeystring | function

Accessor for the value used in the threshold algorithm. A stacked Plot defaults to its stacked value.

tickFormatfunctionDefault function

Formats the tick labels. Defaults to the locale's abbreviated number format.

ticksnumber | number[] | false

The major ticks: a target count, an explicit array of values, or false for none. Counted ticks always label both ends of the domain.

timestring | false | function

Accessor function or string key for the time dimension of each data point.

timelineDefaultstring | date | array.&lt;string | date&gt;

The starting time or range for the timeline. Can be a single Date/String, or an Array of 2 values representing the min and max.

tooltipConfigtooltipconfig

Configuration for the tooltip component.

totalstring | boolean | function

Accessor function or string key for the total value displayed in the visualization.

translatefunction

Defines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.

valuestring | functionDefault "value"

Accessor function or string key for each row's value (a number is used as a constant value for every row).

valueFormatfunctionDefault function

Formats the value shown under the hub and in each tooltip, as (value, datum) => string. Defaults to the locale's abbreviated number format.

zoombooleanDefault false

Zooming and panning don't help read a dial, so they're off by default.