Giter VIP home page Giter VIP logo

react-native-charts-wrapper's Introduction

React Native Charts Wrapper

This library is React Native wrapper of popular Native charting library MPAndroidChart and Charts

Introduction

Inspired by react-native-mp-android-chart and react-native-ios-charts

React Native Charts Wrapper is built on MPAndroidChart(v3.1.0) & Charts(v3.3.0), support both android & iOS.

ANDROID

IOS

Supported Chart Type

  • Bar(Stack,Group)
  • Line
  • Scatter
  • Bubble
  • Pie
  • Radar
  • Combined
  • CandleStick

Setup

expo

  1. expo init demo
  2. cd demo
  3. expo install react-native-charts-wrapper
  4. eas build

react-native

  • npx react-native init demo
  • cd demo
  • npm install --save react-native-charts-wrapper
  • cd ios && pod install
  • npx react-native run-ios/run-android

update App.js

import React from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View, processColor
} from 'react-native';

import {LineChart} from 'react-native-charts-wrapper';

export default class App extends React.Component {

  render() {
    return (
      <View style={{flex: 1}}>
        <View style={styles.container}>
          <LineChart style={styles.chart}
            data={{dataSets:[{label: "demo", values: [{y: 1}, {y: 2}, {y: 1}]}]}}
          />
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF'
  },
  chart: {
    flex: 1
  }
});

Usage

There are 8 supported charts with many configuration options. Almost all configuration available in base MPAndroidChart library are available through this wrapper. More details on available configuration can be found on their wiki.

Example of how charts are used and how to apply configuration can be found in example.

Convention

Android and IOS have different convention:

  1. color's alpha in android is 0-255, in ios is 0-1
  2. percent in android is 0-100, in ios is 0-1
  3. animation.duration in MpAndroidChart is milliseconds, in Charts is seconds.
  4. their enum case name is always different, for example XAxisPosition, in MpAndroidChart is BOTH_SIDED, in Charts is bothSided.

Here we use android Convention

Always use processColor to set color

Data Format

  • Complete Form

      data : {
          ...
          dataSets: [
              {
                  values: [
                      {x: 5, y: 90},
                      {x: 10, y: 130},
                      {x: 50, y: 2000, marker: "eat more"},
                      {x: 80, y: 9000, marker: "eat less"}
                  ]
              },
              ...
          ]
      }Ï
    

marker is optional, if x is omitted, index will be used.

  • Simplified Form

      data: {
          ...
          dataSets: [
              {
                  values: [5, 40, 77, 81, 43]
              },
              ....
          ]
      }
    

index will used as x.

check Example->TimeSeriesLineChart for details

Supported Callbacks

onSelect

Triggered when a chart value is selected. The event passed back will include the coordinates of the touch as well as the data (including marker label) selected.

onChange

Triggered for various supported events on each platform. Due to the different nature of gesture handling on each platform as well as the different implementations of the underlying chart libraries, the same events are not supported on every platform. For full details on the supported events, see the table below:

Event Name Description iOS Android
chartScaled When a chart is scaled/zoomed via a pinch zoom gesture.
chartTranslated When a chart is moved/translated via a drag gesture.
chartPanEnd When a chart pan gesture ends.
chartGestureStart When a chart gesture starts.
chartGestureEnd When a chart gesture ends.
chartLongPress When a chart is long pressed.
chartSingleTap When a chart is single tapped.
chartFling When a chart recieves a fling gesture.
doubleTapped When a chart is double tapped

check Example->MultipleChart for details.

Direct Function Call

Support direct function call.

You can use chart.moveViewToX(...) or other functions directly.

check Example->MovingWindowChart for details.

