Skip to content

Line Chart

LineChart is the primary modern v2 trend surface. It uses object-row data, explicit keys, renderer-agnostic geometry, and SVG rendering by default.

Use this API for new apps. The legacy react-native-chart-kit data shape is handled separately by the compatibility facade.

Basic Line

import { LineChart } from "react-native-chart-kit/v2";

const data = [
  { month: "Jan", revenue: 52 },
  { month: "Feb", revenue: 86 },
  { month: "Mar", revenue: 58 },
  { month: "Apr", revenue: 134 },
  { month: "May", revenue: 95 },
  { month: "Jun", revenue: 176 },
  { month: "Jul", revenue: 126 },
  { month: "Aug", revenue: 218 },
  { month: "Sep", revenue: 164 },
  { month: "Oct", revenue: 252 },
  { month: "Nov", revenue: 198 },
  { month: "Dec", revenue: 286 }
];

export function RevenueChart() {
  return (
    <LineChart
      data={data}
      xKey="month"
      yKey="revenue"
      width={360}
      height={240}
    />
  );
}

Multi-Series

Use series when each line needs its own label, color, marker, curve, or stroke style.

const data = [
  { month: "Jan", actual: 22, forecast: 190 },
  { month: "Feb", actual: 64, forecast: 168 },
  { month: "Mar", actual: 39, forecast: 143 },
  { month: "Apr", actual: 118, forecast: 122 },
  { month: "May", actual: 73, forecast: 101 },
  { month: "Jun", actual: 161, forecast: 84 },
  { month: "Jul", actual: 109, forecast: 66 },
  { month: "Aug", actual: 204, forecast: 48 }
];

<LineChart
  data={data}
  xKey="month"
  series={[
    { yKey: "actual", label: "Actual", color: "#2563eb" },
    {
      yKey: "forecast",
      label: "Forecast",
      color: "#94a3b8",
      strokeDasharray: [6, 4],
      strokeOpacity: 0.72
    }
  ]}
  legend={{ position: "bottom", wrap: true }}
  width={360}
  height={260}
/>;

Styling Lines and Dots

Supported curve values are linear, monotone, and step.

const data = [
  { date: "Mon", portfolio: 512, benchmark: 690 },
  { date: "Tue", portfolio: 660, benchmark: 610 },
  { date: "Wed", portfolio: 430, benchmark: 650 },
  { date: "Thu", portfolio: 760, benchmark: 540 },
  { date: "Fri", portfolio: 590, benchmark: 700 },
  { date: "Sat", portfolio: 820, benchmark: 520 },
  { date: "Sun", portfolio: 548, benchmark: 735 }
];

<LineChart
  data={data}
  xKey="date"
  series={[
    {
      yKey: "portfolio",
      label: "Portfolio",
      curve: "monotone",
      strokeWidth: 3,
      dot: {
        shape: "diamond",
        radius: 4,
        fill: "background",
        stroke: "series"
      }
    },
    {
      yKey: "benchmark",
      label: "Benchmark",
      curve: "linear",
      strokeDasharray: [5, 5],
      strokeLinecap: "butt",
      dot: false
    }
  ]}
  activeDot={{ radius: 6, fill: "background", stroke: "series" }}
  width={360}
  height={260}
/>;

Threshold Coloring

Threshold coloring clips the rendered path above or below a y value. Raw points are unchanged.

const data = [
  { month: "Jan", attainment: 62 },
  { month: "Feb", attainment: 138 },
  { month: "Mar", attainment: 74 },
  { month: "Apr", attainment: 151 },
  { month: "May", attainment: 89 },
  { month: "Jun", attainment: 122 },
  { month: "Jul", attainment: 55 },
  { month: "Aug", attainment: 164 },
  { month: "Sep", attainment: 96 },
  { month: "Oct", attainment: 145 },
  { month: "Nov", attainment: 78 },
  { month: "Dec", attainment: 172 }
];

