1.0.0 • Published 6 years ago

react-native-xsy-mpchart v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

THIS LIBRARY IS NO LONGER MAINTAINED.

See https://github.com/hongyin163/react-native-chart-android and https://github.com/Jpadilla1/react-native-ios-charts

react-native-mpchart

A React Native chart library

This module is a bridge between React Native and MPAndroidChart. Eventually, iOS will be supported via the iOS port of MPAndroidChart, ios-charts.

All charts and properties come from MPAndroidChart.

Installation

Android

Install the node package

npm install --save https://github.com/mikemonteith/react-native-mpchart

Import the java library from node_modules/react-native-mpchart/android

android/settings.gradle

include ':react-native-mpchart', ':app'

project(':react-native-mpchart').projectDir = new File(settingsDir, '../node_modules/react-native-mpchart/android')

Add the project to your gradle dependencies

android/app/build.gradle

apply plugin: 'com.android.application'

android {
  ...
}

dependencies {
  compile fileTree(dir: "libs", include: ["*.jar"])
  compile "com.android.support:appcompat-v7:23.0.0"
  compile "com.facebook.react:react-native:0.19.+"
  compile project(":react-native-mpchart")
}

Add the package to your ReactInstanceManager

MainActivity.java

//import chart package (usually, your IDE will do this for you)
import com.mikemonteith.reactnativempchart.MPChartPackage;

// ...

/**
* 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() // <-- add this line
	);
}

// ...

Basic Usage

var React = require('react-native');
var Charts = require('react-native-mpchart');

var ExampleComponent = React.createClass({
  render: function(){
    return (
      <Charts.BarChart
        style={{flex: 1}}
        data={{
          dataSets: [{
            values: [1, 2, 3, 4, 5],
          }],
          xValues: ["one", "two", "three", "four", "five"],
        }}
      />
    );
  },
});

Charts

  • PieChart
  • BarChart
  • LineChart

Props

(inherits from React.View)

PropDescriptionTypeCharts
datasee data propertiesobjectAll
touchEnabledhandle touch gestures on the chartbooleanAll
xAxissee xaxis propertiesobjectBar, Line
leftAxissee yaxis propertiesobjectBar, Line
rightAxissee yaxis propertiesobjectBar, Line
gridBackgroundColorcolor of the grid backgroundstringBar, Line
holeRadiuspercentage radius of the pie holenumberPie
transparentCircleRadiuspercentage radius of the transparent overlaynumberPie
transparentCircleColorcolor of the transparent overlaystringPie
transparentCircleAlphaalpha of the transparent overlay between 0 and 1numberPie
rotationAngleclockwise angle in degrees where the first segment starts (0 = 3 o'clock)numberPie

data properties

PropertyDescriptionTypeCharts
dataSetssee dataSet propertiesarray of DataSet objectsAll
xValuesstrings specifying x axis labelsarray of stringsAll

dataSet properties

PropertyDescriptionTypeCharts
valuesvalues to plot on the grapharray of numbersAll
colorscolors to draw the chart dataarray of stringsAll
drawValuesdraw value textbooleanAll
drawCirclesdraw circles on data pointsbooleanLine
drawCubicdraw a smooth line-of-best-fitbooleanLine
lineWidthwidth of the line-of-best-fitnumberLine
drawFilldraw a colored area underneath the linebooleanLine
fillColorcolor of fill underneath the linestringLine
fillAlphaalpha of the fill underneath the line between 0 and 1numberLine

axis properties

PropertyDescriptionTypeCharts
enableddraw the axisbooleanBar, Line
drawAxisLinedraw the main axis linebooleanBar, Line
drawGridLinesdraw grid lines that are parallel to this axisbooleanBar, Line

x axis properties

(inherits from axis properties)

PropertyDescriptionTypeCharts
positionwhere to draw the axisstring 'bottom', 'top' or 'bothSided'Bar, Line

y axis properties

(inherits from axis properties)

PropertyDescriptionTypeCharts
minValueminimum valuenumberBar, Line
maxValuemaximum valuenumberBar, Line
invertedif true, draw the data upside-downbooleanBar, Line

TODO

  • Support all MPAndroidChart charts
  • Support all MPAndroidChart properties
  • Support iOS
  • Release as npm package