Giter VIP home page Giter VIP logo

react-native-chart-android's Introduction

react-native-chart-android

react-native-chart-android provide modules to add chart to android,all charts are come from mpandroidchart library,include bar chart ,line chart,combine chart etc.

about MpAndroidChart ,you can read doc:

-MPAndroidChart-github -MPAndroidChart-Wiki

Installation

npm install react-native-chart-android --save

Add it to your android project

  • In android/setting.gradle
include ':react-native-chart-android'
project(':react-native-chart-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-chart-android/android')
  • In android/app/build.gradle
...
dependencies {
  ...
  compile project(':react-native-chart-android')
}
  • Register Module (in MainApplication.java)
import cn.mandata.react_native_mpchart.MPChartPackage;  // <--- import

public class MainActivity extends ReactActivity {

    ......

    /**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new ReactNativeIcons(Arrays.asList(
                        new IconFont("typicons", "typicons.ttf"),
                        new IconFont("fontawesome", "FontAwesome.otf")
                )),
                new MPChartPackage(),// <------ add this line to yout MainActivity class
                new ManDataLibPackage(),
                new BaiduVoiseLibPackage()
        );
    }
    ......
}

Example

/* @flow */
'use strict';

var React = require('react-native');
var TitleBar=require('./TitleBar');
var {
  BarChart,
  CombinedChart
}=require('../index.android');
var {
  StyleSheet,
  View,
  Text
} = React;

var Component = React.createClass({
  getBarData:function (argument) {
    var data={
      xValues:['1','2','3'],
      yValues:[
        {
          data:[4.0,5.0,6.0],
          label:'test1',
          config:{
            color:'blue'
          }
        },
        {
          data:[4.0,5.0,6.0],
          label:'test2',
          config:{
            color:'red'
          }
        },
        {
          data:[4.0,5.0,6.0],
          label:'test2',
          config:{
            color:'yellow'
          }
        }
      ]
    };  
    return data;
  },
  getRandomData:function (argument) {
    var data={};
    data['xValues']=[];
    data['yValues']=[
      {
        data:[],
        label:'test1',
        config:{
          color:'blue'
        }
      }
    ];
    for (var i = 0; i < 500; i++) {
      data.xValues.push(i+'');
      data.yValues[0].data.push(Math.random()*100);
    };
    return data;
  },
  render: function() {
    return (
      <View style={styles.container}>
        <TitleBar/>
        <View style={styles.chartContainer}>
          <BarChart style={{flex:1}} data={this.getBarData()}/>
         
          <BarChart 
            style={{flex:1}} 
            data={this.getRandomData()}
            visibleXRange={[0,30]}
            maxVisibleValueCount={50} 
                xAxis={{drawGridLines:false,gridLineWidth:1,position:"BOTTOM"}}
                yAxisRight={{enable:false}} 
                yAxis={{startAtZero:false,drawGridLines:false,position:"INSIDE_CHART"}}
                drawGridBackground={false}
                backgroundColor={"WHITE"} 
                description={"测试"}
                legend={{enable:true,position:'ABOVE_CHART_LEFT',direction:"LEFT_TO_RIGHT"}}
            />

           <LineChart 
             style={{flex:1}} 
             data={this.getRandomData()}
             visibleXRange={[0,30]}
             maxVisibleValueCount={50} 
             xAxis={{
              drawGridLines:false,
              gridLineWidth:1,
              position:"BOTTOM",
              labelRotationAngle: 12.0,
              spaceBetweenLabels: 10,
            }}
             yAxisRight={{enable:false}} 
             yAxis={{
              startAtZero:false,
              drawGridLines:true,
              position:"OUTSIDE_CHART",
              textColor: "#E94343"
              }}
             drawGridBackground={false}
             backgroundColor={"#FAFAFA"} 
             description={"Line Chart sample"}
             legend={{enable:true,position:'ABOVE_CHART_LEFT',direction:"LEFT_TO_RIGHT", legendForm: "CIRCLE"}}
             pinchZoom={true}
             dragDecelerationFrictionCoef={0.5}
             noDataText={"No data available"}
             onSelect={(e) => {
              console.log("onSelect xIndex", e.nativeEvent.xIndex, "yValue:", e.nativeEvent.yValue);
            }}
         />
        </View>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container:{
    flex:1
  },
  chartContainer:{
    flex:1
  },
  chart:{
    flex:1
  }
});


module.exports = Component;

alt tag

alt tag

There are some samples in sample folder,you can download them and try to run them.

License

MIT

react-native-chart-android's People

Contributors

amanagr avatar anmolakhilesh avatar arman92 avatar cnjon avatar dima7a14 avatar dmhood avatar farzadab avatar hongyin163 avatar ianaz avatar kielan avatar lammertw avatar mahlon-gumbs avatar mijia avatar prithsharma avatar quinnstephens avatar raininfall avatar wkwyatt avatar xwartz avatar yiwang20 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

react-native-chart-android's Issues

bug

当npm install安装组件的后,编译提示merge androidManifest.xml error:line 7

解决:
删掉android/src/main/AndroidManifest.xml中的第七行
android:icon="@mipmap/ic_launcher"

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.mandata.react_native_mpchart">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>

不知是不是这个是否是bug?如果是希望作者更新下npm中的代码库

Build failure for react-native run-android

My react native run android fails with following error:

C:\Users\abhay\React\infp_devices\android\app\src\main\java\com\infp_devices\MainActivity.java:19:
error: cannot find symbol
protected List getPackages() {
^ symbol: class List location: class MainActivity C:\Users\abhay\React\infp_devices\android\app\src\main\java\com\infp_devices\MainActivity.java:19:
error: cannot find symbol
protected List getPackages() {
^ symbol: class ReactPackage location: class MainActivity
C:\Users\abhay\React\infp_devices\android\app\src\main\java\com\infp_devices\MainActivity.java:18:
error: method does not override or implement a method from a supertype
@OverRide
^ C:\Users\abhay\React\infp_devices\android\app\src\main\java\com\infp_devices\MainActivity.java:21:
error: cannot find symbol
new MainReactPackage(),
^ symbol: class MainReactPackage location: class MainActivity
C:\Users\abhay\React\infp_devices\android\app\src\main\java\com\infp_devices\MainActivity.java:20:
error: cannot find symbol
return Arrays.asList(
^ symbol: class ReactPackage location: class MainActivity
C:\Users\abhay\React\infp_devices\android\app\src\main\java\com\infp_devices\MainActivity.java:20:
error: cannot find symbol
return Arrays.asList(
^ symbol: variable Arrays location: class MainActivity 6 errors :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

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

Compilation failed; see the compiler error output for details.

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

BUILD FAILED

I have made following changes :

In android/setting.gradle :

include ':react-native-chart-android'
project(':react-native-chart-android').projectDir = new 
File(rootProject.projectDir, '../node_modules/react-native-chart-
android/android')

In android/app/build.gradle:

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_module
    compile project(':react-native-chart-android') //Changes to the code
}

My entire android/app/src/main/java/com/xxxxxxx/MainActivity.java, (XXXXXXX is my app name), looks as follows :

package com.xxxxxxx;  // xxxxxxx is my app name

import com.facebook.react.ReactActivity;

import cn.mandata.react_native_mpchart.MPChartPackage;  // <--- import

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "xxxxxxx";   //xxxxxxx is my app name
        }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new MPChartPackage());
}
}

My application code looks as follows :

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

import {
  BarChart,
  CombinedChart
} from 'react-native-chart-android';

import { getBarData } from './graphComponent';


const graphDisplay = (props) => {
  // const myData = getBarData();
  return (
    <View style={{flex:1}}>
      <BarChart style={{flex:1}} data={getBarData()} />
   /View>
    );
});

export default graphDisplay;

I get a fatal ESLint error on the BarChart tag line as "Unterminated JSX content (Fatal)". However I have not got around to solving it. Not sure if it is relevant for this problem.

Please help

Edited:

My code for the imported getBarData() function is as follows:

export function getBarData() {
  const data = {
    xValues: ['1', '2', '3'],
    yValues: [
      {
        data: [4.0, 5.0, 6.0],
        label: 'test1',
        config: {
          color: 'blue'
        }
      },
      {
        data: [4.0, 5.0, 6.0],
        label: 'test2',
        config: {
          color: 'red'
        }
      },
      {
        data: [4.0, 5.0, 6.0],
        label: 'test2',
        config: {
          color: 'yellow'
        }
    }
    ]
  };
  return (data);
}

Animation support

I noticed that the last merged pull request includes animation support. I'd love to use that in my app. Could you please make a new release that includes it? ☺️

能触摸数据响应事件吗

您好,请问这个组件能支持触摸事件吗,比如图表上的数据节点是[5,7,3,5,3],我触摸7能够把点击的X轴和y轴数据当参数传入跳转页面或者其他响应去看具体的内容,不知道有没有这方面的API

after start,warning:

Native component for' MPBarChart' doesnt exsit
Native component for' MPLineChart' doesnt exsit
...
...
...

HorizontalBarChart?

Curious, does this lib support Horizontal Bar Charts? Didn't see any in the docs or examples.

Feature Request Pie Charts

Hello first I'd like to start off by saying thanks for this repo, the best charting lib for android.

I see in the source PieCharts are partly built. Out of necessity I have started to make the API for a PieChart and forked this repo but as someone who has not used MPACharts, Java, or react-native much before this is a a slow process.

There is no PieChart component as far as I can tell for React Android. In my own project I have (hopefully temporarily) switched to creating a factory to render a native webview. From what I can reason this seems to be the most viable alternative approach.

I suppose this is a little bit of a feature request or at least to open up dialogue to discuss what outstanding parts of MPACharts need an API to react-native remain?

How can I set color of the x and y labels?

By defaults they show in black color, but my chart's background is already black and these labels are not visible now. Can you please tell me how can I customize this?

MainActivity.java file issue

Hi,
I am getting an error in android studio as

Cannot resolve cn, unused import statement.

for my import statement
import cn.mandata.react_native_mpchart.MPChartPackage;

I can't resolve this issue.

Doesn't works with react native 0.25

Tried to follow the installation of this plugin but the MainActivity is not the same as described.
Could you test it , and check if its possible to run under v0.25?

app/src/main/java/com/app/MainActivity.java

package com.app;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import cn.mandata.react_native_mpchart.MPChartPackage;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "App";
}

/**
 * Returns whether dev mode should be enabled.
 * This enables e.g. the dev menu.
 */
@Override
protected boolean getUseDeveloperSupport() {
    return BuildConfig.DEBUG;
}

/**
 * A list of packages used by the app. If the app uses additional views
 * or modules besides the default ones, add more packages here.
 */
@Override
protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new MPChartPackage()
    );
  }
}