supported functions:

  1. highlights([...])

    it can be used to highlight entries programmatically, or clear already highlighted entries if you pass empty array to it: highlights([])

  2. moveViewTo/moveViewToX/moveViewToAnimated/centerViewTo/centerViewToAnimated

  3. fitScreen

  4. setDataAndLockIndex

    It will rescale and move to the begining of your data when new data is set by default, this is not expected when you want to load more data when user scrolls.
    setDataAndLockIndex will remain x/y/zoom when you load more data.
    Because of the implementation of MpAndroidChart, if the action of setDataAndLockIndex is triggered by user dragging,
    then the range of new data (xMax - xMin) should be equal to original data(this basicly means size of new data equals to old one), otherwise the calculation of position transition won't be accurate,
    use may find the chart suddenly blink to another position.
    This restriction only exists in android, in iOS, we have no such problem.

    You can check the example InfiniteScrollLineChartScreen.

Special properties

Several extra properties are introduced:

  1. group&identifier&syncX&syncY

    They are useful when you want to implement linkage charts.

    Charts will sync its operation to other charts in the same group. All these sync jobs are done at native side.

    You can check the example LinkageChartScreen.

    Another way of syncing charts is to use onChange, but the performace is poor. You can check the example MultipleChartScreen.

    There is a stock kLine chart in example, it combines group&identifier and setDataAndLockIndex together.

Custom Marker Content

Support custom marker content.

check Example->TimeSeriesLineChart for details.

Notice

size of chart

you can set chart to fixed width & height, or flex:1

License

The MIT License

Copyright (c) 2017 wuxudong

Copyright (c) 2016 Martin Skec

Copyright (c) 2016 Jose E. Padilla

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

react-native-charts-wrapper's People

Contributors

acatalina avatar afladmark avatar ahanriat avatar china-mobile2008 avatar choiminseok avatar csotiriou avatar danceyoung avatar davidliu avatar dependabot[bot] avatar douglasjunior avatar ferrannp avatar germanmontejo avatar happylifedev001 avatar harunsmrkovic avatar hasan-aga avatar hellpirat avatar hexadecy avatar horodnicdragos avatar iday avatar idealllee avatar johnmartel avatar jonnylinja avatar kerlw avatar konclave avatar makoy21 avatar onestromberg avatar phantom1299 avatar rghorbani avatar varunvs avatar wuxudong 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  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

react-native-charts-wrapper's Issues

get custom property from bridge

hi, it's not a issue, just some question, feel free to close if need :)

I notice that in swift 2.0 previous project react-native-ios-charts define custom property in both header file and implement file, then get the value from js side via swift setter, I follow this way and it works well.

Today I upgrade my project to swift 3.0, strangely I notice that setter feature like setConfig no longer be called, I don't know how to get custom property value from js side in swift 3.0, and I check your smart project but also have no idea,

how should I get custom property value from js side in swift 3.0?

thanks for your time,

regards.

a better way to wrap ios code

I hope you can make an improvement to wrap ios source code in a library to avoid adding source code to Build Phrases -> compile sources

drawCircleHole not work

I add drawCircleHole property like below format to LineChart

data={{
  dataSets: [ { config: { drawCircleHole: true, circleHoleColor: processColor('yellow'), }, }, ...]
}}

but it seems not work, then I find that bridge config also receive drawCircleHole property, why does't make sense?

image

thanks for your time.

example npm install error

cd Example
npm install

`npm ERR! addLocal Could not install /home/ijoy/show
npm ERR! Linux 4.4.0-66-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v6.5.0
npm ERR! npm v3.10.3
npm ERR! code EISDIR
npm ERR! errno -21
npm ERR! syscall read

npm ERR! eisdir EISDIR: illegal operation on a directory, read
npm ERR! eisdir This is most likely not a problem with npm itself
npm ERR! eisdir and is related to npm not being able to find a package.json in
npm ERR! eisdir a package you are trying to install.

npm ERR! Please include the following file with any support request:`

Does this work on React-Native v0.43.4 or higher??

**packages versions**
react : 16.0.0-alpha.6,
react-native : 0.43.4,
react-native-charts-wrapper : 0.2.8,

