react-native-ez-charts docs

react-native-ez-charts

A lightweight and customizable React Native chart library for creating stunning visualizations. This library supports Bar Charts, Line Charts, and Pie Charts with various customization options.

Installation

Install the package using npm:

npm install react-native-svg react-native-ez-charts

Features

  • Bar Charts: Simple and Multi-Bar Charts
  • Line Charts: Simple and Stacked Line Charts
  • Pie Charts: Inscribed and Offset Pie Charts
  • Customizable animations, gradients, tooltips, and more.

Usage Examples

Simple Bar Chart

import React from 'react';
import {BarChart} from 'react-native-ez-charts';

const SimpleBarChart = () => (
  <BarChart
    catergoricalAxis={['Jan', 'Feb', 'March', 'April', 'May']}
    numericalAxes={[
      {
        data: [100, 233, 322, 122, 34],
        strokeColor: 'blue',
      },
    ]}
    barWidth={100}
    chartHeight={500}
    barGap={20}
    categoricalAxisHeight={50}
    dashedLineGap={20}
    dashedLineWidth={20}
    categoricalLabelTilt={0}
    variant="gradient"
    endOpacity={0.5}
    animationType="timing"
    duration={500}
  />
);

export default SimpleBarChart;

Alt text


Multi Bar Chart

import React from 'react';
import {BarChart} from 'react-native-ez-charts';

const MultiBarChart = () => (
  <BarChart
    catergoricalAxis={['Jan', 'Feb', 'March', 'April']}
    numericalAxes={[
      {
        data: [100, 233, 322, 122],
        strokeColor: 'orange',
      },
      {
        data: [70, 263, 222, 122],
        strokeColor: 'pink',
      },
      {
        data: [170, 223, 212, 212],
        strokeColor: 'grey',
      },
    ]}
    barWidth={100}
    chartHeight={500}
    barGap={20}
    categoricalAxisHeight={50}
    dashedLineGap={20}
    dashedLineWidth={20}
    categoricalLabelTilt={0}
    variant="gradient"
    endOpacity={0.5}
    animationType="timing"
    duration={500}
  />
);

export default MultiBarChart;

Alt text

Simple Line Chart

import React from 'react';
import {LineChart} from 'react-native-ez-charts';

const SimpleLineChart = () => (
  <LineChart
    catergoricalAxis={['Jan', 'Feb', 'March', 'April']}
    numericalAxes={[
      {
        data: [100, 133, 122, 122],
        strokeColor: 'red',
        strokeWidth: 2,
      },
    ]}
    xUnit={100}
    chartHeight={300}
    categoricalAxisHeight={50}
    dashedLineGap={20}
    dashedLineWidth={20}
    categoricalLabelTilt={0}
    variant="area"
    showToolTip={true}
    toolTipColor="black"
  />
);

export default SimpleLineChart;

Alt text

Stacked Line Chart

import React from 'react';
import {LineChart} from 'react-native-ez-charts';

const StackedLineChart = () => (
  <LineChart
    catergoricalAxis={['Jan', 'Feb', 'March', 'April', 'May']}
    numericalAxes={[
      {
        data: [100, 133, 122, 122, 121],
        strokeColor: 'pink',
        strokeWidth: 2,
      },
      {
        data: [90, 73, 82, 92, 90],
        strokeColor: 'red',
        strokeWidth: 2,
      },
      {
        data: [20, 43, 42, 42, 69],
        strokeColor: 'grey',
        strokeWidth: 2,
      },
    ]}
    xUnit={100}
    chartHeight={500}
    categoricalAxisHeight={50}
    dashedLineGap={20}
    dashedLineWidth={20}
    categoricalLabelTilt={0}
    variant="area"
    showToolTip={true}
    toolTipColor="black"
  />
);

export default StackedLineChart;

Alt text

Inscribed Pie Chart

import React from 'react';
import {PieChart} from 'react-native-ez-charts';

const InscribedPieChart = () => (
  <PieChart
    size={180}
    data={[
      {
        value: 30,
        color: '#FF5733',
        label: {value: 'Mango', color: 'black'},
      },
      {
        value: 20,
        color: '#33FF57',
        label: {value: 'Orange', color: 'black'},
      },
      {value: 50, color: '#3357FF', label: {value: 'Peas', color: 'black'}},
      {value: 10, color: 'gray', label: {value: 'Avocado', color: 'black'}},
      {
        value: 20,
        color: '#33FF57',
        label: {value: 'Banana', color: 'black'},
      },
    ]}
    variant="inscribed"
    labelFontSize={15}
  />
);

export default InscribedPieChart;

Alt text

Offset Pie Chart

import React from 'react';
import {PieChart} from 'react-native-ez-charts';

const OffsetPieChart = () => (
  <PieChart
    size={250}
    data={[
      {
        value: 30,
        color: '#FF5733',
        label: {value: 'Mango', color: 'black'},
      },
      {
        value: 20,
        color: '#33FF57',
        label: {value: 'Orange', color: 'black'},
      },
      {value: 50, color: '#3357FF', label: {value: 'Peas', color: 'black'}},
      {value: 10, color: 'gray', label: {value: 'Avocado', color: 'black'}},
      {
        value: 20,
        color: '#33FF57',
        label: {value: 'Banana', color: 'black'},
      },
    ]}
    variant="offset"
    labelFontSize={15}
  />
);

