1.0.2 • Published 5 months ago

react-native-chart-tnbt v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

How to use react-native-chart-tnbt

Getting Started

Note: I am a newbie in React Native. Here is my frist package which I publish to npm. If it make you waste your time, please dont blame me. I hope to disscuss about any the problem with you. Thank you !!!

This package is for Android

Test

You can clone this repo to test package.

https://github.com/tiennguyen12g/react-native-chart-tnbt.git
npx react-native start

In the App.tsx, I have some data for test, you can use it if need.

Installation using npm

npm i react-native-chart-tnbt

1. PieChart

Import to your component

import {PieChart} from "react-native-chart-tnbt"

if typescript gives the error, you can try to create file name react-native-chart-tnbt.d.ts

// file react-native-chart-tnbt.d.ts
declare module "react-native-chart-tnbt"

typeNo = 1

Type1 Image

typeNo = 2

Type2 Image

annotations

Annotaions Image

Available props

interface PieChartProps {
   typeNo?: number; // default: 1 or option 2
   data: DataInput[]; 
   duration?: number; // default: 2000ms
   mainPie?: {
     size?: number; // default: 280
     strokeWidth?: number; // default: 15
   };
   decorPie?: {
     sizeDecorCircular: number;
     strokeWidthDecorCircular: number;
     seperateSlice: boolean;
     opacityDecorCircular: number; // Value 0-1
     annotation?: boolean;
     logoData?: CryptoLogoPNG;
     logoSize?: number;
     colorCustomList?: string[]
   };
   animations?: {
     clockwiseDirection: string; // option "clockwise" or 'counter_clockwise'
   };
}

Table list props

NameTypeDefaultDescription
typyNonumber1Type of pie chart
dataDataInput[]noData to pass to the pie chart
durationnumber2000Time for animation to run
mainPieParameter to create the main circle chart
sizenumber280The size of the view box
strokeWidthnumber15The size of the stroke for the circle
decorPieParameter to create a second circle for decorating the main circle
sizeDecorCircularnumber150The size of the second circle
strokeWidthDecorCircularnumber25The size of the stroke for the second circle
separateSlicebooleantrueCreates clear lines to cut graph pieces
opacityDecorCircularnumber0.5Adds opacity for the circle decor
annotationbooleanfalseAdds a note for each fund
logoSizenumber35The size for inserting a logo in annotations or each slice
colorCustomListstring[]see belowThe size for inserting a logo in annotations or each slice
clockwiseDirectionstringclockwise or counter_clockwiseDirection of rotation of the circle
interface DataInput {
   title: string;
   value: number;
}

How to use

   Example: 
      const dataInput = [
      {
        title: 'Gold',
        value: 23900.52,
      },
      {
        title: 'USD',
        value: 11100,
      }]
      <YourComponent>
         <PieChart
          typeNo={1}
          data={dataInput}
          duration={2000}
          mainPie={
            {
               size: 280, 
               strokeWidth: 15
            }
         }
          animations={{
            clockwiseDirection: 'clockwise', // counter_clockwise or clockwise
          }}
          decorPie={{
            sizeDecorCircular: 150,
            strokeWidthDecorCircular: 25,
            seperateSlice: true,
            opacityDecorCircular: 0.5,
            annotation: true,
          }}
        />
      </YourComponent>

Declare logo like this component

interface CryptoLogos {
 [key: string]: {uri: string};
}
const BTC = require('./PNG/btc.png');
const ETH = require('./PNG/eth.png');

  const Crypto_Logo_PNG: CryptoLogos = {
   "BTC": BTC,
   "ETH": ETH,
  };

export default Crypto_Logo_PNG;

** Note: The key for the logo must to the same with the title.
Example: 
const dataInput = [{
   title: 'BTC',
   value: 23900.52,
}];
const Crypto_Logo_PNG: CryptoLogos = {
   "BTC": BTC,
};
The title "BTC" have to equal the key of object logo "BTC" in this case.

Add your favorite colors

// default color
const colorCustomList = [
   'rgb(244,62,61)',
   'rgb(254,165,61)',
   'rgb(128,22,80)',
   'rgb(131,242,58)',
   'rgb(59,95,255)',
   'rgb(252,60,222)',
   'rgb(72,220,236)',
];
If you not pass this data or your data is large, the code will auto create random color.

I will try to build more type of chart.

Congratulations! :tada:

You've successfully run and modified this package. :partying_face: