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 [];
}

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 (linear)

Full option list

OptionTypeDefaultDescription
startAngleDegrees-110radial-gauge arc
endAngleDegrees110radial-gauge arc
fillsColorValue[]palettecolors (when segments is not set)
thicknessPixelslinear 16; radial auto (min 10)bar/arc thickness
scale.minnumber0scale minimum
scale.maxnumber100scale maximum
label.enabledbooleantruevalue in the center/alongside
label.formatter(value) => stringthe valuevalue format
segments[]{ to, color }[]radial-gauge color zones

Options

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