Carbon µPlot

Value + sparkline

Custom color — memory

Custom color — network

Sparkline only — showValue: false

Value only — sparkline: false

Live — setValue()

Small — size: 'sm'

Large centered — size: 'lg', align + verticalAlign

Center aligned — align: 'center'

Right aligned — align: 'right'

Value + sparkline


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: cpuSeries.at(-1),
  data: [timestamps, cpuSeries],
  label: 'CPU utilization',
  valueFormat: (value) => `${value.toFixed(0)}%`,
});

Custom color — memory


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: memUsed.at(-1),
  data: [timestamps, memUsed],
  label: 'Memory used',
  color: '#be95ff',
  valueFormat: (value) => `${(value / 1024).toFixed(1)} GB`,
});

Custom color — network


import { createStat } from 'carbon-uplot';

function formatNetworkRate(bytes) {
  if (bytes >= 1_048_576) return `${(bytes / 1_048_576).toFixed(1)} MB/s`;
  return `${(bytes / 1024).toFixed(0)} KB/s`;
}

createStat(el, {
  value: netInbound.at(-1),
  data: [timestamps, netInbound],
  label: 'Network in',
  color: '#42be65',
  valueFormat: formatNetworkRate,
});

Sparkline only — showValue: false


import { createStat } from 'carbon-uplot';

createStat(el, {
  data: [timestamps, cpuSeries],
  showValue: false,
  color: '#3ddbd9',
});

Value only — sparkline: false


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: 99.97,
  label: 'Uptime',
  sparkline: false,
  valueFormat: (value) => `${value}%`,
});

Live — setValue()


import { createStat } from 'carbon-uplot';

const stat = createStat(el, {
  value: 45,
  data: [timestamps, cpuSeries],
  label: 'CPU utilization (live)',
  color: '#ff832b',
  valueFormat: (value) => `${value.toFixed(0)}%`,
});

let liveValue = 45;
setInterval(() => {
  liveValue = Math.min(100, Math.max(0, liveValue + (Math.random() - 0.48) * 6));
  stat.setValue({ value: Math.round(liveValue) });
}, 1000);

Small — size: 'sm'


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: cpuSeries.at(-1),
  data: [timestamps, cpuSeries],
  label: 'CPU utilization',
  size: 'sm',
  valueFormat: (value) => `${value.toFixed(0)}%`,
});

Large centered — size, align, verticalAlign


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: 99.97,
  label: 'Uptime',
  sparkline: false,
  size: 'lg',
  align: 'center',
  verticalAlign: 'center',
  valueFormat: (value) => `${value}%`,
});

Center aligned — align: 'center'


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: memUsed.at(-1),
  data: [timestamps, memUsed],
  label: 'Memory used',
  color: '#be95ff',
  align: 'center',
  valueFormat: (value) => `${(value / 1024).toFixed(1)} GB`,
});

Right aligned — align: 'right'


import { createStat } from 'carbon-uplot';

createStat(el, {
  value: netInbound.at(-1),
  data: [timestamps, netInbound],
  label: 'Network in',
  color: '#42be65',
  align: 'right',
  valueFormat: formatNetworkRate,
});