Skip to content

Crosshair & tooltips ​

The crosshair selects a candle and displays its time, price and OHLC tooltip.

A crosshair lets users inspect one candle without estimating its value from the axes. Its lines mark the selected time and price, while a tooltip can show that candle's open, high, low, close and volume.

Use the built-in tooltip when those values belong on the chart. If your screen has its own detail panel, handle onSelectedCandleChange and show the selected values there. You can hide the built-in tooltip while keeping the selection interaction.

Tap once to pin the crosshair to the nearest candle, drag to move it, and tap again to clear it. A long press follows the finger and keeps the selection pinned after release. The options below control the lines, labels and tooltip fields.

Crosshair ​

PropertyType / valuesDefaultDescription
enabledbooleantrueEnables selection gestures and crosshair rendering.
showTooltipbooleantrueShows the OHLCV tooltip.
showTooltipHeaderbooleantrueShows the formatted date/time heading.
tooltipBackgroundOpacityNumber from 0 to 11Legacy tooltip opacity and appearance fallback.
lineStyle'solid', 'dashed''solid'Crosshair line pattern.
tooltipFieldsReadonlyArray<CrosshairTooltipField>All fields in the order belowSelects and orders tooltip rows. Unknown or duplicate fields are rejected; an empty array is allowed.
tooltipLabelsCrosshairTooltipLabelsEnglish labelsLocalizes tooltip row labels.
Tooltip label propertyDefaultDescription
open / close / high / lowOpen / Close / High / LowOHLC row labels.
amplitudeAmplitudeHigh-low amplitude label.
changePercentChange %Percentage change from open.
changeChangeAbsolute change from open.
volumeVolumeVolume row label.

When the candle opens at zero, the tooltip shows an em dash for percentages because the relative change cannot be calculated. Volume uses a compact format without the Y-axis currency symbol. When tooltipFields is empty, the tooltip contains only its header. If showTooltipHeader is also false, no tooltip panel is drawn even when showTooltip is true.

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 = 'crosshair';

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

  return (
    <TradingChartsView
      style={{ height: 480 }}
      chartId={chartId}
      appearance={{
        candles: { radius: 3 },
        currentPrice: { label: { border: { radius: 7 } } },
      }}
      crosshair={{
        tooltipFields: ['close', 'changePercent', 'volume'],
        showTooltipHeader: false,
      }}
    />
  );
}

Released under the MIT License.