• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pie chart for React Native

react-native-pie

Pie chart for React Native, works on both iOS and Android

Demo

iOS Android

Install

# NPM
npm i --save react-native-pie
OR
# Yarn
yarn add react-native-pie

For react-native-pie >= 1.1.0 install peer dependency

# NPM
npm i --save @react-native-community/art
OR
# Yarn
yarn add @react-native-community/art

Migration from react-native-pie <= 0.6.2

Please unlink react-native ART library

Linking module

Mostly automatic linking

If react-native >= 0.60 && react-native-pie >= 1.1.0, the package will be linked automatically.

Manual linking for react-native-pie <= 0.6.2

Link the ART library to your ReactNative project (how to link a library). You'll find the React ART library in node_modules/react-native/Libraries/ART/ART.xcodeproj

React Native Version Support

If you are using < .45, please install react-native-pie v0.1.0 instead
npm i --save [email protected]

Please use >= 0.50.0-rc.0 otherwise there is a ring shape drawing issue with react-native-pie

Usage

import React from 'react'
import {
  StyleSheet,
  View,
  Text,
} from 'react-native'
import Pie from 'react-native-pie'

export default () => {
    return (
      <View style={styles.container}>
          <View
            style={{
              paddingVertical: 15,
              flexDirection: 'row',
              width: 350,
              justifyContent: 'space-between',
            }}
          >
            <Pie
              radius={80}
              sections={[
                {
                  percentage: 10,
                  color: '#C70039',
                },
                {
                  percentage: 20,
                  color: '#44CD40',
                },
                {
                  percentage: 30,
                  color: '#404FCD',
                },
                {
                  percentage: 40,
                  color: '#EBD22F',
                },
              ]}
              strokeCap={'butt'}
            />
            <Pie
              radius={80}
              innerRadius={50}
              sections={[
                {
                  percentage: 10,
                  color: '#C70039',
                },
                {
                  percentage: 20,
                  color: '#44CD40',
                },
                {
                  percentage: 30,
                  color: '#404FCD',
                },
                {
                  percentage: 40,
                  color: '#EBD22F',
                },
              ]}
              strokeCap={'butt'}
            />
          </View>
          <View
            style={{
              paddingVertical: 15,
              flexDirection: 'row',
              width: 350,
              justifyContent: 'space-between',
            }}
          >
            <Pie
              radius={80}
              innerRadius={60}
              sections={[
                {
                  percentage: 10,
                  color: '#C70039',
                },
                {
                  percentage: 20,
                  color: '#44CD40',
                },
                {
                  percentage: 30,
                  color: '#404FCD',
                },
                {
                  percentage: 40,
                  color: '#EBD22F',
                },
              ]}
              dividerSize={4}
              strokeCap={'round'}
            />
            <Pie
              radius={80}
              innerRadius={60}
              sections={[
                {
                  percentage: 10,
                  color: '#C70039',
                },
                {
                  percentage: 20,
                  color: '#44CD40',
                },
                {
                  percentage: 30,
                  color: '#404FCD',
                },
                {
                  percentage: 40,
                  color: '#EBD22F',
                },
              ]}
              dividerSize={6}
              strokeCap={'butt'}
            />
          </View>
          <View
            style={{
              paddingVertical: 15,
              width: 350,
              flexDirection: 'row',
              justifyContent: 'space-between',
            }}
          >
            <Pie
              radius={80}
              sections={[
                {
                  percentage: 10,
                  color: '#C70039',
                },
                {
                  percentage: 20,
                  color: '#44CD40',
                },
                {
                  percentage: 30,
                  color: '#404FCD',
                },
                {
                  percentage: 40,
                  color: '#EBD22F',
                },
              ]}
              dividerSize={6}
              strokeCap={'butt'}
            />
            <View style={{ width: 175, alignItems: 'center' }}>
              <Pie
                radius={80}
                innerRadius={75}
                sections={[
                  {
                    percentage: 60,
                    color: '#f00',
                  },
                ]}
                backgroundColor="#ddd"
              />
              <View
                style={styles.gauge}
              >
                <Text
                  style={styles.gaugeText}
                >
                  60%
                </Text>
              </View>
            </View>
          </View>
        </View>
    )
  
}

const styles = StyleSheet.create({
  container: { alignItems: 'center', justifyContent: 'center', height: 1050 },
  gauge: {
    position: 'absolute',
    width: 100,
    height: 160,
    alignItems: 'center',
    justifyContent: 'center',
  },
  gaugeText: {
    backgroundColor: 'transparent',
    color: '#000',
    fontSize: 24,
  },
})

Props

  • sections {percentage, color} of each section in the pie - array, required
  • radius radius = size / 2 , - number, required
  • innerRadius defaults to 0 - number, optional
  • backgroundColor defaults to #fff - string, optional
  • strokeCap ( round , butt ) defaults to butt - string, optional
    • PLEASE NOTE If using strokeCap={'round'} it is highly recommended to use a higher innerRadius (around 60% of radius and higher) in addition to not having very small percentage sections. This will ensure proper display. We hope to address these issues in future PRs
  • dividerSize defaults to 0 - percentage size to divide the sections - number, optional

License

MIT

More Repositories

1

react-native-dva-starter

a React Native starter powered by dva and react-navigation
JavaScript
641
star
2

react-native-sudoku

a sudoku game written in React Native
JavaScript
641
star
3

react-runner

Run your React code on the go
TypeScript
409
star
4

hexo-hey

an admin plugin for hexo
JavaScript
208
star
5

iZhihu

Zhihudaily powered by Node.js
JavaScript
150
star
6

create-slots

Bring slots to React component
TypeScript
93
star
7

Nevermore

a shadowsocks client powered by node-webkit
JavaScript
90
star
8

stickyard

Make your React component sticky the easy way
JavaScript
83
star
9

NeoReader

one reader for all
73
star
10

react-native-flanimatedimage

FLAnimatedImage for React Native
Objective-C
51
star
11

react-texty

A straight forward text component with tooltip support when it's truncated
JavaScript
20
star
12

seawind

TypeScript
10
star
13

react-native-leancloud

a react native component for leancloud javascript-sdk
Java
8
star
14

storybook-addon-react-runner

Storybook addon to provide react live preview powered by react-runner
JavaScript
4
star
15

AskWeather

a weather app written in React Native
CSS
2
star
16

react-esm

run React + TypeScript App without building tools
JavaScript
2
star
17

gatsby-remark-emoji-unicode

Gatsby plugin to convert emoji code to unicode
JavaScript
2
star
18

gatsby-using-dva

Gatsby example site that shows use of Dva
CSS
2
star
19

react-native-timer

a timer component for react-native
JavaScript
1
star
20

play-react

TypeScript
1
star
21

dsb

dead simple blog, based on nodejs, expressjs, ejs, marked
JavaScript
1
star
22

zhihudaily

Node.js 版知乎日报
1
star