Skip to content

Gauges ​

Gauges are series without data: the value is set directly in the options.

Radial gauge ​

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Cluster load' },
    series: [
      {
        type: 'radial-gauge',
        value: 67,
        scale: { min: 0, max: 100 },
        segments: [
          { to: 60, color: '#21a06c' },
          { to: 85, color: '#f4a236' },
          { to: 100, color: '#e5484d' },
        ],
        label: { formatter: (value) => `${value}%` },
      },
    ],
  };
}
ts
/** The gauge does not use data — the value is set in options. */
export function getData() {
  return [];
}

Linear gauge ​

A linear scale with a target mark (bullet):

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Plan completion' },
    series: [
      {
        type: 'linear-gauge',
        value: 1240,
        target: 1500,
        scale: { min: 0, max: 2000 },
      },
    ],
    height: 180,
  };
}
ts
/** The gauge does not use data — the value is set in options. */
export function getData() {
  return [];
}

Target on a linear gauge ​

target — the target mark, thickness — the bar height:

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Sales vs target' },
    series: [
      {
        type: 'linear-gauge',
        value: 7.4,
        target: 9,
        scale: { min: 0, max: 12 },
        thickness: 22,
        label: { formatter: (value) => `${value.toFixed(1)} of 12M` },
      },
    ],
  };
}
ts
export function getData() {
  return [];
}

Vertical gauge with segments ​

orientation: 'vertical' stands the scale on end. With segments the track carries the qualitative ranges and the value rides over them as a thinner bar, the way a bullet chart reads; label.formatter and ticks.formatter say what the numbers read as:

ts
{
  type: 'linear-gauge',
  orientation: 'vertical',
  value: 15_400_000,
  target: 18_000_000,
  scale: { min: 0, max: 24_000_000 },
  segments: [
    { to: 8_000_000, color: '#e5484d' },
    { to: 16_000_000, color: '#f4a236' },
    { to: 24_000_000, color: '#21a06c' },
  ],
  label: { formatter: (value) => `${(value / 1e6).toFixed(1)} mln m³` },
  ticks: { formatter: (value) => `${value / 1e6} mln` },
}
ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Reservoir level' },
    series: [
      {
        type: 'linear-gauge',
        orientation: 'vertical',
        value: 15_400_000,
        target: 18_000_000,
        scale: { min: 0, max: 24_000_000 },
        segments: [
          { to: 8_000_000, color: '#e5484d' },
          { to: 16_000_000, color: '#f4a236' },
          { to: 24_000_000, color: '#21a06c' },
        ],
        label: { formatter: (value) => `${(value / 1e6).toFixed(1)} mln m³` },
        ticks: { formatter: (value) => `${value / 1e6} mln` },
      },
    ],
  };
}
ts
/** The gauge does not use data — the value is set in options. */
export function getData() {
  return [];
}

Preset ​

ts
Charts.createGauge({
  container,
  type: 'radial-gauge', // | 'linear-gauge'
  value: 67,
  scale: { min: 0, max: 100 },
  title: 'Cluster load',
});
OptionTypeDescription
valuenumbercurrent value
needleSwitchableneedle (radial)
targetnumbertarget mark

Full option list ​

Both gauges take segments and target; orientation belongs to the linear one, the angles and the needle to the radial one. A gauge sizes its own text and its own thickness against the room it was given — every option below only comes in when the default is not what the tile calls for.

OptionTypeDefaultDescription
startAngleDegrees-110radial-gauge arc
endAngleDegrees110radial-gauge arc
orientation'horizontal' | 'vertical''horizontal'which way a linear-gauge scale runs
fillsColorValue[]palettecolors (when segments is not set)
thicknessPixelsa share of the room, 14…36bar/arc thickness
scale.minnumber0scale minimum
scale.maxnumber100scale maximum
targetnumber—target mark across the bar/ring
targetColorColorValuetheme foregroundcolor of the target mark
segments[]{ to, color }[]—color zones of the scale
label.enabledbooleantruevalue in the center/alongside
label.formatter(value) => stringthe valuevalue format
label.fontSizePixelsfollows the gaugevalue size
label.fontWeightFontWeight'bold'value weight
label.fontFamilystringtheme fontvalue face
label.colorColorValuetheme foregroundvalue color
ticks.enabledbooleantruelabels of the two ends of the scale
ticks.formatter(value) => stringthe boundformat of the bounds
ticks.fontSizePixelstheme label sizesize of the bounds
ticks.fontWeightFontWeight'normal'weight of the bounds
ticks.fontFamilystringtheme fontface of the bounds
ticks.colorColorValuetheme mutedcolor of the bounds

Options ​

Options common to all series (name, showInLegend, tooltip.renderer, …) are covered in Common series options.

tooltip.renderer receives NodeTooltipRendererParams — { label, value, share, color }, where value is the number the gauge shows.