Code Monkey home page Code Monkey logo

abhinandan-kushwaha / react-native-gifted-charts Goto Github PK

View Code? Open in Web Editor NEW
581.0 581.0 125.0 14.05 MB

The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.

Home Page: https://www.npmjs.com/package/react-native-gifted-charts

License: MIT License

JavaScript 2.59% Starlark 0.75% Java 2.43% Objective-C 1.75% Ruby 0.85% TypeScript 91.64%
area-chart barchart charts data-visualization donut-chart graph line-charts pie-chart piechart population pyramid pyramid-chart react-native

react-native-gifted-charts's Introduction

react-native-gifted-charts Rate on Openbase

The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.

Yet another chart library? Why?

To bring Life to your data

  1. Plenty of features with minimal code
  2. Apply animations to your charts on load and on value change, just by adding a prop
  3. Smooth animations implemented using LayoutAnimation
  4. Clickable and scrollable
  5. Three-D and gradient effects
  6. Fully customizable (see the props)
  7. Detailed documentation with examples
  8. Support for combined Bar and Line charts

๐Ÿ“ฃ Announcement

The web counterpart of this library is public now. Try out our new reactJS library- react-gifted-charts
The exact same piece of code that you write to render charts in react-native, can be used to render charts in reactJS using this library!


Installation

React Native CLI

npm install react-native-gifted-charts react-native-linear-gradient react-native-svg

Expo

npx expo install react-native-gifted-charts expo-linear-gradient react-native-svg

Please note that react-native-svg and react-native-linear-gradient/expo-linear-gradient are needed for the library to work, so make sure they are installed in your project.

Docs

Documentation and gallery

Usage

The simplest usage of various types of charts can be done as below-

import { BarChart, LineChart, PieChart, PopulationPyramid } from "react-native-gifted-charts";

// ...
const data=[ {value:50}, {value:80}, {value:90}, {value:70} ]

<BarChart data = {data} />
<LineChart data = {data} />
<PieChart data = {data} />
<PopulationPyramid data = {[{left:10,right:12}, {left:9,right:8}]} />

// For Horizontal Bar chart, just add the prop horizontal to the <BarChart/> component

<BarChart data = {data} horizontal />

// For Area chart, just add the prop areaChart to the <LineChart/> component

<LineChart data = {data} areaChart />

// For Donut chart, just add the prop donut to the <PieChart/> component

<PieChart data = {data} donut />

Props tables

1. BarChart, Horizontal BarChart and Stacked Bar Chart props
2. LineChart and AreaChart props
3. PieChart and DonutChart props
4. Population Pyramid props

Contributing

This project exists thanks to all the people who contribute.



Dear developers! Your small contribution can make someone's day ๐Ÿ˜Š

One of the ways you can contribute is to address an open issue.

Sometimes people report issues which don't exist, or request for features which are already present. Such issues can be addressed without pushing any code to the repo. Just show them in the comments how to do it.

See the contributing guide to learn how to contribute to the repository and the development workflow.

To do list

License

MIT

react-native-gifted-charts's People

Contributors

abeyuya avatar abhi-amci avatar abhinandan-kushwaha avatar abhinandan1234 avatar ak-spotter avatar andy-leezard avatar aphromad avatar araphiel-nf avatar christophby avatar descyther avatar fstefanello avatar hkellou-vitalcare avatar jardelbordignon avatar linkeddg avatar maurosaladino avatar onyx-flame avatar patrickkabwe avatar sabuhiteymurov avatar wari-dudafa avatar yash-tronx 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

react-native-gifted-charts's Issues

Label positioning

Hi,

Is it possible to add a bit more customisation for labels on the x axis? it's difficult to get them lined up.

You can currently add labelWidth. Are you able to add labelX so that you can adjust the left position of the View?

So something like this (from line 107 in RenderBars.tsx):

