Giter Club home page Giter Club logo

react-native-pie's Introduction

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

react-native-pie's People

Contributors

kevkevinpal avatar kpallik avatar msand avatar nihgwu avatar preeternal avatar shrichidambar avatar spencerlynn avatar zgordon01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-pie's Issues

How to make the pie clickable?

I wanna show a tooltip above every pie to show extra information. Is it possible to add an onPress handler and a view on every pie?

Use case requiring separation of series and color

In using this package, I can't imagine a use case that requires series and color to be in their own respective arrays. They will always have the same number of elements correct? Does anyone have an example where having more items in series than color is useful (or vice versa)?

I think it would be far more readable if we had a single items array, and properties of objects in items would be color and percentage.

Undefined is not an object

You library worked fined in react-native 0.47 but when I upgraded to 0.48.4 today, below error appeared any idea?

2017-10-05 7 03 36

Undefined is not an object (evaluating 'this.hex')

Error : TypeError: undefined is not an object (evaluating 'this.hex')

Usage:

import Pie from 'react-native-pie'

<Pie
                        radius={80}
                        sections={[
                            {
                                percentage: 10,
                                color: '#C70039',
                            },
                            {
                                percentage: 20,
                                color: '#44CD40',
                            },
                            {
                                percentage: 30,
                                color: '#404FCD',
                            },
                            {
                                percentage: 40,
                                color: '#EBD22F',
                            },
                        ]}
                        dividerSize={6}
                        strokeCap={'butt'}
                    />

RN version: 0.63.4
react-native-pie: 1.1.2
Device: Android 10 (emulator)

Missing License

There is no license file for this project. Would you accept a PR adding one?

Cannot read property 'slice' of null - when blank color passed

It's throwing this exception with some data:
image

I've tracked it down to sending a blank color '' in one of the bands which I can fix my end, but it would be better if the component is resilient enough to recover from such bad data, eg by defaulting bad colours to white or transparent rather than crashing the app.

Pie Label

Hello,

How to make the Pie Label, not in middle but in the slice of pie?

Thank you

How to add an image inside the pie

Hey
Im trying to add an image inside the pie but with no success:

    <View style={styles.statContainer}>
    {
      <Pie radius={43} innerRadius={33} series={series} colors={['#FFF', color, '#FFF']} backgroundColor='#DCDCE0' />
    }
    
    <View style={styles.gauge}>
      
        <ResponsiveImage
        style={{ backgroundColor: 'transparent' }}
        source={require('../assets/calories_gauge.png')}
        initWidth="1"
        initHeight="1" />
        
    </View>

How can I do that? thanks!

Migrating from react-native-community/art to react-native-svg

Migrating from react-native-community/art to react-native-svg

react-native-community/art is a deprecated library, and with JCenter becoming read-only on February 1st, 2022 a migration to react-native-svg should be done to avoid issues related to JCenter. RNSvg is the recommended replacement library for RNC/art as per the RNC/art readme.

A similar migration has been done to react-native-progress

custom pie

hi @nihgwu
thank for your lib.
i want to create space between lines and border radius lines.
like this. Could you tell me how to do this? Thank you.
screen shot 2018-06-02 at 9 50 41 pm

No component found for view with name "ARTShape"

Hi!
I am having the issue attached trying to render a pie defined as below:

                    <View>
                        <Pie
                            radius={50}
                            innerRadius={45}
                            series={[60]}
                            colors={['#f00']}
                            backgroundColor='#ddd' />
                        <View style={styles.gauge}>
                            <Text style={styles.gaugeText}>60%</Text>
                        </View>
                    </View>

I am using React Native 0.55

simulator screen shot - iphone 6 - 2018-04-18 at 23 17 12

Values on series

Sir I have a dynamic value for the pie [40,0,0,0] for the colors ['red', 'lime', 'blue', 'yellow', 'green']. Here was the output
capture _2018-01-08-14-05-16

Sir how can I fill the whole circle just like my values above. Thank you in advance!

Graphical Issue with Pie on Android

Hi!

I experience an issue with Pie on Android:
pie_android

Same code is working on iOS:
pie_ios

What's the reason for this behaviour?

