Git Product home page Git Product logo

react-native-pie-chart's Introduction

This repo is moved

From version 3.0.0, the code is rewritten, and the repo is moved here: https://github.com/aidin36/react-native-pie-chart Please open issues or pull requests on the new repository.

react-native-pie-chart

npm version npm downloads license

Simple pie chart module for your React Native app, for both iOS and Android.

Installation

You need to have react, react-native and @react-native-community/art as your app's dependencies.

~$ npm install react-native-pie-chart --save

For react-native versions older than 0.60 you need to manually install and link @react-native-community/art:

~$ npm install @react-native-community/art --save
~$ react-native link @react-native-community/art

Refer to their project repository for more information: https://github.com/react-native-art/art

Usage

Here's a quick start code. Refer to the example directory for a fully working app.

import React, { Component } from 'react';
import { StyleSheet, ScrollView , Text, View } from 'react-native';
import PieChart from 'react-native-pie-chart';

export default class TestChart extends Component {
  render() {
    const widthAndHeight = 250
    const series = [123, 321, 123, 789, 537]
    const sliceColor = ['#F44336','#2196F3','#FFEB3B', '#4CAF50', '#FF9800']

    return (
      <ScrollView style={{flex: 1}}>
        <View style={styles.container}>
          <Text style={styles.title}>Basic</Text>
          <PieChart
            widthAndHeight={widthAndHeight}
            series={series}
            sliceColor={sliceColor}
          />
          <Text style={styles.title}>Doughnut</Text>
          <PieChart
            widthAndHeight={widthAndHeight}
            series={series}
            sliceColor={sliceColor}
            doughnut={true}
            coverRadius={0.45}
            coverFill={'#FFF'}
          />
        </View>
      </ScrollView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center'
  },
  title: {
    fontSize: 24,
    margin: 10
  }
});

Example App

Have a look at the app in the example directory for how to write a simple app that shows two charts. To setup and run the example app follow these instructions:

# Clone package
~$ git clone https://github.com/genexu/react-native-pie-chart.git

# Setup ART and dependencies
~$ cd react-native-pie-chart/example
~$ npm install

# Run simulator
# Notice: plz make sure your simulator state is normal
~$ npx react-native run-ios
~$ npx react-native run-android

TypeScript

The npm package includes TypeScript types.

Upgrading from version one

The only breaking change between version one and two is chart_wh prop. It is renamed to widthAndHeight. Beside that, there shouldn't be any issue upgrading.

Props

Property Type Description Required Default
widthAndHeight Number chart width and height Yes
coverFill String doughnut cover fill color No #FFF
coverRadius Number doughnut cover radius No 0.6
doughnut Bool doughnut style No false
series Array < number > series data array Yes
sliceColor Array < string > series slice color array Yes
style Object pie chart style No {}

series should be a list of all positive (or zero) numbers. The sum of the series cannot be zero.

The size of the sliceColor array should be equal to the size of the series array.

react-native-pie-chart's People

Contributors

aidin-gh avatar aidin36 avatar awibox avatar dependabot[bot] avatar genexu avatar mithunm93 avatar sarmad1995 avatar sethvincent 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  avatar  avatar

react-native-pie-chart's Issues

No Component Found For View With Name ARTShape.

In your installation instruction it says the second step says link art , do you mean to run react-native link? if so then I think you should state that, but anyways I've ran react-native link and got an error, No component found for view with name ARTShape.

View.propTypes warnings

Looks like View.propTypes will be deprecated in future releases of ReactNative.

"Warning: View.propTypes has been deprecated and will be removed in a future version of ReactNative. Use ViewPropTypes instead"

what units for data series

Hi, can you tell me what units the series values are in; is it radians?
What would values be for a 50/50 pie chart for example?

Thanks for the help

Pie chart not rendering properly for a single value

Hey,

So I was trying to use the chart for a single value like so:
const series = [1];

And instead of drawing a circle it messes it up as shown:
Issue

What I'm trying to accomplish is a dynamic pie chart with three values in the series, so if one of them is say 0, that is
const series = [0, 25, 52];

It should just render the pie chart with two values. Is there a better way to accomplish that? Because passing 1 value in causes that issue.

Thanks!

edit: Forgot to mention I'm testing on an Android device.

Would like to become the maintainer

Hi @genexu,