<LineChart
  data={data}
  xKey="month"
  series={[
    {
      yKey: "attainment",
      label: "Attainment",
      threshold: {
        y: 100,
        aboveColor: "#16a34a",
        belowColor: "#dc2626"
      }
    }
  ]}
  referenceLines={[{ y: 100, label: "Plan", strokeDasharray: [5, 4] }]}
  width={360}
  height={240}
/>;

Tooltips and Selection

Selection state is shared by tooltips, active dots, crosshairs, and external UI through onSelect.

const data = [
  { date: "Nov 03", portfolio: 512, benchmark: 720 },
  { date: "Nov 04", portfolio: 681, benchmark: 604 },
  { date: "Nov 05", portfolio: 438, benchmark: 698 },
  { date: "Nov 10", portfolio: 794, benchmark: 552 },
  { date: "Nov 11", portfolio: 566, benchmark: 746 },
  { date: "Nov 12", portfolio: 842, benchmark: 580 },
  { date: "Nov 13", portfolio: 618, benchmark: 790 },
  { date: "Nov 14", portfolio: 906, benchmark: 534 }
];

<LineChart
  data={data}
  xKey="date"
  yKeys={["portfolio", "benchmark"]}
  interaction={{
    mode: "scrub",
    selectionPersistence: "whileActive",
    onSelect: (event) => {
      setHeaderValue(event.series[0]?.formattedValue);
    }
  }}
  tooltip={{
    shared: true,
    anchor: "pointer",
    placement: "above",
    offset: 18,
    positionAnimationDuration: 320
  }}
  crosshair
  width={360}
  height={260}
/>;

Selection modes:

  • none: no chart selection.
  • tap: tap to select the nearest x value.
  • scrub: press and drag to update the nearest x value.

Selection persistence:

  • persist: keep the last selection after the gesture ends.
  • whileActive: clear selection on gesture end.
  • none: emit selection events without keeping internal selected state.

Tooltip positioning:

  • anchor: "point" positions around the selected data point.
  • anchor: "pointer" positions around the touch/mouse pointer.
  • placement: "auto" | "above" | "below" controls vertical placement while preserving edge clamping.

Custom Crosshair

Use renderCrosshair when a product needs branded cursors, axis badges, or a custom inspection overlay.

import { G, Line, Text as SvgText } from "react-native-svg";

const data = [
  { month: "Jan", actual: 22, forecast: 190 },
  { month: "Feb", actual: 64, forecast: 168 },
  { month: "Mar", actual: 39, forecast: 143 },
  { month: "Apr", actual: 118, forecast: 122 },
  { month: "May", actual: 73, forecast: 101 },
  { month: "Jun", actual: 161, forecast: 84 },
  { month: "Jul", actual: 109, forecast: 66 },
  { month: "Aug", actual: 204, forecast: 48 }
];

<LineChart
  data={data}
  xKey="month"
  yKeys={["actual", "forecast"]}
  selectedIndex={4}
  crosshair={{ strokeDasharray: [3, 4] }}
  renderCrosshair={({ config, plot, series, x, xLabel, y }) => (
    <G>
      <Line
        x1={x}
        x2={x}
        y1={plot.y}
        y2={plot.y + plot.height}
        stroke={config.color}
        strokeDasharray={config.strokeDasharray}
      />
      <SvgText x={x + 8} y={y - 8}>
        {xLabel}: {series[0]?.formattedValue}
      </SvgText>
    </G>
  )}
  width={360}
  height={260}
/>;

Scroll, Pan, Zoom, and Range Selector

Use simple horizontal scrolling for long categorical or time-series charts.

<LineChart
  data={largeData}
  xKey="date"
  yKey="price"
  scrollable
  visiblePoints={30}
  initialIndex="end"
  yAxisLabelWidth="stable"
  width={360}
  height={260}
/>

Use a controlled viewport for direct pan, pinch zoom, or a mini-chart range selector.