<View
        style={[
          {
            width:
              (item.labelWidth ||
                props.labelWidth ||
                item.barWidth ||
                props.barWidth ||
                30) ,
            left: props.labelX,
            position: 'absolute',
            backgroundColor:'orange',
            bottom: rotateLabel ? -40 : -25,
          },
          rotateLabel
            ? props.horizontal
              ? {transform: [{rotate: '330deg'}]}
              : {transform: [{rotate: '60deg'}]}
            : props.horizontal
            ? {transform: [{rotate: '-90deg'}]}
            : {},
        ]}>
        {item.labelComponent ? (
          item.labelComponent()
        ) : (
          <Text
            style={[labelTextStyle, {textAlign: 'center'}]}
            numberOfLines={1}>
            {label || ''}
          </Text>
        )}
      </View>

Thanks!

Automatic scroll to right for Line Chart

Hello!

First off, I just want to say this library has been fantastic and been a great solution thus far for our needs. Thank you for the great work.

I saw a previously closed ticket addressing automatic scrolling to right. I left a comment there but wasn't sure if that was the appropriate place. I implemented based on the suggestion of adding scrollToEnd. I see it's available for Bar Charts, but I'm unable to get it to work with Line Charts. Is there any plans to implement on Line Charts?

Thank you!

Separate data for line chart with combined Bar chart.

Thanks โค๏ธ for this awesome library..
Is it possible to pass separate data for Line chart which is combined in Bar chart.
I need to draw a horizontal straight line (Average value) in barchart.

<BarChart
  width={DisplayUtils.setWidth(72)}
  data={servingTimeGraphData}
  barWidth={30}
  spacing={20}
  xAxisThickness={0.5}
  yAxisThickness={0.5}
  yAxisTextStyle={{ fontSize: 13, color: Colors.BLACK_COLOR }}
  noOfSections={4}
  maxValue={0}
  isAnimated={true}
  initialSpacing={8}
  scrollToEnd
  hideRules
  showLine
  lineConfig={{
     delay: 1, isAnimated: true,
      data: [{ value: 25 }, { value: 25 }] //Like this or any other..
  }}
/>

Seems like now the line chart uses the same data of Barchart.
IMG_250D6F24E5E8-1

Expected chart like this

IMG_19A9B6F5B32D-1

Support for Y-Axis labels on right side?

Hi,

I'm interested in using this package but have a specific requirement for something I'm trying to implement. Is it possible to set up the layout so the Y-Axis labels are on the right side of the chart, similar to this:

5993a5c3-a185-414c-ab38-56d37c2b38f0

Thanks!

BarChart - Value and section line don't match

Hi,
Thanks for this amazing package. However, I'm facing this issue with the BarChart component:
Please check this image for more comprehensive: Screenshot
The bars' values are 3 and 6, but their tops don't reach the relevant section lines.

Prop for text font

Hi, Thanks for an awesome library. I would be great, if you can add prop to set text font. e.g. prop to set fontStyle and fontFamily for text labels.

ShowVerticalLine isn't the height of the chart

Was hoping to use showVerticalLine to render on specific data points while looking similar to the chart prop showVerticalLines where the lines are the height of the chart.

Using showVerticalLine however only goes to the height of the data point.

Screen Shot 2022-03-10 at 2 03 05 PM

Need Semi Donut Chart

Can we have the option of customizing the donut chart to semi donut?

32

Need to customize semi donut chart in this format.

minValue for LineChart

Hi again ๐Ÿ‘‹

I was wondering if there's a way to provide a minValue to the LineChart? One of the charts I'm trying to implement is a line chart that has no use for values under 100, it's making the chart unreadable so I would rather limit the range shown.

Screen Shot 2022-02-23 at 11 34 01 AM

OnPress not working at all?

Can we get a complete example for onPress so that we can test locally and figure out why our graph functionality isn't working.

I have these following props set and nothing is triggered. Not using the graph inside tab-view / horizontal scrollview etc, so that is not the issue.

pressEnabled={true}
showDataPointOnPress={true}
showStripOnPress={true}
showTextOnPress={true}
focusedDataPointShape={"orange"}
focusedDataPointColor={"blue"}
focusedDataPointRadius={5}
onPress={() => console.log("hey!")}