I would like to become the maintainer of this package. My company (https://github.com/movio/) uses this package in one of its apps. It's a nice little package that does the job and we don't need to add some large dependencies to our app just to draw a pie chart.

You did a great job writing this package. I understand you don't have time anymore to maintain this. So I decided to step up and take the responsibility, so this useful package can live on.

Please let me know what do you think.

Invariant Violation: ART has been removed from React Native. It can now be installed and imported from '@react-native-community/art' instead of 'react-native'

"react-native": "0.64.2"
"react-native-pie-chart": "^1.0.13"
"@react-native-community/art": "^1.2.0"

I've recently updated my RN version along with the RNPC version to the listed above, but keep getting this error. Although, have seen there's no need to link @react-native-community/art manually. I did hope that it would work out of the box but didn't.
Any possible workaround for this would be of great help.
Thanks!

Show warning after Pie style prop update

@mithunm93
I'm doing further testing today, use newest version react-native, and it will show warning after Pie style prop update, did you have same problem?

In addition, can you show me propType errors you say at original version? I don't get any error at original version, so i want to see what error it is.(original version mean the version before merge you PR)

screen shot 2017-04-22 at 8 40 01 pm

Error in rendering pie chart (angle greater than 360)

With this series

[789669, 530000, 40149, 3236, 16358, 26]

in index.tsx, the expression

previous[previous.length - 1] + Math.round((360 * current) / sum)

returns an angle greater than 360.

Math.round should be changed in Math.floor

Request for transferring the ownership

Hi @genexu,

I hope you're fine and everything is alright. (:

I have a favor to ask.

As you might know, the "@react-native-community/art" package is deprecated (#49). So, I rewrote the code of the package to use "react-native-svg" and "d3". I ended up re-writing the whole code!
So I thought, I move it under my own Github account. So I can also have admin access to the repo.

Will you be kind enough to transfer the ownership of the repo to me? In that way, the starts, issues, PRs, etc will remain. Including your credit, as the main designer/contributor.
It's fine if you don't want to. I can create a new repo. But it will be a pity to lose all the history.

Please let me know what you think.

Many thanks,

Disappearing chart on screen off.

Hey,

So I'm having a strange issue with the pie chart disappearing if the screen is turned off and turned back on. I could not figure out a way to re-render the chart in such a scenario. What's going on here?

Thanks!

Error: Unable to resolve module @react-native-community/art

After I install react-native-pi-chart via 'yarn add react-native-pie-chart', the developer console shows error as belows.

error: Error: Unable to resolve module @react-native-community/art from D:\working\CovidTracker\node_modules\react-native-pie-chart\dist\Pie.js: @react-native-community/art could not be found within the project or in these directories:
node_modules\react-native-pie-chart\node_modules
node_modules

If you are sure the module exists, try these steps:

  1. Clear watchman watches: watchman watch-del-all
  2. Delete node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-*

Is there any good way to tackle this issue?

RN version=0.41.2 upgrade version to 1.0.12

hi @genexu I have a issue in my project.
My RN version is 0.41.2 , and the 'react-native-pie-chart' upgrade version to 1.0.12 , there hava a issue style: ViewPropTypes.style,

Have there a low version for 0.41.2 .

Thank you very much!!!!!!

Pie Chart

While using piechart if we provide 0,0 value in series it crashes application.

Try :
series={[0,0,0]}

Invariant Violation: requireNativeComponent: "ARTShape" was not found in the UIManager

While using an expo app (managed workflow), I run into the error while running this code:

<PieChart
    widthAndHeight={250}
    series={[123, 321, 123, 789, 537]}
    sliceColor={['#F44336','#2196F3','#FFEB3B', '#4CAF50', '#FF9800']}
 />

I simply made sure to install the following packages: react, react-native and @react-native-community/art and ran the app. Is there some additional setup that is required? Or is this just incompatible with expo apps?

Versions:
"@react-native-community/art": "^1.2.0",
"react": "18.1.0",
"react-native": "0.70.5",

Thanks in advance!

Android support

Are you planning to support Android as well? Your iOS implementation works perfect for me, but require Android support as well for my project. Thanks in advance.

A number sequence produces the wrong chart proportions

This gives me a completely green donut.
const chart_wh = 300
const series = [7, 2, 13, 0]
const sliceColor = ['#F44336','#2196F3','#FFEB3B', '#4CAF50']

Adding an extra 0 to series gives me the right proportions though
const chart_wh = 300
const series = [7, 2, 13, 0, 0]
const sliceColor = ['#F44336','#2196F3','#FFEB3B', '#4CAF50']

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.