Skip to content

Sparklines

Miniature charts without axes and chrome — for tables and cards:

Line:

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

// the same in an app: Charts.createSparkline({ container, data, field: 'value', type: 'line' })
export function createOptions(): ChartOptions {
  return buildSparklineOptions({
    data: getData(),
    field: 'value',
    type: 'line',
    height: 56,
  }) as ChartOptions;
}
ts
export function getData() {
  const values = [42, 45, 43, 49, 47, 52, 50, 56, 53, 59, 62, 60, 66, 64, 71, 69, 75, 78, 74, 82];
  return values.map((value) => ({ value }));
}

Area:

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

// the same in an app: Charts.createSparkline({ container, data, field: 'value', type: 'area' })
export function createOptions(): ChartOptions {
  return buildSparklineOptions({
    data: getData(),
    field: 'value',
    type: 'area',
    height: 56,
  }) as ChartOptions;
}
ts
export function getData() {
  const values = [42, 45, 43, 49, 47, 52, 50, 56, 53, 59, 62, 60, 66, 64, 71, 69, 75, 78, 74, 82];
  return values.map((value) => ({ value }));
}

Bar:

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

// the same in an app: Charts.createSparkline({ container, data, field: 'value', type: 'bar' })
export function createOptions(): ChartOptions {
  return buildSparklineOptions({
    data: getData(),
    field: 'value',
    type: 'bar',
    height: 56,
  }) as ChartOptions;
}
ts
export function getData() {
  const values = [42, 45, 43, 49, 47, 52, 50, 56, 53, 59, 62, 60, 66, 64, 71, 69, 75, 78, 74, 82];
  return values.map((value) => ({ value }));
}

Preset

ts
Charts.createSparkline({
  container,
  data, // [{ value: 12 }, ...]
  field: 'value',
  type: 'area', // 'line' | 'area' | 'bar'
  height: 40,
});

The preset builds regular options: a series + "bare" axes + minimal padding — the same thing can be assembled manually (see the config.ts tab above).

Options

OptionTypeDefaultDescription
type'line' | 'area' | 'bar''line'sparkline kind
containerdatacontainer, data, and value field (categories are indices)
datadatacontainer, data, and value field (categories are indices)
fielddatacontainer, data, and value field (categories are indices)
fillColorValuepalettecolors
strokeColorValuepalettecolors
widthPixelsfrom containerdimensions
heightPixelsfrom containerdimensions
themeThemeName | ThemeOptionsdefaulttheme