Bar Chart label is not in the middle of the bar

image
Like the title, the X label is not in the middle of the bar.
Here is my config for the bar chart
<BarChart barWidth={50} noOfSections={4} spacing={80} initialSpacing={50} maxValue={max.value} labelWidth={100} barBorderRadius={4} stepValue={(max.value - 0) / 4} frontColor="lightgray" data={showChart} />

BarChart floating away element

I'm trying to add the bars inside a card, but it has a fixed size and is floating outside the element.

When I set the maxValue or height it cuts the bar.

in short: it is not possible to change the size of bars, pie, donut etc.

Bug: Donut chart doesn't load on mount

I'm having an issue where the donut chart only shows the center components on load, then in the console it outputs Did not receive response to shouldStartLoad in time, defaulting to YES and then it loads the rest of the chart. It does it in dev and in production.

Any ideas how to fix it?

Excellent library btw. You're doing great work.

RN 0.66.3
Gifted Charts 1.0.5
RN Webview 11.0.3

Reference line option isn't provided in the props

Great library with ease of use. In the library examples as well in the documentation, the following graph is provided,
image

but, neither does the dotted reference line appear if we implement the example nor does the library has properties for any such lines. Is there any possibility to have that reference line in a bar chart/any chart?

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

I use barchart it warns:
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it.
in RCTView (at View.js:32)
in View (at ThreeDBar/index.tsx:159)
in RCTView (at View.js:32)
in View (at ThreeDBar/index.tsx:75)
in ThreeDBar (at RenderBars.tsx:333)
in RCTView (at View.js:32)
in View (at createAnimatedComponent.js:242)
in AnimatedComponent (at createAnimatedComponent.js:295)
in AnimatedComponentWrapper (at TouchableOpacity.js:228)
in TouchableOpacity (at TouchableOpacity.js:278)
in TouchableOpacity (at RenderBars.tsx:264)
in RenderBars (at BarChart/index.tsx:1025)
in AndroidHorizontalScrollContentView (at ScrollView.js:1674)
in AndroidHorizontalScrollView (at ScrollView.js:1792)
in ScrollView (at ScrollView.js:1818)
in ScrollView (at BarChart/index.tsx:966)
in RCTView (at View.js:32)
in View (at BarChart/index.tsx:956)
in BarChart (at HomeScreen.js:48)
in RCTView (at View.js:32)
in View (at HomeScreen.js:47)
in HomeScreen (at SceneView.tsx:126)
in StaticContainer
in EnsureSingleNavigator (at SceneView.tsx:118)
in SceneView (at useDescriptors.tsx:210)
in RCTView (at View.js:32)
in View (at Screen.tsx:63)
in RCTView (at View.js:32)
in View (at Background.tsx:13)
in Background (at Screen.tsx:58)
in Screen (at BottomTabView.tsx:129)
in MaybeFreeze (at src/index.native.tsx:229)
in RNSScreen (at createAnimatedComponent.js:242)
in AnimatedComponent (at createAnimatedComponent.js:295)
in AnimatedComponentWrapper (at src/index.native.tsx:208)
in Screen (at ScreenFallback.tsx:37)
in MaybeScreen (at BottomTabView.tsx:122)
in RNSScreenContainer (at src/index.native.tsx:277)
in ScreenContainer (at ScreenFallback.tsx:28)
in MaybeScreenContainer (at BottomTabView.tsx:93)
in RCTView (at View.js:32)
in View (at SafeAreaProviderCompat.tsx:42)
in SafeAreaProviderCompat (at BottomTabView.tsx:92)
in BottomTabView (at createBottomTabNavigator.tsx:116)
in Unknown (at createBottomTabNavigator.tsx:115)
in BottomTabNavigator (at Main.js:16)
in Main (at SceneView.tsx:126)
in StaticContainer
in EnsureSingleNavigator (at SceneView.tsx:118)
in SceneView (at useDescriptors.tsx:210)
in RCTView (at View.js:32)
in View (at DebugContainer.native.tsx:27)
in DebugContainer (at NativeStackView.native.tsx:71)
in MaybeNestedStack (at NativeStackView.native.tsx:230)
in MaybeFreeze (at src/index.native.tsx:229)
in RNSScreen (at createAnimatedComponent.js:242)
in AnimatedComponent (at createAnimatedComponent.js:295)
in AnimatedComponentWrapper (at src/index.native.tsx:208)
in Screen (at NativeStackView.native.tsx:176)
in SceneView (at NativeStackView.native.tsx:278)
in RNSScreenStack (at src/index.native.tsx:160)
in ScreenStack (at NativeStackView.native.tsx:269)
in NativeStackViewInner (at NativeStackView.native.tsx:323)
in RNCSafeAreaProvider (at SafeAreaContext.tsx:76)
in SafeAreaProvider (at SafeAreaProviderCompat.tsx:46)
in SafeAreaProviderCompat (at NativeStackView.native.tsx:322)
in NativeStackView (at createNativeStackNavigator.tsx:67)
in NativeStackNavigator (at App.js:17)
in EnsureSingleNavigator (at BaseNavigationContainer.tsx:430)
in BaseNavigationContainer (at NavigationContainer.tsx:132)
in ThemeProvider (at NavigationContainer.tsx:131)
in NavigationContainerInner (at App.js:16)
in App (at SVONLINE_/index.js:14)
in ThemeProvider (at Provider.tsx:104)
in RCTView (at View.js:32)
in View (at PortalHost.tsx:125)
in Portal.Host (at Provider.tsx:102)
in Provider (at SVONLINE_/index.js:13)
in Main (at renderApplication.js:50)
in RCTView (at View.js:32)
in View (at AppContainer.js:92)
in RCTView (at View.js:32)
in View (at AppContainer.js:119)
in AppContainer (at renderApplication.js:43)
please help me fix this error
thanks you!
code:
import {BarChart} from 'react-native-gifted-charts';
import React, {useEffect} from 'react';
import {View} from 'react-native';