Somehow I can't seem to get it work.. all I see using the examples is a white screen with a red vertical red line on the left side. Or am I doing anything wrong??

IOS blank chart

Hello everyone.
I am trying to generate the graphics in IOS and they appear blank. They work perfectly on the android.
All steps were performed.
Infos: Xcode Version 8.3.2
RN 0.43.4
captura de pantalla 2017-05-14 a la s 20 07 25

Thank you

ios support long press gesture?

thanks for your smart project.

I want to add callback which could pass x and y axis data in iOS side like android gesture of LongPressed effect, but I don't know which property could implements it.

please notice this link.
void onChartLongPressed(MotionEvent me);

thanks for your time.

regards :)

Not Working on IOS

The Pod install command for swiftyjson fails.

I tried manual install, I get errors saying:
2017-04-03 00:29:22.117 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNBarChart" does not exist
2017-04-03 00:29:22.117 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNHorizontalBarChart" does not exist
2017-04-03 00:29:22.117 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNBubbleChart" does not exist
2017-04-03 00:29:22.118 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNCandleStickChart" does not exist
2017-04-03 00:29:22.118 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNLineChart" does not exist
2017-04-03 00:29:22.119 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNPieChart" does not exist
2017-04-03 00:29:22.119 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNRadarChart" does not exist
2017-04-03 00:29:22.119 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNScatterChart" does not exist
2017-04-03 00:29:22.119 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNCombinedChart" does not exist

Trying to get it fixed for several hours, I tried the example for beginners step by step and couldn't get it to work either. can you advise?

Unable to edit EntryLabel on Pie Chat

The fields entryLabelColor and entryLabelTextSize do not appear to do anything on the pie chart. Setting them as

entryLabelColor={processColor('black')}
entryLabelTextSize={1}

simply returns the same white font. Same results no matter how I edit them.

This also occurs in the example application. All other functionality is as expected in my installation.

How to build with Xcode 8.3.2

screen shot 2017-04-28 at 15 05 40

You should make sure set this file in your target -> Build Settings -> Swift Compiler - General -> Object-C Bridging Header

Not found

horizontal barchart support?

hi, I find that no Horizontal BarChart exist in your lib at js side,

image

how should I use horizontal barchart?

thanks for your time.

LineChart 'highlightColor' property don't work in iOS?

I see the swift code 'highlightColor' is number, but you get it string in ChartDataSetConfigUtils.swift;
like:
error
so i change it, work is ok.

And are you plan config LineChart LeftAxis and Right Axis? Thank you for your time.

Position xAxis labels on iOS

Hello!

I'd like some help to get the labels onscreen. A little more to the left and it would be perfect.
I checked Charts wiki and tried setting spaceMin and spaceMax but it didn't seem to affect the labels.
screen shot 2017-04-10 at 16 59 34
screen shot 2017-04-10 at 16 59 24
Any ideas?
Thanks in advance 😊

Is valueTextColor not support?

const chartDataSetConfig = {
common: {
valueTextSize:PropTypes.number,
// ,,,
},

There is no valueTextColor or valueTextColors。。。

LineChart style

  1. How to config LeftAxis and Right Axis?
  2. How to style text color for xAxis, LeftAxis, RightAxis and points value?

Thanks!

Dificult

I'm new in iOs using and follow the installations steps, and copy the barchart example, but not work form me. The only thing i change was the width and height.

Result:

image

How to set decimal places to 0?

First of all big thanks for this awesome lib!

Does anyone know how to set decimal places to 0 so a value of 0 doesn't show up as .0?

image

com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;

android emulator.

npm install
react-native run-android

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)

:app:dexDebug FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/ijoy/tools/jdk1.8.0_101/bin/java'' finished with non-zero exit value 2

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.841 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

exception when I set animation property

hi, thanks for your latest release, it's wonderful :)

I encounter below error when I set animation property, I find that native thread will crash while js side could still run.

image