const [viewport, setViewport] = useState<LineChartViewportConfig>({
  startIndex: 40,
  endIndex: 90
});

<LineChart
  data={portfolioHistory}
  xKey="date"
  yKeys={["portfolio", "benchmark"]}
  viewport={viewport}
  onViewportChange={(event) => setViewport(event.viewport)}
  viewportInteraction={{ pan: true, pinchZoom: true, lockParentScroll: true }}
  rangeSelector={{ visible: true, interactive: true, height: 68 }}
  yAxisLabelWidth="stable"
  width={360}
  height={340}
/>;

yAxisLabelWidth="stable" reserves label width from the full dataset, so changing the viewport does not make the plot jump when labels change.

Reference Overlays

Reference lines and bands are clipped to the plot bounds. Line labels default to automatic vertical placement and try to avoid nearby series geometry.

const data = [
  { month: "Jan", attainment: 62 },
  { month: "Feb", attainment: 138 },
  { month: "Mar", attainment: 74 },
  { month: "Apr", attainment: 151 },
  { month: "May", attainment: 89 },
  { month: "Jun", attainment: 122 },
  { month: "Jul", attainment: 55 },
  { month: "Aug", attainment: 164 },
  { month: "Sep", attainment: 96 },
  { month: "Oct", attainment: 145 },
  { month: "Nov", attainment: 78 },
  { month: "Dec", attainment: 172 }
];

<LineChart
  data={data}
  xKey="month"
  yKey="attainment"
  referenceBands={[{ y1: 90, y2: 110, label: "Target range", opacity: 0.12 }]}
  referenceLines={[{ y: 100, label: "Plan", strokeDasharray: [5, 4] }]}
  width={360}
  height={240}
/>;

Layout Debug

Use debugLayout in development when a chart clips labels, legends, or tooltips.

<LineChart
  data={data}
  xKey="month"
  yKey="revenue"
  debugLayout
  onLayoutDebug={(model) => {
    console.log(model.rects);
  }}
  width={360}
  height={240}
/>

Labels and Axes

Useful label props:

  • labelStrategy: auto, show, skip, rotate, stagger, or hide.
  • edgeLabelPolicy: shift, hide, or show.
  • formatXLabel: format dates, categories, or numeric x values.
  • formatYLabel: format y-axis labels and tooltip values.
  • axisLabelAnimation: crossfade y-axis label changes during viewport changes.
  • yAxisLabelWidth: auto, stable, or a fixed number.

Decimation

LineChart uses automatic path-only min/max decimation by default. This reduces SVG path complexity for dense charts while preserving source points for selection, tooltips, labels, and custom dots.

<LineChart
  data={largeData}
  xKey="timestamp"
  yKey="price"
  showDots={false}
  decimation={{ maxPoints: 700 }}
  width={360}
  height={240}
/>

Decimation options:

  • decimation="auto": default. Uses roughly two rendered path points per plot pixel, with a minimum of 120.
  • decimation={false}: disables path decimation.
  • decimation={500}: caps each rendered path around a fixed point budget.
  • decimation={{ maxPoints: 700 }}: object form for future strategy options.

Accessibility

Every LineChart generates a summary if accessibilityLabel is not provided. For custom accessibility surfaces, use:

import {
getLineChartAccessibilitySummary,
getLineChartDataTable
} from "react-native-chart-kit/v2";

getLineChartDataTable() returns columns and rows suitable for an app-level table fallback or export workflow.

Props

LineChart