const HomeScreen = () => {
const barData = [
{
value: 230,
label: 'Jan',
frontColor: '#4ABFF4',
sideColor: '#23A7F3',
topColor: '#92e6f6',
},
{
value: 180,
label: 'Feb',
frontColor: '#79C3DB',
sideColor: '#68BCD7',
topColor: '#9FD4E5',
},
{
value: 195,
label: 'Mar',
frontColor: '#28B2B3',
sideColor: '#0FAAAB',
topColor: '#66C9C9',
},
{
value: 250,
label: 'Apr',
frontColor: '#4ADDBA',
sideColor: '#36D9B2',
topColor: '#7DE7CE',
},
{
value: 320,
label: 'May',
frontColor: '#91E3E3',
sideColor: '#85E0E0',
topColor: '#B0EAEB',
},
];
useEffect(() => {

}, []);
return (



);
};
export default HomeScreen;

Automatically scroll to right or start from right side of the chart

Hi,

For example I'm using monthly data to show, and origin at x axis my data starts from 30 days ago and continues to today through right side. User need to scroll right to see his/her most recent data.

So, can you please provide a prop like automatically start from right or automatically scroll to right to user sees his most recent data at first.

Thank you!

x Axis label color

Hi
I have found out that my x-axis where it says days is colour white and I want it to change to another colour.
I tried to call label color - didn't work
I tried from BarChart all colour props and it didn't work.

I read almost the whole document.. maybe I have missed it?

span horizontal rule lines to the end of the container

Make rule lines and the horizontal x-axis line span to the end of the container irrespective of less amount of data.

The below Image show the current problems where the horizontal rule line stop just after August. I want it to continue to the end of the container
Screenshot 2022-02-17 at 10 48 39 PM

Redundant Space at top of Bar Chart

Hi,

Just wondering if it's possible to get rid of the redundant space at the top of the bar chart - highlighted the background in red to show the space at the top:

Screenshot 2022-01-20 at 17 10 34

Thanks

.

donut chart stroke width not working

Strokewidth is not working properly for donut chart