And if I remove animation property from my chart config object, all thing back to normal.

I try to figure out reason and have no idea, just provide my data config as below json format,

the first one is basic config before I fetch remote data, and the second one is fill data which be fetch from remote server.

would you mind take a look, I debug many times but cannot find any problem except the config possible.


basic config before fill remote data

basic_config.txt

fill remote data after http request
basic_config_with_filling_data.txt

thanks for your time,

regards.

Scroll zoomed chart to the end

@wuxudong thanks for the library!

I'm making a financial app that's using candlestick chart to show prices.

I need my chart to zoom my chart to show only latest X values out of hundreds available. I managed to do that with zoom prop.

Also, I need my chart to show the latest available value at the right side of the chart. By default it starts with the first value and the left side. Is there a way to do that?

LineChart disorder

Hey, first of all, thanks for an awesome component!

I have a problem regarding using it with a LineChart:

let lineData={
dataSets:[ {
values: [67, 25, 76, 82, 81, 79],
// ...
}],
};

let linexAxis = {
valueFormatter: [
'2016-11',
'2016-12',
'2017-01',
'2017-02',
'2017-03',
'2017-04',
],
};

I found when data set more than 4 length, the render is something wrong...

lineError.png

图片死活传不上,只好先放到临时网站上了。。

Install: No Swift Compiler - Objective-C Bridging Header option under build settings.

Attempting to integrate into existing project. Followed all the steps for install until it comes to linking the bridging header.

Docs state "You should make sure set this file in your target -> Build Settings -> Swift Compiler - General -> Object-C Bridging Header."

My project doesn't appear to have a Swift Compiler category under build settings, so there's no place for me to specify the bridging header.

screen shot 2017-04-18 at 9 29 51 pm

LineChartView doesn't show marker

It doesn't show MarkerView When clicking on a point in example ‘s lineChart.
code:
this.state = {
...
marker: {
enabled: true,
type: 'oval',
backgroundTint: processColor('teal')
}
...
};
<LineChart
style={styles.chart}
data={this.state.data}
description={{text: ''}}
legend={this.state.legend}
marker={this.state.marker}
... >< LineChart >

add code :(in LineChart props)
drawMarkers = {true}

Also wrong!

How to set Value Text Color For Barchart

data: {
dataSets: [{
values: [{y: 23}, {y: 105}, {y: 102}, {y: 110}, {y: 114}, {y: 109}, {y: 105}, {y: 99}, {y: 95}],
config: {
colors:[processColor('#d3d3d3')],
valueTextSize: 13,
valueTextColor: processColor('green'), // not working
valueFormatter: "##",
barSpacePercent: 40,
barShadowColor: processColor('lightgrey'),
highlightAlpha: 90,
highlightColor: processColor('red'),
}
}],
},

Thank you

rotationEnabled support

thanks wuxudong, this issue is for coming soon feature.

rotationEnabled should be added to pie and radar

Draw a lines with many colors

I dont find any implementation of multiple colors for Lines ? Like red before Y: 0 and green after Y:0. Is there a way to do that with that wrapper ?

package.json error

npm ERR! Failed to parse json npm ERR! Trailing comma in object at 25:1 npm ERR! } npm ERR! ^

remove comma
"Charts"
]

Gesture support

Hi,
Are planning to support more gesture callbacks like scale or doubletap?

compile error

hi, thanks for your help that merging ios and and project.

I also get many swift 3.0 compile error by following setup staging, how about your setup environment, maybe I did something wrong.

thanks for your time.

PS: I notice Charts project remove previous swift 3.0 support branch and some inner maintainer fork the new repo here, have you follow it in your test case?

how to custom xAxis value appropriatly

hi, in my project I want to custom xAxis value, like formatter, and I find that property valueFormatter could works in your Example LineChartScreen.js , but when I change the count, it will not sort appropriatly.

image

image

how should I sort them homogeneous?

thanks for your time.

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.