Update: added the line in getPackages() testing now if it works on v0.25

Wrong import

Hi,

the class MPCombinedChartManager is still importing the old ReactPropGroup class. I've tried to make a pull request but seem you disabled it...?
See facebook/react-native@c1b7a36 for more

Set intervals for Y axis labels

I want the labels on Y axis of my line chart to show with definite intervals. For example like 0, 1, 2, 3 or 0, 2,4,6.. so on.

I tried using granularity property as mentioned in MP chart library like :

yAxis={{drawGridLines:true,textColor:"#FFFFFF",granularity:"1"}}

, but nothing happened. Can you please guide me on this.

Not working on React Native 0.31

Imported the chart like
import {
BarChart,
CombinedChart,
LineChart,
} from 'react-native-chart-android';
But nothing is showing.

Thanks

how can I set the PieChart legend

I use the PieChart and show the data,but when I set legent like BarChart it does not effect,
someone can show me a simply example,thanks!

How to customize the value above bar?

How can I style the value located above the bar? Only thing I found is:

drawValueAboveBar

which will enable/disable the value. Anything on styling? Specifically the font size

Text color in Pie Chart

Hello,

Thank you for the plug in.

I am using a Pie Chart and I can't figure out how to change the text color of the percentages written inside the Pie.

There are also many properties I did not manage to use : for example i cannot change the radius of the transparent circle.