Resolve this issue ASAP!! largely dependent on this stroke width for data viewing

Versions :
"react": "17.0.2",
"react-native": "0.65.1",
"react-native-gifted-charts": "^0.1.14"

Screenshot_1635758587

Code :

const pieData = [
{
value: 25,
color: '#FFC107',
textBackgroundColor: '#FFC107',
textColor: '#343A40',
textSize: 12,
},
{
value: 25,
color: '#FAD76F',
textBackgroundColor: '#FAD76F',
textColor: '#343A40',
textSize: 12,
},
{
value: 25,
color: '#F7E3A7',
textBackgroundColor: '#F7E3A7',
textColor: '#343A40',
textSize: 12,
},
{
value: 25,
color: '#F5EBCD',
textBackgroundColor: '#F5EBCD',
textColor: '#343A40',
textSize: 12,
},
];
<PieChart
data={pieData}
donut
innerRadius={55}
radius={110}
showText={true}
showValuesAsLabels={true}
showTextBackground={true}
strokeWidth={20}
strokeColor={'green'}
/>

Do I need to call useEffect?

Hi,
Thank you so much for this API. I really love to read your documents and examples! First-time me having stressless!! Bravo!!

I have two questions!

  1. Is it in Typescript? I see from index**.tsx** , it would be awesome if you update npm site that it can "speak" in typescript :) You know that small icon TS.

I took an example from a graph with days
When I want to change the value from 250 to 500 like this
const barData = [ {value: 250, label: 'M'}, // I WANT TO CHANGE E.G. 500 ...
when I press save the phone react-native doesn't show up, instead, I need to refresh the app. I wonder if I need to call useEffect?
But I can see in index.tsx that you have already called useEffect?
I am a bit confused , plz help :)

Feature request: Pie chart animation

Is it possible to animate Pie chart?
Also, can we align the value text labels to the center?

 <PieChart
  strokeColor="white"
  strokeWidth={2}
  donut
  data={pieData}
  showText
  extSize={16}
  />

IMG_0B513A6FAFAC-1

Screen.Recording.2022-02-21.at.7.35.26.PM.mov

onPress on StackBar not working

The onPress function passed to StackedBar is not firing. The opacity on the bar is detected but the function never gets called.

..................... stacks: [ { value: 10, color: "#4ABFF4" }, { value: 11, color: "orange", marginBottom: 2 }, { value: 15, color: "#28B2B3", marginBottom: 2, onPress: () => { console.log("hi___"); }, }, ], label: "Mar", }, .....................

Can't find a way to add legend to stacked bar chart

Hello.

First of all thank you for your great plugin. It is totally helpful.

I'm using the stacked bar chart.

I'm looking for a way to add a legend next to each part of a stacked bar chart so that the users are able to visually identify what each (colored) part of the stacked bar chart represents.

Thanks again.

Negative Values

Hey there,

We could not render negative values with any charts. Could not find any documentation about it. Do you have any plan supporting negative values? If so, I can help you with that.

Code:
const data=[ {value:-25}, {value:-45}, {value:-35}, {value:-95}] <BarChart data = {data} />

Result:
Screen Shot 2022-02-01 at 10 21 51

Add Y-Axis label above the bar in bar chart

Hi, I just wondered if it was possible to add the value above each bar in the bar chart? I can see it on the screenshots etc, but there isn't documentation for this feature.

X-Axis Linechart (AreaChart) Label

Going through the documentation, I have not seen the equivalent of yAxisLabelTexts={ [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]} for X-Axis.

I want this to be xAxisLabelTexts={ [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]} so it shows on x axis instead but it does not work.

Some props in the documentation are not actually implemented?

@Abhinandan-Kushwaha

Documentation states you can set yAxisLabelText as data point for y-axis data point, however this does not work.

Checking the code, there is no mention of this field anywhere:


I need this because when using yAxisLabelTexts you have to pick your labels very carefully to make sure they match the graph boundaries and I don't want to handle this myself.

I would much rather prefer to set the y-label for each data point and let your library do the existing heavy lifting.

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.