Android version: 4.4.2

Thanks in advance.

can't animate series value (percentage) using Animated, why?

Animation should starts after pressing on TouchableOpacity. any ideas why does not it work?

export default class TimelapseButton extends Component{
  constructor(props) {
    super(props);

    this.state = {
      progress: new Animated.Value(10)
    }
  }

  countTime = () => {
     Animated.timing(this.state.progress, {
        toValue: 100,
        duration: 4000
     }).start();
  }

  render() {
    return (
        <View style={styles2.container}>
            <TouchableOpacity onPress={this.countTime} style={styles2.container}>
              <PieDemo series={this.state.progress._value}/>
            </TouchableOpacity>
        </View>
    );
  }
}

React Native - How to give this Curve Direction same as image

8RTJu

@nihgwu @msand @SpencerLynn @zgordon01 @kevkevinpal I am trying to create a donut pie chart in react-native where curve should be in clock direction. I achieved most of it to fulfil the requirement using plugin https://github.com/nihgwu/react-native-pie but I am not finding a way to change the direction.

If anyone has played around with this component then please suggest the code changes to meet the expected UI.

anyone please help me

The charts are not rendering after bundling

The charts are not rendering after bundling and in order to see changes I have to turn ON my toggle inspector.
Idea: Can we also implement each section as a clickable type, for Ex: clicking on Red section triggers an event and doing so on Green triggers another..?
screenshot_1540389589

duplicate key

Looks like artGroup using I for key and for each item on pie have a duplicate key

ExceptionsManager.js:126 Warning: Encountered two children with the same key, `3`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted โ€” the behavior is unsupported and could change in a future version.
    in ARTGroup (at Group.js:35)
    in Group (at Pie.js:129)
    in RoundDividers (at Pie.js:178)
    in ARTGroup (at Group.js:35)
    in Group (at Pie.js:169)
    in ARTSurfaceView (at Surface.js:37)
    in Surface (at Pie.js:168)
    in Pie (at ModaBuyingPower.tsx:105)
    in RCTView (at ModaBuyingPower.tsx:104)
    in RCTSafeAreaView (at SafeAreaView.js:55)
    in SafeAreaView (at ModaBuyingPower.tsx:98)
    in RCTView (at Paper.tsx:58)
    in Paper (created by Context.Consumer)

Features ?

Hi

would you make some changes or add features in the future?

Android not rendering Pie

Is there something particular I need to do to get Pie to render in Android? It works fine in iOS, but Android will not render the pie. I know it will render other items (I'm using it for markers in react-native-maps), because I have gotten those to show up, but Pie always comes back with nothing. There is no block or anything like that, it's just not there. Any help is appreciated.

Requirement of Library update for RN0.60+

Hello Admin, Can you please update for the React Native 0.60+ version.
I have tried different ways to add ART libraries but end the end they are not working with react native's new updated version (React Native 0.60+).

Can you please check and describe any way if any?

Border around pie

Hi and thanks for your awesome work!

I was wondering if I could somehow achieve the following pie:
screen shot 2018-07-16 at 16 58 24

I tried to add a background color in the color of the border, and then have a series like [20, 80] with colors: [blue, white], but the border is really tiny and almost can't be seen. Resulting in:

screen shot 2018-07-16 at 17 01 54

Android Series issue

<Pie
radius={80}
innerRadius={60}
series={[31,24,16,355,18,1,165]}
colors={['#f00', '#0f0', '#00f', '#ff0','green','blue','red']} />

passing values like this doesn't reflect in piechart shows only a constant color

Android series issue

<Pie
radius={80}
innerRadius={60}
series={[31,24,16,355,18,1,165]}
colors={['#f00', '#0f0', '#00f', '#ff0','green','blue','red']} />

passing values like this doesn't reflect in piechart shows only a constant color

No longer compatible with Expo?

I used this package about a year and a half ago (version ~0.6.0), and just recently came back to my project, and I'm getting an "Invariant Violation: requireNativeComponent: "ArtShape" was not found in the UIManager" error. I've installed @react-native-community/art but I'm unable to link it due to running on Expo (managed workflow). I assume this means this package is now incompatible with Expo?

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.