Could someone please give me a link to the right list of properties ?

Here is my Pie Chart :

`
const data = {
xValues:['Client','Project','Management','Marketing','Growth','Network'],
yValues:[{
data : [35,22,11,18, 7, 7],
label : '',
config:{
colors: catColors,
color : 'white',
fontSize : 35
},
}],
}

return (
<PieChart data = {data}
style={progressStyle.pie}
holeRadius={51}
dragDecelerationEnabled={true}
dragDecelerationFrictionCoef={0.8}
usePercentValue={true}
legend={{enable : false}}
transparentCircleRadius={80}
description={''} />)
`

Thank you for your help

No chart data available

Hi,

Using you exemple provide in BarChart.js, I got two times "No chart data available".

Any idea ?

I'm using React Native 0.19.0.

Thanks !

How to set CUBIC_BEZIER for line chart

Hi, I am trying to config the dataset to be CUBIC_BEZIER for a line chart, tried some settings but does not work. Can you give me a simple instruction how to do it?
Thank you!

Compilation failed

Please help me with this error during compilation

mandata\react_native_mpchart\MPCombinedChartManager.java:10: error: cannot find symbol
import com.facebook.react.uimanager.ReactPropGroup;
                                   ^
  symbol:   class ReactPropGroup
  location: package com.facebook.react.uimanager
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
:react-native-chart-android:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.```

LimitLine Props

Please help me on how to implement limitLine in LineChart!..

Upgrade to 0.19.0

Hello,

It looks like your component is not compatible with RN 0.19.0. Would it be possible for you to upgrade it? Thanks so much

Small Mistake in the RadarChart example

Hello hongyin163,

I found a small mistake in the RadarChart example you forget to import RadarChart.

var { BarChart, CombinedChart }=require('../index.android');

to

var { RadarChart }=require('../index.android');

additional could you add an example of the pie chart and rewrite your setup that the code match to the newer react native version :) ?

Best greeting Jeremy Teichmann.

render linechart will crash when more times

The app will crash when states change more times. please help me, thanks.

getRandomData(){
var data={};
data['xValues']=[];
data['yValues']=[
{
data:[],
label:'test1',
config:{
color:'blue'
}
}
];
for (var i = 0; i < 50; i++) {
data.xValues.push(i+'');
data.yValues[0].data.push(Math.random()*100);
};
return data;
}
componentDidMount() {
var num=0;
setInterval(() => {
var datas=this.getRandomData();
this.setState({
randomDatas:datas
});
}, 1000);
}
render() {
return (


<LineChart
style={{flex:1}}
data={this.state.randomDatas}
visibleXRange={[0,30]}
maxVisibleValueCount={50}
xAxis={{drawGridLines:false,gridLineWidth:1,position:"BOTTOM"}}
yAxisRight={{enable:false}}
yAxis={{startAtZero:false,drawGridLines:false,position:"INSIDE_CHART"}}
drawGridBackground={false}
backgroundColor={"WHITE"}
description={""}
legend={{enable:true,position:'ABOVE_CHART_LEFT',direction:"LEFT_TO_RIGHT"}}
/>


);
}

import com.facebook.react.uimanager.ReactPropGroup error

版本号:

RN:0.37.0
react-native-chart-android: 1.0.8

错误信息

/node_modules/react-native-chart-android/android/src/main/java/cn/mandata/react_native_mpchart/MPCombinedChartManager.java:10: 错误: 找不到符号
import com.facebook.react.uimanager.ReactPropGroup;

由于 RN 这个 issue 造成了打包问题,facebook/react-native#14223

使用回复里的这个解决方案之后

allprojects {
     configurations.all {
       resolutionStrategy {
         eachDependency { DependencyResolveDetails details ->
           if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
             details.useVersion "0.37.0" // Your real React Native version here
           }
         }
       }
     }
  }

出现了以上错误,请帮忙看下

有什么文档之类的吗?

在查看demo的时候,很多props的含义没有相关的文档,请问一下能从哪里查询到这些prop的说明吗?

can it be dynamically updated?

Hi Hongyin,
how can I dynamically update the chart? E.g. add data, remove data, and so forth. By the way, the 慢牛 app's source code can be opened and released out? I am so interested in it. thanks

Is radar chart supported?

I've been trying to insert a radar chart in my project, but i found it seems that this repo did not support it. Is there any way I can diy it or do you have any schedules?

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.