React Native Chart Kit

repository·main·Indexed 25 days ago

https://github.com/chart-kit/react-native-chart-kit

A library for creating interactive charts in React Native applications, including Line, Area, Bar, Pie, Donut, Progress, and Contribution Heatmap visualizations. Version 7.0.2 features a modern v2 API with support for theming, interactivity, and accessibility summaries. The ecosystem includes @chart-kit/core for renderer-agnostic logic and @chart-kit/svg-renderer for react-native-svg integration. Advanced Pro Charts such as Candlebar, Radar, Realtime Bar, and Combo charts are available via a separate installation.

Tokens
69.4K
Snippets
124
Records
294
Agent score
81%

What's inside react-native-chart-kit

  1. Overview of @chart-kit/core

    main
    @chart-kit/core provides renderer-agnostic core utilities for React Native Chart Kit. It is responsible for the mathematical and structural logic of charts, including data normalization, series models, scales, domains, ticks, layout calculations, geometry generation, interaction math, theme tokens, and accessibility summaries. It is designed to return plain data models that can be consumed by various renderers.
  2. Use react-native-chart-kit/v2 in a non-Expo React Native CLI project

    main

    The react-native-chart-kit/v2 package is designed for modern Chart Kit usage in plain React Native CLI applications (non-Expo). When setting up a project using this version, ensure you have the following peer dependencies installed:

    • react
    • react-native
    • react-native-svg

    Commonly used components include LineChart, BarChart, and ProgressRing.

  3. Available Chart Types

    main

    React Native Chart Kit provides several built-in chart types for mobile dashboards and reports:

    • Line
    • Area
    • Bar
    • Pie
    • Donut
    • Progress
    • Contribution Heatmap

    Note: Advanced charts like Candlebar, Radar, Realtime Bar, and Combo charts are part of Chart Kit Pro and require a license.

  4. Use Legacy Charts via root import

    main

    Legacy charts are available through the standard root import from react-native-chart-kit. Note that these legacy components do not consume ChartKitProvider presets. To style them, you must pass props directly such as chartConfig, barColors, legendFontColor, and backgroundColor.

    import {
      BarChart,
      ContributionGraph,
      LineChart,
      PieChart,
      ProgressChart,
      StackedBarChart
    } from "react-native-chart-kit";
  5. Implement tap selection in DonutChart

    main

    You can enable slice selection using the interaction prop. For uncontrolled selection, set interaction={{ mode: "tap" }}. For controlled selection, pass selectedIndex and use the onSelect callback within the interaction object to update your state.

    const revenueMix = [
      { plan: "Enterprise", revenue: 680 },
      { plan: "Business", revenue: 420 },
      { plan: "Teams", revenue: 260 },
      { plan: "Starter", revenue: 140 }
    ];
    
    const [selectedIndex, setSelectedIndex] = useState(0);
    
    <DonutChart
      data={revenueMix}
      valueKey="revenue"
      labelKey="plan"
      selectedIndex={selectedIndex}
      interaction={{
        mode: "tap",
        onSelect: (event) => setSelectedIndex(event.index)
      }}
      centerLabel={revenueMix[selectedIndex]?.plan}
      activeSlice={{ inactiveOpacity: 0.36, strokeWidth: 4 }}
      width={410}
      height={260}
    />;
  6. Select the appropriate chart type

    main

    Choose a chart based on your data visualization goal:

    Standard Charts:

    • Trend over time: LineChart
    • Filled trend: AreaChart
    • Comparison by category: BarChart
    • Parts of whole: DonutChart (preferred) or PieChart
    • Completion/rings: ProgressChart or ProgressRing
    • Calendar activity: ContributionGraph or CalendarHeatmap

    Pro Charts (Commercial):

    • Revenue plus margin, bars plus line, dual axes: CombinedChart
    • Stocks/OHLC/timeframe inspection: CandlestickChart or CandlebarChart
    • Live updating bars: RealtimeBarChart
    • Multi-axis category comparison: RadarChart
    • PNG/SVG/share workflow: Pro export helpers
  7. Use Realtime.BarChart for rolling data streams

    main

    The Realtime.BarChart component is designed for live analytics and monitoring dashboards. It renders a rolling bar window where visual slots remain stable while new data points slide into view. This ensures that selection and tooltip states follow the specific data point (via liveKey) rather than a moving array index.

    Note: This component is part of Chart Kit Pro. You must install it via the Pro Installation guide.

    import { Realtime } from "@chart-kit/pro";
    
    <Realtime.BarChart
      data={rows}
      xKey="pointIndex"
      yKey="users"
      liveKey="pointIndex"
      windowSize={30}
      animation={{ duration: 2000, mode: "slide" }}
      // ... other props
    />