Skip to content

Axes & formatting ​

Time labels appear below the candles and price labels along the right axis.

The axes tell users when a value occurred and how large it was. The X axis represents time; the Y axis shows prices or the values in an indicator pane. Their labels need to suit the data: a price may need two decimals, a small token price more precision, and volume a compact number.

Use xAxis and yAxis for spacing, dimensions and scale behavior. Use formatters when labels in different places need different formats. For example, the axis can show a short price while the tooltip shows more decimals for inspection.

Formatting changes the displayed text. It does not change the stored timestamps or prices. The time zone used to group trades into candles is configured separately under Time & trade aggregation.

X axis ​

Use elapsed-time spacing when gaps between timestamps should occupy space. Use logical spacing when each candle should have the same horizontal slot, for example across a market closure. Both modes keep timestamps in the labels.

PropertyType / valuesDefaultDescription
visiblebooleantrueShows the time axis.
heightPositive number26Axis height in native view units.
localeLocale string'en-GB'Legacy/default date locale.
timeZoneIANA time-zone string'UTC'Legacy/default label time zone.
showSecondsbooleanfalseEnables second-level axis labels.
spacing'time', 'logical''time'Uses elapsed milliseconds or uniform candle-index slots.

Y axis ​

The price axis is always placed on the right side of the chart.

PropertyType / valuesDefaultDescription
visiblebooleantrueShows the main price axis.
widthPositive number64Axis width in native view units.
defaultScaleNumber from 0.1 to 101Baseline vertical scale restored by history loads and fitContent.
scaleMargins.topNon-negative fraction0.2Reserved space above visible values.
scaleMargins.bottomNon-negative fraction0.1Reserved space below visible values.
valueFormatYAxisValueFormatPrice formatLegacy/main Y-axis formatter; formatters.price.yAxis wins.

Scale margins must leave at least 1e-6 of the plot area, so their sum must be at most 1 - 1e-6. When visible values are equal, autoscale expands the range using minMove.

Price formats ​

Choose price for a fixed number of decimal places, compact for large values with suffixes, or significant when meaningful digits matter more than a fixed decimal count. Set minMove to the instrument tick size so scaling and labels use an appropriate minimum price step.

PropertyType / valuesDefaultDescription
type'price''price'Fixed decimal formatting.
precisionInteger 0...122Decimal precision.
type'compact'Not applicableCompact suffix formatting for large values.
precisionInteger 0...82Compact precision.
type'significant'Not applicableSignificant digits with compact crypto zero-count notation.
significantDigitsInteger 1...83Significant digits to display.
minMovePositive number0.01Real instrument tick size; omitted from display-only formats.
localeLocale string'en-GB'Native number locale.
currencySymbolstring''Prefix displayed with prices.
useGroupingbooleantrueEnables locale grouping where supported.

Volume formats use type: 'volume', precision defaulting to 2, locale defaulting to en-GB, and useGrouping defaulting to true.

Role-specific formatters ​

The axis, tooltip and crosshair badges can show the same value with different precision or date detail. Set the corresponding role under formatters instead of changing every label at once.

PropertyType / valuesDefaultDescription
date.xAxis.localeLocale stringxAxis.localeLocale for adaptive X-axis labels.
date.xAxis.timeZoneIANA time zonexAxis.timeZoneTime zone for adaptive X-axis labels.
date.xAxis.secondsICU pattern'HH:mm:ss'Second-span label format.
date.xAxis.timeICU pattern'HH:mm'Intraday label format.
date.xAxis.dayICU pattern'd MMM'Day label format.
date.xAxis.monthICU pattern'MMM yyyy'Month label format.
date.xAxis.yearICU pattern'yyyy'Year label format.
date.crosshairTimeBadge{ pattern, locale?, timeZone? }'d MMM yyyy HH:mm:ss'Crosshair time badge format.
date.tooltipHeader{ pattern, locale?, timeZone? }'d MMM yyyy HH:mm:ss'Tooltip header format.
price.yAxisYAxisValueFormatyAxis.valueFormatMain Y-axis format.
price.priceExtremesPriceDisplayFormatMain Y formatVisible high/low format.
price.currentPricePriceDisplayFormatMain Y formatCurrent-price format.
price.crosshairPricePriceDisplayFormatMain Y formatCrosshair price badge format.
price.tooltipPriceDisplayFormatMain Y formatTooltip OHLC value format.

Date patterns use Unicode/ICU syntax. Role-specific formatters override the legacy xAxis and yAxis.valueFormat values.

Format each role ​

This chart uses uniform candle spacing, a two-decimal price axis, and more precision in the tooltip. Dates remain timestamps in milliseconds even with logical spacing.

tsx
import { useEffect } from 'react';
import {
  TradingCharts,
  TradingChartsView,
  type OhlcCandle,
} from 'react-native-trading-charts';

// Deterministic sample data. Replace this with your market-data feed.
const history: OhlcCandle[] = Array.from({ length: 80 }, (_, index) => {
  const open = 100 + Math.sin(index / 5) * 8;
  const close = 100 + Math.sin((index + 1) / 5) * 8;
  return {
    timestamp: 1_720_000_000_000 + index * 60_000,
    open,
    high: Math.max(open, close) + 2,
    low: Math.min(open, close) - 2,
    close,
    volume: 10 + index,
  };
});

const chartId = 'axes';

export function Example() {
  useEffect(() => {
    TradingCharts.setHistory(chartId, history);
  }, []);

  return (
    <TradingChartsView
      style={{ height: 420 }}
      chartId={chartId}
      xAxis={{ spacing: 'logical', height: 30, timeZone: 'UTC' }}
      yAxis={{
        width: 88,
        scaleMargins: { top: 0.2, bottom: 0.1 },
        valueFormat: {
          type: 'price',
          precision: 2,
          minMove: 0.01,
          currencySymbol: '$',
        },
      }}
      formatters={{
        date: {
          xAxis: { time: 'HH:mm', day: 'd MMM', timeZone: 'UTC' },
          crosshairTimeBadge: { pattern: 'd MMM HH:mm', timeZone: 'UTC' },
        },
        price: {
          tooltip: { type: 'price', precision: 4, currencySymbol: '$' },
        },
      }}
      appearance={{
        xAxis: { text: { fontSize: 11 } },
        yAxis: { text: { fontSize: 12 } },
      }}
    />
  );
}

minMove sets the instrument tick size used by the scale. Formats used only to display values do not include this property. CompactValueFormat on an axis does not expose useGrouping; fixed-price, significant and volume formats do. The display-only compact variant also accepts useGrouping.

Released under the MIT License.