export default OffsetPieChart;

Alt text

BarChart Props

The BarChart component allows you to render a customizable bar chart. Below is a table describing all the available props:

Prop NameTypeRequiredDefault ValueDescription
numericalAxesNumericalAxisType[]YesN/AAn array of objects defining the data and stroke color for each numerical axis.
catergoricalAxisstring[]YesN/AAn array of strings defining the categorical axis labels.
barWidthnumberYesN/AThe width of each bar in the chart.
barGapnumberYesN/AThe gap between bars in the chart.
chartHeightnumberNoN/AThe height of the chart.
minChartWidthnumberNoN/AThe minimum width of the chart.
categoricalAxisHeightnumberNoN/AThe height of the categorical axis.
categoricalLabelTiltTiltAngleNoN/AThe tilt angle of the categorical labels.
dashedLineWidthnumberNoN/AThe width of dashed lines in the chart.
dashedLineGapnumberNoN/AThe gap between dashed lines in the chart.
dashedLineColorstringNoN/AThe color of dashed lines in the chart.
categoricalLabelColorstringNoN/AThe color of the categorical labels.
numericalLabelColorstringNoN/AThe color of the numerical labels.
categoricalLabelFontSizenumberNoN/AThe font size of the categorical labels.
numericalLabelFontSizenumberNoN/AThe font size of the numerical labels.
variant'gradient' \| 'default'No'default'The visual variant of the chart.
animationTypeAnimationTypeNoN/AThe type of animation applied to the chart.
frictionnumberNoN/AThe friction value for the animation (if applicable).
tensionnumberNoN/AThe tension value for the animation (if applicable).
durationnumberNoN/AThe duration of the animation in milliseconds.
easing(value: number) => numberNoN/AA custom easing function for the animation.
endOpacitynumberNoN/AThe ending opacity for the gradient variant of the chart.

NumericalAxisType Interface

The NumericalAxisType defines the structure of the numericalAxes prop:

export interface NumericalAxisType {
  data: Array<number>;
  strokeColor: string;
}

---

LineChart Props

Here is a table summarizing the properties and types for the LineChart and CategoricalAxis components:

LineChart Props

PropTypeDescription
catergoricalAxisArray<string>Labels for the categorical axis.
numericalAxesNumericalAxisType[]Array of numerical axis configurations, including data and styles.
chartHeightnumber (optional)Height of the chart.
minChartWidthnumber (optional)Minimum width of the chart.
modifyToolTipLabel(x: string, y: number) => string (optional)Function to modify the tooltip label.
xUnitnumber (optional)Unit spacing for the x-axis.
showToolTipboolean (optional)Whether to show tooltips on the chart.
categoricalAxisHeightnumber (optional)Height of the categorical axis.
categoricalLabelTiltTiltAngle (optional)Angle for tilting the categorical labels.
dashedLineWidthnumber (optional)Width of dashed grid lines.
dashedLineGapnumber (optional)Gap between dashed grid lines.
dashedLineColorstring (optional)Color of dashed grid lines.
variant'area' | 'blank' (optional)Style variant of the chart.
categoricalLabelColorstring (optional)Color of the categorical axis labels.
numericalLabelColorstring (optional)Color of the numerical axis labels.
categoricalLabelFontSizenumber (optional)Font size for categorical labels.
numericalLabelFontSizenumber (optional)Font size for numerical labels.
toolTipColorstring (optional)Color of the tooltip.

NumericalAxisType

PropertyTypeDescription
dataArray<number>Data points for the numerical axis.
strokeColorstringColor of the line representing the data.
strokeWidthnumberWidth of the line representing the data.

CategoricalAxis Props

PropTypeDescription
categoricalAxisArray<string>Labels for the categorical axis.
xUnitnumberUnit spacing for the categorical axis.
heightnumber (optional)Height of the categorical axis.
tiltAngleTiltAngle (optional)Angle to tilt the labels for better readability.
labelColorstring (optional)Color of the categorical labels.
fontSizenumber (optional)Font size of the categorical labels.

TiltAngle

ValueDescription
0No tilt (horizontal).
5-90Angle in degrees to tilt labels for readability.

PieChart Props

PropTypeDescription
dataSlice[]Array of slices representing the pie chart. Each slice contains value, color, and optionally a label.
variant"offset" | "inscribed" (optional)Style variant of the pie chart. offset places slices with spacing, inscribed keeps slices compact.
sizenumberDiameter of the pie chart.
labelFontSizenumber (optional)Font size for the labels inside the pie chart.
gradientboolean (optional)Whether to apply a gradient effect to the chart.
endOpacitynumber (optional)Opacity at the end of the gradient (if enabled).

Slice Interface

PropertyTypeDescription
valuenumberValue of the slice, determines its size proportion in the chart.
colorstringColor of the slice.
label{ value: string, color: string } (optional)Optional label for the slice, with text and color.

License

This library is licensed under the MIT License.