Skip to content

Figures ​

A figure counts, stops exactly where you said, and compares itself.

In the text of a page ​

ts
import { createFigure } from 'nervure/figure';

const sales = createFigure(host, {
  value: 1284500,
  label: 'Sales',
  format: { currency: 'EUR', compact: true, letters: ['K', 'M', 'B'] },
  compare: [
    { value: 1100000, label: 'last year' },
    { value: 1300000, label: 'target', show: 'both' },
  ],
  animation: { start: 'visible', duration: 1800 },
});

sales.update({ value: 1310000 });  // counts from the figure shown
html
<script src="https://cdn.jsdelivr.net/npm/nervure"></script>
<nervure-figure value="1284500" currency="EUR" compact previous="1100000" previous-label="last year"></nervure-figure>
tsx
import { Figure } from 'nervure/react';

<Figure value={sales} format={{ currency: 'EUR', compact: true }} compare={{ value: lastYear, label: 'last year' }} />
vue
<NervureFigure :options="{ value: sales, format: { currency: 'EUR' } }" />

In a card, with a trend ​

The kpi chart takes the same fields, and trend. The figures of gauge, liquid, speedometer, thermometer and progress count too.

Formats ​

Any chart takes format, and each axis its own.

ts
createChart(host, { ...spec, format: { currency: 'TND' }, axes: [{ format: { compact: true } }] });
OptionWrites
currency: 'EUR'any ISO code; the symbol and its place follow locale. CURRENCIES lists forty of them
percent: true64 as 64 %
percent: 'ratio'0.64 as 64 %
unit: 'kg'a unit after the figure
prefix, suffixyour own text
decimals: 1, decimals: [0, 2]digits after the point
compact: trueshort from 1,000
compact: 10000short from 10,000
letters: ['K', 'M', 'B', 'T']your letters, instead of those of the language
sign: true+ before positive figures
locale: 'fr'another language than the chart
ts
import { formatter } from 'nervure';

const euros = formatter({ currency: 'EUR', compact: true }, 'fr');
euros(12400);  // 12,4 k €

A function works as well: format: (v) => ${v} points``.

Comparisons ​

OptionDoes
valuethe figure to compare with
labelwhat it is: last year, target, average
showpercent, value, or both
lowerIsBettera fall is green
up, downyour colours of good and bad

The arrow says the direction and the colour says if it is good news: neither is the only clue. A comparison with zero shows the difference, because a share of zero means nothing.

Style ​

.nervure-figure-value, .nervure-figure-label, .nervure-delta and .nervure-delta[data-direction="down"] are plain HTML. Digits keep the same width while they count. Screen readers hear the last figure once, and people who ask for less motion see it at once.