Skip to main content

Custom formatter

priceFormat decides how prices become text on the main chart: Y-axis ticks, price tags beside horizontal grids, crosshair price, last price, OHLC panel, legend — all share one rule set.

Switch instruments often need different formats — BTC maybe 1 decimal, XRP 4, meme coins maybe compact 0.0{9}532. Modeled after TradingView’s price axis: use minMove + precision for most symbols; extreme display goes through type: "custom".

tip

With zero config the library picks a sensible precision from tick step. When instruments differ a lot (e.g. XRP at 4 decimals), pass priceFormat explicitly.

Three knobs

When configuring price format, these three controls matter (you can set only some):

KnobWhatWhy
minMoveMinimum price increment (tick size)Bounds tick step and decimal floor. e.g. 0.0001 → at least 4 decimals
precisionDisplay decimal placesLabels show at least this many; optional, derived from minMove + tick step
formatterCustom format functionOnly for type: "custom"; fully owns the string; minMove still aligns ticks

In short:

  1. Display digits ≥ decimals implied by minMove (minMove=0.0001 → at least 4)
  2. Tick step aligns with minMove (not smaller; preferably an integer multiple)
  3. Once formatter is provided, label text follows it (escape hatch: currency prefix, localization, compact, etc.)

API

KeisenChart

PropTypeDescription
priceFormatPriceFormatMain-chart price format; default { type: "price" }

PriceFormat

Union type — pick one:

type: "price" (built-in)

FieldTypeDefaultDescription
type"price"Use built-in algorithm
minMovenumber?tick size; omit to skip decimal / step floor
precisionnumber?Display decimals; omit → derived from minMove + step
compactTinyboolean?falseTiny values as 0.0{n}xxx
useGroupingboolean?trueThousands separators (1,234.56)

type: "custom"

FieldTypeDescription
type"custom"Fully custom labels
minMovenumber?Still affects tick step alignment
formatterPriceFormatter(value, ctx) => string

PriceFormatter / PriceFormatContext

type PriceFormatter = (value: number, ctx: PriceFormatContext) => string;
ctx fieldTypeDescription
kind"tick" | "value"tick: Y-axis; value: crosshair / OHLC / legend etc.
stepnumber?Current nice tick step; mainly when kind === "tick"
domainPriceDomain?Current price domain for advanced custom formatters

Helpers

FunctionSignatureDescription
createPriceFormatter(format?: PriceFormat) => PriceFormatterTurn config into one function; reuse built-in logic inside custom
formatCompactTiny(value, options?) => string | nullTiny → 0.0{9}532; below threshold returns null
formatPrice(value, ctx, opts?) => stringBuilt-in type: "price" entry

formatCompactTiny options:

FieldTypeDefaultDescription
significantDigitsnumber?4Significant digits
minLeadingZerosnumber?4Min leading zeros to trigger compact

Example

Toggle normal precision vs custom ($ prefix / compact fallback):

Loading interactive example…