PropTypeDescription
dataTData[]Object-row source data for the chart.
xKeykeyof TDataRow key used for the x-axis value.
yKeykeyof TDataSingle row key used for y values when series or yKeys is not provided.
yKeysArray<keyof TData>Multiple row keys rendered as separate series with default styling.
seriesLineChartSeries<TData>[]Full per-series configuration, including labels, colors, stroke, dots, thresholds, and area fill.
widthnumberOuter chart width in pixels.
heightnumberOuter chart height in pixels.
themeChartKitThemeMode or CartesianChartThemeTheme mode or inline theme tokens for this chart.
presetCartesianChartPresetValueBuilt-in or registered preset name used to seed chart colors and typography.
scrollablebooleanEnables a horizontal scroll viewport for long data sets.
visiblePointsnumberNumber of points visible in the viewport when scrollable is enabled.
initialIndexChartViewportInitialIndexInitial scroll/window position, such as "start" or "end".
viewportLineChartViewportConfigControlled visible data window for scroll, pan, zoom, or range selector flows.
onViewportChange(event) => voidCalled when viewport state changes from the main plot or range selector.
viewportInteractionboolean or LineChartViewportInteractionConfigEnables and configures one-finger pan and pinch zoom for the viewport.
rangeSelectorboolean or LineChartRangeSelectorConfigAdds a mini-chart range selector below the main plot.
decimationfalse, "auto", number, or LineChartDecimationConfigControls rendered path simplification for dense series.
curveLineCurveCurve interpolation used for line and area paths.
connectNullsbooleanConnects defined points across null or missing y values.
areabooleanRenders area fills under the line series.
areaFillLineChartAreaFillConfigShared area fill opacity, gradient, or color configuration.
showDotsbooleanShows or hides all point markers.
dotsboolean or LineChartDotConfigConfigures default point marker visibility, size, shape, and color.
renderDot(props) => ReactNodeCustom renderer for ordinary point markers.
selectedIndexnumberControlled selected data index.
defaultSelectedIndexnumberInitial uncontrolled selected data index.
activeDotboolean or LineChartDotConfigConfigures the marker shown for the selected point.
renderActiveDot(props) => ReactNodeCustom renderer for the selected point marker.
interactionLineChartInteraction<TData>Selection/scrub interaction mode and callbacks.
crosshairboolean or LineChartCrosshairConfigShows and configures the selected-point crosshair.
renderCrosshair(props) => ReactNodeCustom renderer for the crosshair.
tooltipboolean or LineChartTooltipConfigShows and configures selected-point tooltip content and placement.
renderTooltip(props) => ReactNodeCustom renderer for selected-point tooltip content.
referenceLinesLineChartReferenceLineConfig[]Horizontal reference lines drawn across the plot.
referenceBandsLineChartReferenceBandConfig[]Horizontal reference bands drawn behind the series.
showHorizontalGridLinesbooleanShows or hides horizontal grid lines.
showVerticalGridLinesbooleanShows or hides vertical grid lines.
legendboolean or LineChartLegendConfigShows and configures the chart legend.
labelStrategyLineChartLabelStrategyControls x-axis label density and layout.
labelRotationnumberRotation angle for x-axis labels when using rotated labels.
labelMinGapnumberMinimum gap used by automatic x-axis label skipping.
edgeLabelPolicyLineChartEdgeLabelPolicyControls how first and last x-axis labels are shifted, hidden, or shown.
yDomainNumericDomainInputOverrides or constrains the computed y-axis domain.
yAxisLabelWidthLineChartYAxisLabelWidthFixed, automatic, or stable width for y-axis labels.
axisLabelAnimationboolean or LineChartAxisLabelAnimationConfigAnimates y-axis label changes during viewport updates.
formatXLabel(value, index) => stringFormats x-axis labels and selected x labels.
formatYLabel(value) => stringFormats y-axis labels, selected values, and tooltip values.
rendererLineChartRendererRenderer implementation used for SVG-compatible primitives.
idstringStable chart id used for internal ids and coordinated selection scope.
debugLayoutbooleanRenders layout debug rectangles in development.
onLayoutDebug(model) => voidReceives computed layout debug geometry.
accessibilityLabelstringOverrides the generated accessible chart summary.
testIDstringTest identifier applied to the chart surface.