├── .gitignore ├── .jshintrc ├── .npmignore ├── LICENSE ├── README.md ├── android ├── .gitignore ├── .npmignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── reactNativeMPAndroidChart │ │ ├── MPAndroidChartPackage.java │ │ ├── charts │ │ ├── BarChartManager.java │ │ ├── BarLineChartBaseManager.java │ │ ├── BubbleChartManager.java │ │ ├── CandleStickChartManager.java │ │ ├── ChartBaseManager.java │ │ ├── CustomFormatter.java │ │ ├── LineChartManager.java │ │ ├── PieChartManager.java │ │ ├── RadarChartManager.java │ │ ├── ScatterChartManager.java │ │ └── YAxisChartBase.java │ │ ├── markers │ │ ├── OvalMarker.java │ │ ├── RNMarkerView.java │ │ └── RectangleMarker.java │ │ └── utils │ │ ├── BridgeUtils.java │ │ └── ChartDataSetConfigUtils.java │ └── res │ ├── drawable-nodpi │ ├── oval_marker.png │ └── rectangle_marker.png │ └── layout │ ├── oval_marker.xml │ └── rectangle_marker.xml ├── index.android.js ├── lib ├── BarChart.js ├── BarLineChartBase.js ├── BubbleChart.js ├── CandleStickChart.js ├── ChartBase.js ├── ChartDataSetConfig.js ├── LineChart.js ├── PieChart.js ├── RadarChart.js ├── ScatterChart.js └── YAxisIface.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node,osx,webstorm 3 | 4 | ### Node ### 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | 10 | # Runtime data 11 | pids 12 | *.pid 13 | *.seed 14 | 15 | # Directory for instrumented libs generated by jscoverage/JSCover 16 | lib-cov 17 | 18 | # Coverage directory used by tools like istanbul 19 | coverage 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # node-waf configuration 25 | .lock-wscript 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directories 31 | node_modules 32 | jspm_packages 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional REPL history 38 | .node_repl_history 39 | 40 | 41 | ### OSX ### 42 | .DS_Store 43 | .AppleDouble 44 | .LSOverride 45 | 46 | # Icon must end with two \r 47 | Icon 48 | 49 | 50 | # Thumbnails 51 | ._* 52 | 53 | # Files that might appear in the root of a volume 54 | .DocumentRevisions-V100 55 | .fseventsd 56 | .Spotlight-V100 57 | .TemporaryItems 58 | .Trashes 59 | .VolumeIcon.icns 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | 69 | ### WebStorm ### 70 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 71 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 72 | 73 | # User-specific stuff: 74 | .idea/workspace.xml 75 | .idea/tasks.xml 76 | .idea/dictionaries 77 | .idea/vcs.xml 78 | .idea/jsLibraryMappings.xml 79 | 80 | # Sensitive or high-churn files: 81 | .idea/dataSources.ids 82 | .idea/dataSources.xml 83 | .idea/dataSources.local.xml 84 | .idea/sqlDataSources.xml 85 | .idea/dynamic.xml 86 | .idea/uiDesigner.xml 87 | 88 | # Gradle: 89 | .idea/gradle.xml 90 | .idea/libraries 91 | 92 | # Mongo Explorer plugin: 93 | .idea/mongoSettings.xml 94 | 95 | ## File-based project format: 96 | *.iws 97 | 98 | ## Plugin-specific files: 99 | 100 | # IntelliJ 101 | /out/ 102 | 103 | # mpeltonen/sbt-idea plugin 104 | .idea_modules/ 105 | 106 | # JIRA plugin 107 | atlassian-ide-plugin.xml 108 | 109 | # Crashlytics plugin (for Android Studio and IntelliJ) 110 | com_crashlytics_export_strings.xml 111 | crashlytics.properties 112 | crashlytics-build.properties 113 | fabric.properties 114 | 115 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esnext": true 3 | } 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2016 Martin Skec 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ⚠️ Not maintained ⚠️ 2 | 3 | Please use https://github.com/wuxudong/react-native-charts-wrapper 4 | 5 | # React Native MPAndroidChart 6 | This library is React Native wrapper of popular Android charting library [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart). 7 | 8 | 9 | ## Table of contents 10 | - [Setup](#setup) 11 | - [Usage](#usage) 12 | - [Example](#example-application) 13 | 14 | ## Setup 15 | Library can be easily installed using NPM: 16 | 17 | `npm i react-native-mp-android-chart --save` 18 | 19 | Additional setup is required because library is using native Android code. 20 | 21 | **android/build.gradle** 22 | ``` 23 | allprojects { 24 | repositories { 25 | ... 26 | 27 | maven { url "https://jitpack.io" } // used for MPAndroidChart 28 | } 29 | } 30 | ``` 31 | 32 | **android/settings.gradle** 33 | ``` 34 | include ':reactNativeMPAndroidChart' 35 | project(':reactNativeMPAndroidChart').projectDir = new File( 36 | rootProject.projectDir, 37 | '../node_modules/react-native-mp-android-chart/android' 38 | ) 39 | ``` 40 | 41 | **android/app/build.gradle** 42 | ``` 43 | dependencies { 44 | ... 45 | compile project(':reactNativeMPAndroidChart') 46 | } 47 | ``` 48 | **MainApplication.java** 49 | 50 | On top where imports are: 51 | ```java 52 | import com.github.reactNativeMPAndroidChart.MPAndroidChartPackage; 53 | ``` 54 | 55 | Add package in `getPackages` method: 56 | ```java 57 | protected List getPackages() { 58 | return Arrays.asList( 59 | new MainReactPackage(), 60 | new MPAndroidChartPackage() // <----- Add this 61 | ); 62 | } 63 | ``` 64 | 65 | 66 | ## Usage 67 | There are 8 supported charts with many configuration options. 68 | Almost all configuration available in base MPAndroidChart library are available through this wrapper. 69 | More details on available configuration can be found on their [wiki](https://github.com/PhilJay/MPAndroidChart/wiki). 70 | 71 | Example of how charts are used and how to apply configuration can be found in example [Android application](#example-application). 72 | 73 | Supported charts with examples: 74 | - [Bar](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/BarChartScreen.js) 75 | - [Bubble](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/BubbleChartScreen.js) 76 | - [Candle stick](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/CandleStickChartScreen.js) 77 | - [Line](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/LineChartScreen.js) 78 | - [Pie](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/PieChartScreen.js) 79 | - [Radar](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/RadarChartScreen.js) 80 | - [Scatter](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/ScatterChartScreen.js) 81 | - [Stacked bar](https://github.com/mskec/react-native-mp-android-chart-example/blob/master/app/StackedBarChartScreen.js) 82 | 83 | ### Example code 84 | This is simple example of how `BarChart` is used. 85 | ```JavaScript 86 | import {BarChart} from 'react-native-mp-android-chart'; 87 | 88 | class BarChartScreen extends React.Component { 89 | 90 | constructor() { 91 | super(); 92 | 93 | this.state = { 94 | data: { 95 | datasets: [{ 96 | yValues: [100, 105, 102, 110], 97 | label: 'Data set 1', 98 | config: { 99 | color: 'teal' 100 | } 101 | }, { 102 | yValues: [110, 100, 105, 108], 103 | label: 'Data set 2', 104 | config: { 105 | color: 'orange' 106 | } 107 | }], 108 | xValues: ['Q1', 'Q2', 'Q3', 'Q4'] 109 | } 110 | }; 111 | } 112 | 113 | render() { 114 | return ( 115 | 116 | 121 | 122 | ); 123 | } 124 | } 125 | 126 | const styles = StyleSheet.create({ 127 | chart: { 128 | height: 300, 129 | width: 300 130 | } 131 | }); 132 | ``` 133 | 134 | ## Example application 135 | Example Android application with source code and `apk` is available [here](https://github.com/mskec/react-native-mp-android-chart-example). 136 | 137 | ## License 138 | The MIT License 139 | 140 | Copyright (c) 2016 Martin Skec 141 | 142 | 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: 143 | 144 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 145 | 146 | 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. 147 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/intellij,android,gradle,osx 3 | 4 | ### Intellij ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | .idea 9 | 10 | # User-specific stuff: 11 | .idea/workspace.xml 12 | .idea/tasks.xml 13 | .idea/dictionaries 14 | .idea/vcs.xml 15 | .idea/jsLibraryMappings.xml 16 | 17 | # Sensitive or high-churn files: 18 | .idea/dataSources.ids 19 | .idea/dataSources.xml 20 | .idea/dataSources.local.xml 21 | .idea/sqlDataSources.xml 22 | .idea/dynamic.xml 23 | .idea/uiDesigner.xml 24 | 25 | # Gradle: 26 | .idea/gradle.xml 27 | .idea/libraries 28 | 29 | # Mongo Explorer plugin: 30 | .idea/mongoSettings.xml 31 | 32 | ## File-based project format: 33 | *.iws 34 | 35 | ## Plugin-specific files: 36 | 37 | # IntelliJ 38 | /out/ 39 | 40 | # mpeltonen/sbt-idea plugin 41 | .idea_modules/ 42 | 43 | # JIRA plugin 44 | atlassian-ide-plugin.xml 45 | 46 | # Crashlytics plugin (for Android Studio and IntelliJ) 47 | com_crashlytics_export_strings.xml 48 | crashlytics.properties 49 | crashlytics-build.properties 50 | fabric.properties 51 | 52 | ### Intellij Patch ### 53 | *.iml 54 | 55 | 56 | ### Android ### 57 | # Built application files 58 | *.apk 59 | *.ap_ 60 | 61 | # Files for the Dalvik VM 62 | *.dex 63 | 64 | # Java class files 65 | *.class 66 | 67 | # Generated files 68 | bin/ 69 | gen/ 70 | out/ 71 | 72 | # Gradle files 73 | .gradle/ 74 | build/ 75 | 76 | # Local configuration file (sdk path, etc) 77 | local.properties 78 | 79 | # Proguard folder generated by Eclipse 80 | proguard/ 81 | 82 | # Log Files 83 | *.log 84 | 85 | # Android Studio Navigation editor temp files 86 | .navigation/ 87 | 88 | # Android Studio captures folder 89 | captures/ 90 | 91 | # Intellij 92 | *.iml 93 | 94 | # Keystore files 95 | *.jks 96 | 97 | ### Android Patch ### 98 | gen-external-apklibs 99 | 100 | 101 | ### Gradle ### 102 | .gradle 103 | build/ 104 | 105 | # Ignore Gradle GUI config 106 | gradle-app.setting 107 | 108 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 109 | !gradle-wrapper.jar 110 | 111 | # Cache of project 112 | .gradletasknamecache 113 | 114 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 115 | # gradle/wrapper/gradle-wrapper.properties 116 | 117 | 118 | ### OSX ### 119 | .DS_Store 120 | .AppleDouble 121 | .LSOverride 122 | 123 | # Icon must end with two \r 124 | Icon 125 | 126 | 127 | # Thumbnails 128 | ._* 129 | 130 | # Files that might appear in the root of a volume 131 | .DocumentRevisions-V100 132 | .fseventsd 133 | .Spotlight-V100 134 | .TemporaryItems 135 | .Trashes 136 | .VolumeIcon.icns 137 | 138 | # Directories potentially created on remote AFP share 139 | .AppleDB 140 | .AppleDesktop 141 | Network Trash Folder 142 | Temporary Items 143 | .apdisk 144 | -------------------------------------------------------------------------------- /android/.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | build/ 3 | .gradle/ 4 | gradle/ 5 | gradlew 6 | gradlew.bat 7 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:1.3.1' 10 | } 11 | } 12 | 13 | android { 14 | compileSdkVersion 23 15 | buildToolsVersion "23.0.1" 16 | 17 | defaultConfig { 18 | minSdkVersion 16 19 | targetSdkVersion 23 20 | versionCode 1 21 | versionName "1.0" 22 | } 23 | lintOptions { 24 | abortOnError false 25 | } 26 | } 27 | 28 | allprojects { 29 | repositories { 30 | mavenLocal() 31 | jcenter() 32 | maven { url "https://jitpack.io" } 33 | } 34 | } 35 | 36 | dependencies { 37 | compile 'com.facebook.react:react-native:0.20.+' 38 | 39 | compile 'com.github.PhilJay:MPAndroidChart:v2.2.4' 40 | } 41 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mskec/react-native-mp-android-chart/854e34d2befa9a7b81d953c5a7117711a9477f06/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'reactNativeMPAndroidChart' 2 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/MPAndroidChartPackage.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | import com.github.reactNativeMPAndroidChart.charts.BarChartManager; 9 | import com.github.reactNativeMPAndroidChart.charts.BubbleChartManager; 10 | import com.github.reactNativeMPAndroidChart.charts.CandleStickChartManager; 11 | import com.github.reactNativeMPAndroidChart.charts.LineChartManager; 12 | import com.github.reactNativeMPAndroidChart.charts.PieChartManager; 13 | import com.github.reactNativeMPAndroidChart.charts.RadarChartManager; 14 | import com.github.reactNativeMPAndroidChart.charts.ScatterChartManager; 15 | 16 | import java.util.Arrays; 17 | import java.util.Collections; 18 | import java.util.List; 19 | 20 | public class MPAndroidChartPackage implements ReactPackage { 21 | 22 | @Override 23 | public List createNativeModules(ReactApplicationContext reactContext) { 24 | return Arrays.asList(); 25 | } 26 | 27 | @Override 28 | public List> createJSModules() { 29 | return Collections.emptyList(); 30 | } 31 | 32 | @Override 33 | public List createViewManagers(ReactApplicationContext reactContext) { 34 | return Arrays.asList( 35 | new BarChartManager(), 36 | new BubbleChartManager(), 37 | new CandleStickChartManager(), 38 | new LineChartManager(), 39 | new PieChartManager(), 40 | new RadarChartManager(), 41 | new ScatterChartManager() 42 | ); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/BarChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | import android.graphics.Color; 4 | import android.view.View; 5 | import com.facebook.react.bridge.ReadableArray; 6 | import com.facebook.react.bridge.ReadableMap; 7 | import com.facebook.react.bridge.ReadableType; 8 | import com.facebook.react.uimanager.ThemedReactContext; 9 | import com.facebook.react.uimanager.annotations.ReactProp; 10 | import com.github.mikephil.charting.charts.BarChart; 11 | import com.github.mikephil.charting.data.BarData; 12 | import com.github.mikephil.charting.data.BarDataSet; 13 | import com.github.mikephil.charting.data.BarEntry; 14 | import com.github.mikephil.charting.data.ChartData; 15 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 16 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 17 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 18 | 19 | import java.util.ArrayList; 20 | 21 | public class BarChartManager extends BarLineChartBaseManager { 22 | 23 | @Override 24 | public String getName() { 25 | return "MPAndroidBarChart"; 26 | } 27 | 28 | @Override 29 | protected View createViewInstance(ThemedReactContext reactContext) { 30 | BarChart barChart = new BarChart(reactContext); 31 | 32 | return barChart; 33 | } 34 | 35 | @Override 36 | ChartData createData(String[] xValues) { 37 | return new BarData(xValues); 38 | } 39 | 40 | @Override 41 | IDataSet createDataSet(ArrayList entries, String label) { 42 | return new BarDataSet(entries, label); 43 | } 44 | 45 | @Override 46 | BarEntry createEntry(ReadableArray yValues, int index) { 47 | BarEntry entry; 48 | 49 | if (ReadableType.Array.equals(yValues.getType(index))) { 50 | entry = new BarEntry(BridgeUtils.convertToFloatArray(yValues.getArray(index)), index); 51 | } else if (ReadableType.Number.equals(yValues.getType(index))) { 52 | entry = new BarEntry((float) yValues.getDouble(index), index); 53 | } else { 54 | throw new IllegalArgumentException("Unexpected entry type: " + yValues.getType(index)); 55 | } 56 | 57 | return entry; 58 | } 59 | 60 | @Override 61 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 62 | BarDataSet barDataSet = (BarDataSet) dataSet; 63 | 64 | ChartDataSetConfigUtils.commonConfig(barDataSet, config); 65 | ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(barDataSet, config); 66 | 67 | if (BridgeUtils.validate(config, ReadableType.Number, "barSpacePercent")) { 68 | barDataSet.setBarSpacePercent((float) config.getDouble("barSpacePercent")); 69 | } 70 | if (BridgeUtils.validate(config, ReadableType.String, "barShadowColor")) { 71 | barDataSet.setBarShadowColor(Color.parseColor(config.getString("barShadowColor"))); 72 | } 73 | if (BridgeUtils.validate(config, ReadableType.Number, "highlightAlpha")) { 74 | barDataSet.setHighLightAlpha(config.getInt("highlightAlpha")); 75 | } 76 | if (BridgeUtils.validate(config, ReadableType.Array, "stackLabels")) { 77 | barDataSet.setStackLabels(BridgeUtils.convertToStringArray(config.getArray("stackLabels"))); 78 | } 79 | } 80 | 81 | @ReactProp(name = "drawValueAboveBar") 82 | public void setDrawValueAboveBar(BarChart chart, boolean enabled) { 83 | chart.setDrawValueAboveBar(enabled); 84 | } 85 | 86 | @ReactProp(name = "drawBarShadow") 87 | public void setDrawBarShadow(BarChart chart, boolean enabled) { 88 | chart.setDrawBarShadow(enabled); 89 | } 90 | 91 | @ReactProp(name = "drawHighlightArrow") 92 | public void setDrawHighlightArrow(BarChart chart, boolean enabled) { 93 | chart.setDrawHighlightArrow(enabled); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/BarLineChartBaseManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | import android.graphics.Color; 4 | import com.facebook.react.bridge.ReadableMap; 5 | import com.facebook.react.bridge.ReadableType; 6 | import com.facebook.react.uimanager.annotations.ReactProp; 7 | import com.github.mikephil.charting.charts.BarLineChartBase; 8 | import com.github.mikephil.charting.charts.Chart; 9 | import com.github.mikephil.charting.components.YAxis; 10 | import com.github.mikephil.charting.data.Entry; 11 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 12 | 13 | public abstract class BarLineChartBaseManager extends YAxisChartBase { 14 | 15 | @Override 16 | public void setYAxis(Chart chart, ReadableMap propMap) { 17 | BarLineChartBase barLineChart = (BarLineChartBase) chart; 18 | 19 | if (BridgeUtils.validate(propMap, ReadableType.Map, "left")) { 20 | YAxis leftYAxis = barLineChart.getAxisLeft(); 21 | setCommonAxisConfig(chart, leftYAxis, propMap.getMap("left")); 22 | setYAxisConfig(leftYAxis, propMap.getMap("left")); 23 | } 24 | if (BridgeUtils.validate(propMap, ReadableType.Map, "right")) { 25 | YAxis rightYAxis = barLineChart.getAxisRight(); 26 | setCommonAxisConfig(chart, rightYAxis, propMap.getMap("right")); 27 | setYAxisConfig(rightYAxis, propMap.getMap("right")); 28 | } 29 | } 30 | 31 | @ReactProp(name = "drawGridBackground") 32 | public void setDrawGridBackground(BarLineChartBase chart, boolean enabled) { 33 | chart.setDrawGridBackground(enabled); 34 | } 35 | 36 | @ReactProp(name = "gridBackgroundColor") 37 | public void setGridBackgroundColor(BarLineChartBase chart, String color) { 38 | chart.setGridBackgroundColor(Color.parseColor(color)); 39 | } 40 | 41 | @ReactProp(name = "drawBorders") 42 | public void setDrawBorders(BarLineChartBase chart, boolean enabled) { 43 | chart.setDrawBorders(enabled); 44 | } 45 | 46 | @ReactProp(name = "borderColor") 47 | public void setBorderColor(BarLineChartBase chart, String color) { 48 | chart.setBorderColor(Color.parseColor(color)); 49 | } 50 | 51 | @ReactProp(name = "borderWidth") 52 | public void setBorderWidth(BarLineChartBase chart, float width) { 53 | chart.setBorderWidth(width); 54 | } 55 | 56 | @ReactProp(name = "maxVisibleValueCount") 57 | public void setMaxVisibleValueCount(BarLineChartBase chart, int count) { 58 | chart.setMaxVisibleValueCount(count); 59 | } 60 | 61 | @ReactProp(name = "autoScaleMinMaxEnabled") 62 | public void setAutoScaleMinMaxEnabled(BarLineChartBase chart, boolean enabled) { 63 | chart.setAutoScaleMinMaxEnabled(enabled); 64 | } 65 | 66 | @ReactProp(name = "keepPositionOnRotation") 67 | public void setKeepPositionOnRotation(BarLineChartBase chart, boolean enabled) { 68 | chart.setKeepPositionOnRotation(enabled); 69 | } 70 | 71 | @ReactProp(name = "scaleEnabled") 72 | public void setScaleEnabled(BarLineChartBase chart, boolean enabled) { 73 | chart.setScaleEnabled(enabled); 74 | } 75 | 76 | @ReactProp(name = "dragEnabled") 77 | public void setDragEnabled(BarLineChartBase chart, boolean enabled) { 78 | chart.setDragEnabled(enabled); 79 | } 80 | 81 | @ReactProp(name = "scaleXEnabled") 82 | public void setScaleXEnabled(BarLineChartBase chart, boolean enabled) { 83 | chart.setScaleXEnabled(enabled); 84 | } 85 | 86 | @ReactProp(name = "scaleYEnabled") 87 | public void setScaleYEnabled(BarLineChartBase chart, boolean enabled) { 88 | chart.setScaleYEnabled(enabled); 89 | } 90 | 91 | @ReactProp(name = "pinchZoom") 92 | public void setPinchZoom(BarLineChartBase chart, boolean enabled) { 93 | chart.setPinchZoom(enabled); 94 | } 95 | 96 | @ReactProp(name = "doubleTapToZoomEnabled") 97 | public void setDoubleTapToZoomEnabled(BarLineChartBase chart, boolean enabled) { 98 | chart.setDoubleTapToZoomEnabled(enabled); 99 | } 100 | 101 | @ReactProp(name = "zoom") 102 | public void setZoom(BarLineChartBase chart, ReadableMap propMap) { 103 | if (BridgeUtils.validate(propMap, ReadableType.Number, "scaleX") && 104 | BridgeUtils.validate(propMap, ReadableType.Number, "scaleY") && 105 | BridgeUtils.validate(propMap, ReadableType.Number, "xValue") && 106 | BridgeUtils.validate(propMap, ReadableType.Number, "yValue")) { 107 | 108 | YAxis.AxisDependency axisDependency = YAxis.AxisDependency.LEFT; 109 | if (propMap.hasKey("axisDependency") && 110 | propMap.getString("axisDependency").equalsIgnoreCase("RIGHT")) { 111 | axisDependency = YAxis.AxisDependency.RIGHT; 112 | } 113 | 114 | chart.zoom( 115 | (float) propMap.getDouble("scaleX"), 116 | (float) propMap.getDouble("scaleY"), 117 | (float) propMap.getDouble("xValue"), 118 | (float) propMap.getDouble("yValue"), 119 | axisDependency 120 | ); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/BubbleChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | 4 | import com.facebook.react.bridge.ReadableArray; 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.facebook.react.bridge.ReadableType; 7 | import com.facebook.react.uimanager.ThemedReactContext; 8 | import com.github.mikephil.charting.charts.BubbleChart; 9 | import com.github.mikephil.charting.data.BubbleData; 10 | import com.github.mikephil.charting.data.BubbleDataSet; 11 | import com.github.mikephil.charting.data.BubbleEntry; 12 | import com.github.mikephil.charting.data.ChartData; 13 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 14 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 15 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 16 | 17 | import java.util.ArrayList; 18 | 19 | public class BubbleChartManager extends ChartBaseManager { 20 | 21 | @Override 22 | public String getName() { 23 | return "MPAndroidBubbleChart"; 24 | } 25 | 26 | @Override 27 | protected BubbleChart createViewInstance(ThemedReactContext reactContext) { 28 | return new BubbleChart(reactContext); 29 | } 30 | 31 | @Override 32 | ChartData createData(String[] xValues) { 33 | return new BubbleData(xValues); 34 | } 35 | 36 | @Override 37 | IDataSet createDataSet(ArrayList entries, String label) { 38 | return new BubbleDataSet(entries, label); 39 | } 40 | 41 | @Override 42 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 43 | BubbleDataSet bubbleDataSet = (BubbleDataSet) dataSet; 44 | 45 | ChartDataSetConfigUtils.commonConfig(bubbleDataSet, config); 46 | ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(bubbleDataSet, config); 47 | 48 | // BubbleDataSet only config 49 | if (BridgeUtils.validate(config, ReadableType.Number, "highlightCircleWidth")) { 50 | bubbleDataSet.setHighlightCircleWidth((float) config.getDouble("highlightCircleWidth")); 51 | } 52 | } 53 | 54 | @Override 55 | BubbleEntry createEntry(ReadableArray yValues, int index) { 56 | if (!ReadableType.Map.equals(yValues.getType(index))) { 57 | throw new IllegalArgumentException("Invalid BubbleEntry data"); 58 | } 59 | 60 | ReadableMap entry = yValues.getMap(index); 61 | if(!BridgeUtils.validate(entry, ReadableType.Number, "value") || 62 | !BridgeUtils.validate(entry, ReadableType.Number, "size")) { 63 | throw new IllegalArgumentException("Invalid BubbleEntry data"); 64 | } 65 | 66 | float value = (float) entry.getDouble("value"); 67 | float size = (float) entry.getDouble("size"); 68 | 69 | return new BubbleEntry(index, value, size); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/CandleStickChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.Paint; 5 | import com.facebook.react.bridge.ReadableArray; 6 | import com.facebook.react.bridge.ReadableMap; 7 | import com.facebook.react.bridge.ReadableType; 8 | import com.facebook.react.uimanager.ThemedReactContext; 9 | import com.github.mikephil.charting.charts.CandleStickChart; 10 | import com.github.mikephil.charting.data.CandleData; 11 | import com.github.mikephil.charting.data.CandleDataSet; 12 | import com.github.mikephil.charting.data.CandleEntry; 13 | import com.github.mikephil.charting.data.ChartData; 14 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 15 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 16 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class CandleStickChartManager extends BarLineChartBaseManager { 21 | 22 | @Override 23 | public String getName() { 24 | return "MPAndroidCandleStickChart"; 25 | } 26 | 27 | @Override 28 | protected CandleStickChart createViewInstance(ThemedReactContext reactContext) { 29 | return new CandleStickChart(reactContext); 30 | } 31 | 32 | @Override 33 | ChartData createData(String[] xValues) { 34 | return new CandleData(xValues); 35 | } 36 | 37 | @Override 38 | IDataSet createDataSet(ArrayList entries, String label) { 39 | return new CandleDataSet(entries, label); 40 | } 41 | 42 | @Override 43 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 44 | CandleDataSet candleDataSet = (CandleDataSet) dataSet; 45 | 46 | ChartDataSetConfigUtils.commonConfig(candleDataSet, config); 47 | ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(candleDataSet, config); 48 | ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(candleDataSet, config); 49 | 50 | // CandleDataSet only config 51 | if (BridgeUtils.validate(config, ReadableType.Number, "barSpace")) { 52 | candleDataSet.setBarSpace((float) config.getDouble("barSpace")); 53 | } 54 | if (BridgeUtils.validate(config, ReadableType.Number, "shadowWidth")) { 55 | candleDataSet.setShadowWidth((float) config.getDouble("shadowWidth")); 56 | } 57 | if (BridgeUtils.validate(config, ReadableType.String, "shadowColor")) { 58 | candleDataSet.setShadowColor(Color.parseColor(config.getString("shadowColor"))); 59 | } 60 | if (BridgeUtils.validate(config, ReadableType.Boolean, "shadowColorSameAsCandle")) { 61 | candleDataSet.setShadowColorSameAsCandle(config.getBoolean("shadowColorSameAsCandle")); 62 | } 63 | if (BridgeUtils.validate(config, ReadableType.String, "neutralColor")) { 64 | candleDataSet.setNeutralColor(Color.parseColor(config.getString("neutralColor"))); 65 | } 66 | if (BridgeUtils.validate(config, ReadableType.String, "decreasingColor")) { 67 | candleDataSet.setDecreasingColor(Color.parseColor(config.getString("decreasingColor"))); 68 | } 69 | if (BridgeUtils.validate(config, ReadableType.String, "decreasingPaintStyle")) { 70 | candleDataSet.setDecreasingPaintStyle(Paint.Style.valueOf(config.getString("decreasingPaintStyle").toUpperCase())); 71 | } 72 | if (BridgeUtils.validate(config, ReadableType.String, "increasingColor")) { 73 | candleDataSet.setIncreasingColor(Color.parseColor(config.getString("increasingColor"))); 74 | } 75 | if (BridgeUtils.validate(config, ReadableType.String, "increasingPaintStyle")) { 76 | candleDataSet.setIncreasingPaintStyle(Paint.Style.valueOf(config.getString("increasingPaintStyle").toUpperCase())); 77 | } 78 | } 79 | 80 | @Override 81 | CandleEntry createEntry(ReadableArray yValues, int index) { 82 | if (!ReadableType.Map.equals(yValues.getType(index))) { 83 | throw new IllegalArgumentException(); 84 | } 85 | 86 | ReadableMap entryData = yValues.getMap(index); 87 | if (!BridgeUtils.validate(entryData, ReadableType.Number, "shadowH") || 88 | !BridgeUtils.validate(entryData, ReadableType.Number, "shadowL") || 89 | !BridgeUtils.validate(entryData, ReadableType.Number, "open") || 90 | !BridgeUtils.validate(entryData, ReadableType.Number, "close")) { 91 | throw new IllegalArgumentException("CandleStick data must contain: shadowH, shadowL, open and close values"); 92 | } 93 | 94 | float shadowH = (float) entryData.getDouble("shadowH"); 95 | float shadowL = (float) entryData.getDouble("shadowL"); 96 | float open = (float) entryData.getDouble("open"); 97 | float close = (float) entryData.getDouble("close"); 98 | 99 | return new CandleEntry(index, shadowH, shadowL, open, close); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/ChartBaseManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.content.res.ColorStateList; 6 | import android.os.Build; 7 | import com.facebook.react.bridge.ReadableArray; 8 | import com.facebook.react.bridge.ReadableMap; 9 | import com.facebook.react.bridge.ReadableType; 10 | import com.facebook.react.uimanager.SimpleViewManager; 11 | import com.facebook.react.uimanager.annotations.ReactProp; 12 | import com.github.mikephil.charting.animation.Easing.EasingOption; 13 | import com.github.mikephil.charting.charts.Chart; 14 | import com.github.mikephil.charting.components.AxisBase; 15 | import com.github.mikephil.charting.components.Legend; 16 | import com.github.mikephil.charting.components.Legend.LegendForm; 17 | import com.github.mikephil.charting.components.Legend.LegendPosition; 18 | import com.github.mikephil.charting.components.LimitLine; 19 | import com.github.mikephil.charting.components.XAxis; 20 | import com.github.mikephil.charting.components.XAxis.XAxisPosition; 21 | import com.github.mikephil.charting.data.ChartData; 22 | import com.github.mikephil.charting.data.Entry; 23 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 24 | import com.github.reactNativeMPAndroidChart.markers.OvalMarker; 25 | import com.github.reactNativeMPAndroidChart.markers.RNMarkerView; 26 | import com.github.reactNativeMPAndroidChart.markers.RectangleMarker; 27 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 28 | 29 | import java.lang.reflect.InvocationTargetException; 30 | import java.util.ArrayList; 31 | 32 | public abstract class ChartBaseManager extends SimpleViewManager { 33 | 34 | 35 | /** 36 | * More details about legend customization: https://github.com/PhilJay/MPAndroidChart/wiki/Legend 37 | */ 38 | @ReactProp(name = "legend") 39 | public void setLegend(T chart, ReadableMap propMap) { 40 | Legend legend = chart.getLegend(); 41 | 42 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) { 43 | legend.setEnabled(propMap.getBoolean("enabled")); 44 | } 45 | 46 | // Styling 47 | if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) { 48 | legend.setTextColor(Color.parseColor(propMap.getString("textColor"))); 49 | } 50 | if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) { 51 | legend.setTextSize((float) propMap.getDouble("textSize")); 52 | } 53 | if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") || 54 | BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) { 55 | legend.setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily")); 56 | } 57 | 58 | // Wrapping / clipping avoidance 59 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "wordWrapEnabled")) { 60 | legend.setWordWrapEnabled(propMap.getBoolean("wordWrapEnabled")); 61 | } 62 | if (BridgeUtils.validate(propMap, ReadableType.Number, "maxSizePercent")) { 63 | legend.setMaxSizePercent((float) propMap.getDouble("maxSizePercent")); 64 | } 65 | 66 | // Customizing 67 | if (BridgeUtils.validate(propMap, ReadableType.String, "position")) { 68 | legend.setPosition(LegendPosition.valueOf(propMap.getString("position").toUpperCase())); 69 | } 70 | if (BridgeUtils.validate(propMap, ReadableType.String, "form")) { 71 | legend.setForm(LegendForm.valueOf(propMap.getString("form").toUpperCase())); 72 | } 73 | if (BridgeUtils.validate(propMap, ReadableType.Number, "formSize")) { 74 | legend.setFormSize((float) propMap.getDouble("formSize")); 75 | } 76 | if (BridgeUtils.validate(propMap, ReadableType.Number, "xEntrySpace")) { 77 | legend.setXEntrySpace((float) propMap.getDouble("xEntrySpace")); 78 | } 79 | if (BridgeUtils.validate(propMap, ReadableType.Number, "yEntrySpace")) { 80 | legend.setYEntrySpace((float) propMap.getDouble("yEntrySpace")); 81 | } 82 | if (BridgeUtils.validate(propMap, ReadableType.Number, "formToTextSpace")) { 83 | legend.setFormToTextSpace((float) propMap.getDouble("formToTextSpace")); 84 | } 85 | 86 | // Custom labels & colors 87 | if (BridgeUtils.validate(propMap, ReadableType.Map, "custom")) { 88 | ReadableMap customMap = propMap.getMap("custom"); 89 | if (BridgeUtils.validate(customMap, ReadableType.Array, "colors") && 90 | BridgeUtils.validate(customMap, ReadableType.Array, "labels")) { 91 | 92 | ReadableArray colorsArray = customMap.getArray("colors"); 93 | ReadableArray labelsArray = customMap.getArray("labels"); 94 | 95 | if (colorsArray.size() == labelsArray.size()) { 96 | // TODO null label should start a group 97 | // TODO -2 color should avoid drawing a form 98 | String[] labels = BridgeUtils.convertToStringArray(labelsArray); 99 | String[] colors = BridgeUtils.convertToStringArray(colorsArray); 100 | 101 | int[] colorsParsed = new int[colors.length]; 102 | for (int i = 0; i < colors.length; i++) { 103 | colorsParsed[i] = Color.parseColor(colors[i]); 104 | } 105 | 106 | legend.setCustom(colorsParsed, labels); 107 | } 108 | } 109 | } 110 | 111 | // TODO resetCustom function 112 | // TODO extra 113 | 114 | chart.invalidate(); // TODO is this necessary? Looks like enabled is not refreshing without it 115 | } 116 | 117 | @ReactProp(name = "logEnabled") 118 | public void setLogEnabled(Chart chart, boolean enabled) { 119 | chart.setLogEnabled(enabled); 120 | } 121 | 122 | @ReactProp(name = "backgroundColor") 123 | public void setBackgroundColor(Chart chart, String color) { 124 | chart.setBackgroundColor(Color.parseColor(color)); 125 | } 126 | 127 | @ReactProp(name = "description") 128 | public void setDescription(Chart chart, ReadableMap propMap) { 129 | if (BridgeUtils.validate(propMap, ReadableType.String, "text")) { 130 | chart.setDescription(propMap.getString("text")); 131 | } 132 | if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) { 133 | chart.setDescriptionColor(Color.parseColor(propMap.getString("textColor"))); 134 | } 135 | if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) { 136 | chart.setDescriptionTextSize((float) propMap.getDouble("textSize")); 137 | } 138 | if (BridgeUtils.validate(propMap, ReadableType.Number, "positionX") && 139 | BridgeUtils.validate(propMap, ReadableType.Number, "positionY")) { 140 | 141 | chart.setDescriptionPosition((float) propMap.getDouble("positionX"), (float) propMap.getDouble("positionY")); 142 | } 143 | if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") || 144 | BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) { 145 | chart.setDescriptionTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily")); 146 | } 147 | } 148 | 149 | @ReactProp(name = "noDataText") 150 | public void setNoDataText(Chart chart, String noDataText) { 151 | chart.setNoDataText(noDataText); 152 | } 153 | 154 | @ReactProp(name = "noDataTextDescription") 155 | public void setNoDataTextDescription(Chart chart, String noDataTextDescription) { 156 | chart.setNoDataTextDescription(noDataTextDescription); 157 | } 158 | 159 | @ReactProp(name = "touchEnabled") 160 | public void setTouchEnabled(Chart chart, boolean enabled) { 161 | chart.setTouchEnabled(enabled); 162 | } 163 | 164 | @ReactProp(name = "dragDecelerationEnabled") 165 | public void setDragDecelerationEnabled(Chart chart, boolean enabled) { 166 | chart.setDragDecelerationEnabled(enabled); 167 | } 168 | 169 | @ReactProp(name = "dragDecelerationFrictionCoef") 170 | public void setDragDecelerationFrictionCoef(Chart chart, float coef) { 171 | chart.setDragDecelerationFrictionCoef(coef); 172 | } 173 | 174 | /** 175 | * Animations docs: https://github.com/PhilJay/MPAndroidChart/wiki/Animations 176 | */ 177 | @ReactProp(name = "animation") 178 | public void setAnimation(Chart chart, ReadableMap propMap) { 179 | Integer durationX = null; 180 | Integer durationY = null; 181 | EasingOption easingX = EasingOption.Linear; 182 | EasingOption easingY = EasingOption.Linear; 183 | 184 | if (BridgeUtils.validate(propMap, ReadableType.Number, "durationX")) { 185 | durationX = propMap.getInt("durationX"); 186 | } 187 | if (BridgeUtils.validate(propMap, ReadableType.Number, "durationY")) { 188 | durationY = propMap.getInt("durationY"); 189 | } 190 | if (BridgeUtils.validate(propMap, ReadableType.String, "easingX")) { 191 | easingX = EasingOption.valueOf(propMap.getString("easingX")); 192 | } 193 | if (BridgeUtils.validate(propMap, ReadableType.String, "easingY")) { 194 | easingY = EasingOption.valueOf(propMap.getString("easingY")); 195 | } 196 | 197 | if (durationX != null && durationY != null) { 198 | chart.animateXY(durationX, durationY, easingX, easingY); 199 | } else if (durationX != null) { 200 | chart.animateX(durationX, easingX); 201 | } else if (durationY != null) { 202 | chart.animateY(durationY, easingY); 203 | } 204 | } 205 | 206 | /** 207 | * xAxis config details: https://github.com/PhilJay/MPAndroidChart/wiki/XAxis 208 | */ 209 | @ReactProp(name = "xAxis") 210 | public void setXAxis(Chart chart, ReadableMap propMap) { 211 | XAxis axis = chart.getXAxis(); 212 | 213 | setCommonAxisConfig(chart, axis, propMap); 214 | 215 | if (BridgeUtils.validate(propMap, ReadableType.Number, "labelsToSkip")) { 216 | axis.setLabelsToSkip(propMap.getInt("labelsToSkip")); 217 | } 218 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "avoidFirstLastClipping")) { 219 | axis.setAvoidFirstLastClipping(propMap.getBoolean("avoidFirstLastClipping")); 220 | } 221 | if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBetweenLabels")) { 222 | axis.setSpaceBetweenLabels(propMap.getInt("spaceBetweenLabels")); 223 | } 224 | if (BridgeUtils.validate(propMap, ReadableType.String, "position")) { 225 | axis.setPosition(XAxisPosition.valueOf(propMap.getString("position"))); 226 | } 227 | } 228 | 229 | @ReactProp(name = "marker") 230 | public void setMarker(Chart chart, ReadableMap propMap) { 231 | if (!BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled") || !propMap.getBoolean("enabled")) { 232 | chart.setMarkerView(null); 233 | return; 234 | } 235 | 236 | RNMarkerView marker = null; 237 | String type = "rectangle"; 238 | 239 | if (BridgeUtils.validate(propMap, ReadableType.String, "type")) { 240 | type = propMap.getString("type"); 241 | } 242 | 243 | if ("rectangle".equals(type)) { 244 | marker = new RectangleMarker(chart.getContext()); 245 | 246 | } else if ("oval".equals(type)) { 247 | marker = new OvalMarker(chart.getContext()); 248 | 249 | } else { 250 | try { 251 | marker = (RNMarkerView) Class.forName(type) 252 | .getConstructor(Context.class) 253 | .newInstance(chart.getContext()); 254 | 255 | } catch (InstantiationException e) { 256 | e.printStackTrace(); 257 | } catch (InvocationTargetException e) { 258 | e.printStackTrace(); 259 | } catch (NoSuchMethodException e) { 260 | e.printStackTrace(); 261 | } catch (IllegalAccessException e) { 262 | e.printStackTrace(); 263 | } catch (ClassNotFoundException e) { 264 | e.printStackTrace(); 265 | } 266 | } 267 | 268 | if (marker == null) { 269 | return; 270 | } 271 | 272 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && 273 | BridgeUtils.validate(propMap, ReadableType.String, "backgroundTint")) { 274 | marker.getMarkerContent() 275 | .setBackgroundTintList( 276 | ColorStateList.valueOf(Color.parseColor(propMap.getString("backgroundTint"))) 277 | ); 278 | } 279 | 280 | if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) { 281 | marker.getTvContent().setTextColor(Color.parseColor(propMap.getString("textColor"))); 282 | } 283 | if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) { 284 | marker.getTvContent().setTextSize(propMap.getInt("textSize")); 285 | } 286 | if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") || 287 | BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) { 288 | marker.getTvContent() 289 | .setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily")); 290 | } 291 | 292 | chart.setMarkerView(marker); 293 | } 294 | 295 | /** 296 | * General axis config details: https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis 297 | */ 298 | protected void setCommonAxisConfig(Chart chart, AxisBase axis, ReadableMap propMap) { 299 | // what is drawn 300 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) { 301 | axis.setEnabled(propMap.getBoolean("enabled")); 302 | } 303 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawLabels")) { 304 | axis.setDrawLabels(propMap.getBoolean("drawLabels")); 305 | } 306 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawAxisLine")) { 307 | axis.setDrawAxisLine(propMap.getBoolean("drawAxisLine")); 308 | } 309 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawGridLines")) { 310 | axis.setDrawGridLines(propMap.getBoolean("drawGridLines")); 311 | } 312 | 313 | // style 314 | if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) { 315 | axis.setTextColor(Color.parseColor(propMap.getString("textColor"))); 316 | } 317 | if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) { 318 | axis.setTextSize((float) propMap.getDouble("textSize")); 319 | } 320 | if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") || 321 | BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) { 322 | axis.setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily")); 323 | } 324 | if (BridgeUtils.validate(propMap, ReadableType.String, "gridColor")) { 325 | axis.setGridColor(Color.parseColor(propMap.getString("gridColor"))); 326 | } 327 | if (BridgeUtils.validate(propMap, ReadableType.Number, "gridLineWidth")) { 328 | axis.setGridLineWidth((float) propMap.getDouble("gridLineWidth")); 329 | } 330 | if (BridgeUtils.validate(propMap, ReadableType.String, "axisLineColor")) { 331 | axis.setAxisLineColor(Color.parseColor(propMap.getString("axisLineColor"))); 332 | } 333 | if (BridgeUtils.validate(propMap, ReadableType.Number, "axisLineWidth")) { 334 | axis.setAxisLineWidth((float) propMap.getDouble("axisLineWidth")); 335 | } 336 | if (BridgeUtils.validate(propMap, ReadableType.Map, "gridDashedLine")) { 337 | ReadableMap gridDashedLine = propMap.getMap("gridDashedLine"); 338 | float lineLength = 0; 339 | float spaceLength = 0; 340 | float phase = 0; 341 | 342 | if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "lineLength")) { 343 | lineLength = (float) gridDashedLine.getDouble("lineLength"); 344 | } 345 | if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "spaceLength")) { 346 | spaceLength = (float) gridDashedLine.getDouble("spaceLength"); 347 | } 348 | if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "phase")) { 349 | phase = (float) gridDashedLine.getDouble("phase"); 350 | } 351 | 352 | axis.enableGridDashedLine(lineLength, spaceLength, phase); 353 | } 354 | 355 | // limit lines 356 | if (BridgeUtils.validate(propMap, ReadableType.Array, "limitLines")) { 357 | ReadableArray limitLines = propMap.getArray("limitLines"); 358 | 359 | for (int i = 0; i < limitLines.size(); i++) { 360 | if (!ReadableType.Map.equals(limitLines.getType(i))) { 361 | continue; 362 | } 363 | 364 | ReadableMap limitLineMap = limitLines.getMap(i); 365 | if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "limit")) { 366 | LimitLine limitLine = new LimitLine((float) limitLineMap.getDouble("limit")); 367 | 368 | if (BridgeUtils.validate(limitLineMap, ReadableType.String, "label")) { 369 | limitLine.setLabel(limitLineMap.getString("label")); 370 | } 371 | if (BridgeUtils.validate(limitLineMap, ReadableType.String, "lineColor")) { 372 | limitLine.setLineColor(Color.parseColor(limitLineMap.getString("lineColor"))); 373 | } 374 | if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "lineWidth")) { 375 | limitLine.setLineWidth((float) limitLineMap.getDouble("lineWidth")); 376 | } 377 | 378 | axis.addLimitLine(limitLine); 379 | } 380 | 381 | } 382 | } 383 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawLimitLinesBehindData")) { 384 | axis.setDrawLimitLinesBehindData(propMap.getBoolean("drawLimitLinesBehindData")); 385 | } 386 | } 387 | 388 | /** 389 | * 390 | * Dataset config details: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail 391 | */ 392 | @ReactProp(name = "data") 393 | public void setData(Chart chart, ReadableMap propMap) { 394 | if (!BridgeUtils.validate(propMap, ReadableType.Array, "datasets")) { 395 | return; 396 | } 397 | 398 | String[] xValues = new String[0]; 399 | if (BridgeUtils.validate(propMap, ReadableType.Array, "xValues")) { 400 | xValues = BridgeUtils.convertToStringArray(propMap.getArray("xValues")); 401 | } 402 | 403 | ChartData> chartData = createData(xValues); 404 | 405 | ReadableArray datasets = propMap.getArray("datasets"); 406 | for (int i = 0; i < datasets.size(); i++) { 407 | ReadableMap dataset = datasets.getMap(i); 408 | 409 | // TODO validation 410 | ReadableArray yValues = dataset.getArray("yValues"); 411 | String label = dataset.getString("label"); 412 | 413 | ArrayList entries = createEntries(yValues); 414 | 415 | IDataSet lineDataSet = createDataSet(entries, label); 416 | 417 | if (BridgeUtils.validate(dataset, ReadableType.Map, "config")) { 418 | dataSetConfig(lineDataSet, dataset.getMap("config")); 419 | } 420 | 421 | chartData.addDataSet(lineDataSet); 422 | } 423 | 424 | chart.setData(chartData); 425 | chart.invalidate(); 426 | } 427 | 428 | abstract ChartData> createData(String[] xValues); 429 | abstract IDataSet createDataSet(ArrayList entries, String label); 430 | abstract void dataSetConfig(IDataSet dataSet, ReadableMap config); 431 | 432 | ArrayList createEntries(ReadableArray yValues) { 433 | ArrayList entries = new ArrayList<>(yValues.size()); 434 | for (int j = 0; j < yValues.size(); j++) { 435 | if (!yValues.isNull(j)) { 436 | entries.add(createEntry(yValues, j)); 437 | } 438 | } 439 | return entries; 440 | } 441 | 442 | U createEntry(ReadableArray yValues, int index) { 443 | return (U) new Entry((float) yValues.getDouble(index), index); 444 | } 445 | 446 | } 447 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/CustomFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | import com.github.mikephil.charting.formatter.YAxisValueFormatter; 5 | 6 | public class CustomFormatter implements YAxisValueFormatter { 7 | 8 | private String mFormat; 9 | 10 | public CustomFormatter(String value) { 11 | this.mFormat = value; 12 | } 13 | 14 | @Override 15 | public String getFormattedValue(float value, YAxis yAxis) { 16 | return String.format(mFormat, value); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/LineChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | 4 | import android.graphics.Color; 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.facebook.react.bridge.ReadableType; 7 | 8 | import com.facebook.react.uimanager.ThemedReactContext; 9 | import com.github.mikephil.charting.charts.LineChart; 10 | import com.github.mikephil.charting.data.ChartData; 11 | import com.github.mikephil.charting.data.Entry; 12 | import com.github.mikephil.charting.data.LineData; 13 | import com.github.mikephil.charting.data.LineDataSet; 14 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 15 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 16 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class LineChartManager extends BarLineChartBaseManager { 21 | 22 | @Override 23 | public String getName() { 24 | return "MPAndroidLineChart"; 25 | } 26 | 27 | @Override 28 | protected LineChart createViewInstance(ThemedReactContext reactContext) { 29 | return new LineChart(reactContext); 30 | } 31 | 32 | @Override 33 | ChartData createData(String[] xValues) { 34 | return new LineData(xValues); 35 | } 36 | 37 | @Override 38 | IDataSet createDataSet(ArrayList entries, String label) { 39 | return new LineDataSet(entries, label); 40 | } 41 | 42 | @Override 43 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 44 | LineDataSet lineDataSet = (LineDataSet) dataSet; 45 | 46 | ChartDataSetConfigUtils.commonConfig(lineDataSet, config); 47 | ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(lineDataSet, config); 48 | ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(lineDataSet, config); 49 | ChartDataSetConfigUtils.commonLineRadarConfig(lineDataSet, config); 50 | 51 | // LineDataSet only config 52 | if (BridgeUtils.validate(config, ReadableType.Number, "circleRadius")) { 53 | lineDataSet.setCircleRadius((float) config.getDouble("circleRadius")); 54 | } 55 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCircles")) { 56 | lineDataSet.setDrawCircles(config.getBoolean("drawCircles")); 57 | } 58 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCubic")) { 59 | lineDataSet.setDrawCubic(config.getBoolean("drawCubic")); 60 | } 61 | if (BridgeUtils.validate(config, ReadableType.Number, "drawCubicIntensity")) { 62 | lineDataSet.setCubicIntensity((float) config.getDouble("drawCubicIntensity")); 63 | } 64 | if (BridgeUtils.validate(config, ReadableType.String, "circleColor")) { 65 | lineDataSet.setCircleColor(Color.parseColor(config.getString("circleColor"))); 66 | } 67 | if (BridgeUtils.validate(config, ReadableType.Array, "circleColors")) { 68 | lineDataSet.setCircleColors(BridgeUtils.parseColors(config.getArray("circleColors"))); 69 | } 70 | if (BridgeUtils.validate(config, ReadableType.String, "circleColorHole")) { 71 | lineDataSet.setCircleColorHole(Color.parseColor(config.getString("circleColorHole"))); 72 | } 73 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCircleHole")) { 74 | lineDataSet.setDrawCircleHole(config.getBoolean("drawCircleHole")); 75 | } 76 | if (BridgeUtils.validate(config, ReadableType.Map, "dashedLine")) { 77 | ReadableMap dashedLine = config.getMap("dashedLine"); 78 | float lineLength = 0; 79 | float spaceLength = 0; 80 | float phase = 0; 81 | 82 | if (BridgeUtils.validate(dashedLine, ReadableType.Number, "lineLength")) { 83 | lineLength = (float) dashedLine.getDouble("lineLength"); 84 | } 85 | if (BridgeUtils.validate(dashedLine, ReadableType.Number, "spaceLength")) { 86 | spaceLength = (float) dashedLine.getDouble("spaceLength"); 87 | } 88 | if (BridgeUtils.validate(dashedLine, ReadableType.Number, "phase")) { 89 | phase = (float) dashedLine.getDouble("phase"); 90 | } 91 | 92 | lineDataSet.enableDashedLine(lineLength, spaceLength, phase); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/PieChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | 4 | import android.graphics.Color; 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.facebook.react.bridge.ReadableType; 7 | import com.facebook.react.uimanager.ThemedReactContext; 8 | import com.facebook.react.uimanager.annotations.ReactProp; 9 | import com.github.mikephil.charting.charts.PieChart; 10 | import com.github.mikephil.charting.data.ChartData; 11 | import com.github.mikephil.charting.data.Entry; 12 | import com.github.mikephil.charting.data.PieData; 13 | import com.github.mikephil.charting.data.PieDataSet; 14 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 15 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 16 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class PieChartManager extends ChartBaseManager { 21 | 22 | @Override 23 | public String getName() { 24 | return "MPAndroidPieChart"; 25 | } 26 | 27 | @Override 28 | protected PieChart createViewInstance(ThemedReactContext reactContext) { 29 | return new PieChart(reactContext); 30 | } 31 | 32 | @Override 33 | ChartData createData(String[] xValues) { 34 | return new PieData(xValues); 35 | } 36 | 37 | @Override 38 | IDataSet createDataSet(ArrayList entries, String label) { 39 | return new PieDataSet(entries, label); 40 | } 41 | 42 | @Override 43 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 44 | PieDataSet pieDataSet = (PieDataSet) dataSet; 45 | 46 | ChartDataSetConfigUtils.commonConfig(pieDataSet, config); 47 | 48 | // PieDataSet only config 49 | if (BridgeUtils.validate(config, ReadableType.Number, "sliceSpace")) { 50 | pieDataSet.setSliceSpace((float) config.getDouble("sliceSpace")); 51 | } 52 | if (BridgeUtils.validate(config, ReadableType.Number, "selectionShift")) { 53 | pieDataSet.setSelectionShift((float) config.getDouble("selectionShift")); 54 | } 55 | } 56 | 57 | @ReactProp(name = "drawSliceText") 58 | public void setDrawSliceText(PieChart chart, boolean enabled) { 59 | chart.setDrawSliceText(enabled); 60 | } 61 | 62 | @ReactProp(name = "usePercentValues") 63 | public void setUsePercentValues(PieChart chart, boolean enabled) { 64 | chart.setUsePercentValues(enabled); 65 | } 66 | 67 | @ReactProp(name = "centerText") 68 | public void setCenterText(PieChart chart, String text) { 69 | chart.setCenterText(text); 70 | } 71 | 72 | @ReactProp(name = "centerTextRadiusPercent") 73 | public void setCenterTextRadiusPercent(PieChart chart, float radiusPercent) { 74 | chart.setCenterTextRadiusPercent(radiusPercent); 75 | } 76 | 77 | @ReactProp(name = "holeRadius") 78 | public void setHoleRadius(PieChart chart, float percent) { 79 | chart.setHoleRadius(percent); 80 | } 81 | 82 | @ReactProp(name = "holeColor") 83 | public void setHoleColor(PieChart chart, String color) { 84 | chart.setHoleColor(Color.parseColor(color)); 85 | } 86 | 87 | @ReactProp(name = "transparentCircleRadius") 88 | public void setTransparentCircleRadius(PieChart chart, float percent) { 89 | chart.setTransparentCircleRadius(percent); 90 | } 91 | 92 | @ReactProp(name = "transparentCircleColor") 93 | public void setTransparentCircleColor(PieChart chart, String color) { 94 | chart.setTransparentCircleColor(Color.parseColor(color)); 95 | } 96 | 97 | @ReactProp(name = "transparentCircleAlpha") 98 | public void setTransparentCircleAlpha(PieChart chart, int alpha) { 99 | chart.setTransparentCircleAlpha(alpha); 100 | } 101 | 102 | @ReactProp(name = "maxAngle") 103 | public void setMaxAngle(PieChart chart, float maxAngle) { 104 | chart.setMaxAngle(maxAngle); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/RadarChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | 4 | import com.facebook.react.bridge.ReadableMap; 5 | import com.facebook.react.uimanager.ThemedReactContext; 6 | import com.facebook.react.uimanager.annotations.ReactProp; 7 | import com.github.mikephil.charting.charts.Chart; 8 | import com.github.mikephil.charting.charts.RadarChart; 9 | import com.github.mikephil.charting.components.YAxis; 10 | import com.github.mikephil.charting.data.ChartData; 11 | import com.github.mikephil.charting.data.Entry; 12 | import com.github.mikephil.charting.data.RadarData; 13 | import com.github.mikephil.charting.data.RadarDataSet; 14 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 15 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 16 | 17 | import java.util.ArrayList; 18 | 19 | public class RadarChartManager extends YAxisChartBase { 20 | 21 | @Override 22 | public String getName() { 23 | return "MPAndroidRadarChart"; 24 | } 25 | 26 | @Override 27 | protected RadarChart createViewInstance(ThemedReactContext reactContext) { 28 | return new RadarChart(reactContext); 29 | } 30 | 31 | @Override 32 | public void setYAxis(Chart chart, ReadableMap propMap) { 33 | RadarChart radarChart = (RadarChart) chart; 34 | YAxis axis = radarChart.getYAxis(); 35 | 36 | setCommonAxisConfig(chart, axis, propMap); 37 | setYAxisConfig(axis, propMap); 38 | } 39 | 40 | @Override 41 | ChartData createData(String[] xValues) { 42 | return new RadarData(xValues); 43 | } 44 | 45 | @Override 46 | IDataSet createDataSet(ArrayList entries, String label) { 47 | return new RadarDataSet(entries, label); 48 | } 49 | 50 | @Override 51 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 52 | RadarDataSet radarDataSet = (RadarDataSet) dataSet; 53 | 54 | ChartDataSetConfigUtils.commonConfig(radarDataSet, config); 55 | ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(radarDataSet, config); 56 | ChartDataSetConfigUtils.commonLineRadarConfig(radarDataSet, config); 57 | 58 | // RadarDataSet only config 59 | } 60 | 61 | @ReactProp(name = "skipWebLineCount") 62 | public void setSkipWebLineCount(RadarChart chart, int count) { 63 | chart.setSkipWebLineCount(count); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/ScatterChartManager.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | 4 | import android.graphics.Color; 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.facebook.react.bridge.ReadableType; 7 | import com.facebook.react.uimanager.ThemedReactContext; 8 | import com.github.mikephil.charting.charts.ScatterChart; 9 | import com.github.mikephil.charting.charts.ScatterChart.ScatterShape; 10 | import com.github.mikephil.charting.data.ChartData; 11 | import com.github.mikephil.charting.data.Entry; 12 | import com.github.mikephil.charting.data.ScatterData; 13 | import com.github.mikephil.charting.data.ScatterDataSet; 14 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 15 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 16 | import com.github.reactNativeMPAndroidChart.utils.ChartDataSetConfigUtils; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class ScatterChartManager extends BarLineChartBaseManager { 21 | 22 | @Override 23 | public String getName() { 24 | return "MPAndroidScatterChart"; 25 | } 26 | 27 | @Override 28 | protected ScatterChart createViewInstance(ThemedReactContext reactContext) { 29 | return new ScatterChart(reactContext); 30 | } 31 | 32 | @Override 33 | ChartData createData(String[] xValues) { 34 | return new ScatterData(xValues); 35 | } 36 | 37 | @Override 38 | IDataSet createDataSet(ArrayList entries, String label) { 39 | return new ScatterDataSet(entries, label); 40 | } 41 | 42 | @Override 43 | void dataSetConfig(IDataSet dataSet, ReadableMap config) { 44 | ScatterDataSet scatterDataSet = (ScatterDataSet) dataSet; 45 | 46 | ChartDataSetConfigUtils.commonConfig(scatterDataSet, config); 47 | ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(scatterDataSet, config); 48 | ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(scatterDataSet, config); 49 | 50 | // ScatterDataSet only config 51 | if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeSize")) { 52 | scatterDataSet.setScatterShapeSize((float) config.getDouble("scatterShapeSize")); 53 | } 54 | if (BridgeUtils.validate(config, ReadableType.String, "scatterShape")) { 55 | scatterDataSet.setScatterShape(ScatterShape.valueOf(config.getString("scatterShape").toUpperCase())); 56 | } 57 | if (BridgeUtils.validate(config, ReadableType.String, "scatterShapeHoleColor")) { 58 | scatterDataSet.setScatterShapeHoleColor(Color.parseColor(config.getString("scatterShapeHoleColor"))); 59 | } 60 | if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeHoleRadius")) { 61 | scatterDataSet.setScatterShapeHoleRadius((float) config.getDouble("scatterShapeHoleRadius")); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/charts/YAxisChartBase.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.charts; 2 | 3 | import android.graphics.Color; 4 | import com.facebook.react.bridge.ReadableMap; 5 | import com.facebook.react.bridge.ReadableType; 6 | import com.facebook.react.uimanager.annotations.ReactProp; 7 | import com.github.mikephil.charting.charts.Chart; 8 | import com.github.mikephil.charting.components.YAxis; 9 | import com.github.mikephil.charting.data.Entry; 10 | import com.github.mikephil.charting.formatter.LargeValueFormatter; 11 | import com.github.mikephil.charting.formatter.PercentFormatter; 12 | import com.github.reactNativeMPAndroidChart.utils.BridgeUtils; 13 | 14 | public abstract class YAxisChartBase extends ChartBaseManager { 15 | 16 | /** 17 | * yAxis config details: https://github.com/PhilJay/MPAndroidChart/wiki/YAxis 18 | */ 19 | @ReactProp(name = "yAxis") 20 | public abstract void setYAxis(Chart chart, ReadableMap propMap); 21 | 22 | protected void setYAxisConfig(YAxis axis, ReadableMap propMap) { 23 | if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaxValue")) { 24 | axis.setAxisMaxValue((float) propMap.getDouble("axisMaxValue")); 25 | } 26 | if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinValue")) { 27 | axis.setAxisMinValue((float) propMap.getDouble("axisMinValue")); 28 | } 29 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "inverted")) { 30 | axis.setInverted(propMap.getBoolean("inverted")); 31 | } 32 | if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceTop")) { 33 | axis.setSpaceTop((float) propMap.getDouble("spaceTop")); 34 | } 35 | if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBottom")) { 36 | axis.setSpaceBottom((float) propMap.getDouble("spaceBottom")); 37 | } 38 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "showOnlyMinMax")) { 39 | axis.setShowOnlyMinMax(propMap.getBoolean("showOnlyMinMax")); 40 | } 41 | if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) { 42 | boolean labelCountForce = false; 43 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) { 44 | labelCountForce = propMap.getBoolean("labelCountForce"); 45 | } 46 | axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce); 47 | } 48 | if (BridgeUtils.validate(propMap, ReadableType.String, "position")) { 49 | axis.setPosition(YAxis.YAxisLabelPosition.valueOf(propMap.getString("position"))); 50 | } 51 | if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) { 52 | axis.setGranularity((float) propMap.getDouble("granularity")); 53 | } 54 | if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) { 55 | axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled")); 56 | } 57 | 58 | 59 | // formatting 60 | if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) { 61 | String valueFormatter = propMap.getString("valueFormatter"); 62 | 63 | if ("largeValue".equals(valueFormatter)) { 64 | axis.setValueFormatter(new LargeValueFormatter()); 65 | } else if ("percent".equals(valueFormatter)) { 66 | axis.setValueFormatter(new PercentFormatter()); 67 | } else { 68 | axis.setValueFormatter(new CustomFormatter(valueFormatter)); 69 | } 70 | } 71 | 72 | // TODO docs says the remaining config needs to be applied before setting data. Test it 73 | // zero line 74 | if (BridgeUtils.validate(propMap, ReadableType.Map, "zeroLine")) { 75 | ReadableMap zeroLineConfig = propMap.getMap("zeroLine"); 76 | 77 | if (BridgeUtils.validate(zeroLineConfig, ReadableType.Boolean, "enabled")) { 78 | axis.setDrawZeroLine(zeroLineConfig.getBoolean("enabled")); 79 | } 80 | if (BridgeUtils.validate(zeroLineConfig, ReadableType.Number, "lineWidth")) { 81 | axis.setZeroLineWidth((float) zeroLineConfig.getDouble("lineWidth")); 82 | } 83 | if (BridgeUtils.validate(zeroLineConfig, ReadableType.String, "lineColor")) { 84 | axis.setZeroLineColor(Color.parseColor(zeroLineConfig.getString("lineColor"))); 85 | } 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/markers/OvalMarker.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.markers; 2 | 3 | import android.content.Context; 4 | import com.github.reactNativeMPAndroidChart.R; 5 | 6 | public class OvalMarker extends RNMarkerView { 7 | public OvalMarker(Context context) { 8 | super(context, R.layout.oval_marker, R.id.oval_markerContent, R.id.oval_tvContent); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/markers/RNMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.markers; 2 | 3 | import android.content.Context; 4 | import android.widget.RelativeLayout; 5 | import android.widget.TextView; 6 | import com.github.mikephil.charting.components.MarkerView; 7 | import com.github.mikephil.charting.data.CandleEntry; 8 | import com.github.mikephil.charting.data.Entry; 9 | import com.github.mikephil.charting.highlight.Highlight; 10 | import com.github.mikephil.charting.utils.Utils; 11 | 12 | public abstract class RNMarkerView extends MarkerView { 13 | 14 | private RelativeLayout markerContent; 15 | private TextView tvContent; 16 | 17 | public RNMarkerView(Context context, int layoutResource, int markerContentId, int tvContentId) { 18 | super(context, layoutResource); 19 | 20 | tvContent = (TextView) findViewById(tvContentId); 21 | markerContent = (RelativeLayout) findViewById(markerContentId); 22 | } 23 | 24 | @Override 25 | public void refreshContent(Entry e, Highlight highlight) { 26 | if (e instanceof CandleEntry) { 27 | CandleEntry ce = (CandleEntry) e; 28 | tvContent.setText(Utils.formatNumber(ce.getClose(), 2, true)); 29 | } else { 30 | tvContent.setText(Utils.formatNumber(e.getVal(), 0, true)); 31 | } 32 | } 33 | 34 | @Override 35 | public int getXOffset(float xpos) { 36 | // this will center the marker-view horizontally 37 | return -(getWidth() / 2); 38 | } 39 | 40 | @Override 41 | public int getYOffset(float ypos) { 42 | // this will cause the marker-view to be above the selected value 43 | return -getHeight(); 44 | } 45 | 46 | public TextView getTvContent() { 47 | return tvContent; 48 | } 49 | 50 | public RelativeLayout getMarkerContent() { 51 | return markerContent; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/markers/RectangleMarker.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.markers; 2 | 3 | import android.content.Context; 4 | 5 | import com.github.reactNativeMPAndroidChart.R; 6 | 7 | public class RectangleMarker extends RNMarkerView { 8 | public RectangleMarker(Context context) { 9 | super(context, R.layout.rectangle_marker, R.id.rectangle_markerContent, R.id.rectangle_tvContent); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/utils/BridgeUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.Typeface; 6 | import com.facebook.react.bridge.ReadableArray; 7 | import com.facebook.react.bridge.ReadableMap; 8 | import com.facebook.react.bridge.ReadableType; 9 | import com.facebook.react.views.text.ReactFontManager; 10 | 11 | public class BridgeUtils { 12 | 13 | public static boolean validate(ReadableMap map, ReadableType propType, String propName) { 14 | return map.hasKey(propName) && propType.equals(map.getType(propName)); 15 | } 16 | 17 | public static int[] convertToIntArray(ReadableArray readableArray) { 18 | int[] array = new int[readableArray.size()]; 19 | 20 | for (int i = 0; i < readableArray.size(); i++) { 21 | if (!ReadableType.Number.equals(readableArray.getType(i))) { 22 | throw new IllegalArgumentException("Expecting array of numbers"); 23 | } 24 | array[i] = readableArray.getInt(i); 25 | } 26 | 27 | return array; 28 | } 29 | 30 | public static float[] convertToFloatArray(ReadableArray readableArray) { 31 | float[] array = new float[readableArray.size()]; 32 | 33 | for (int i = 0; i < readableArray.size(); i++) { 34 | if (!ReadableType.Number.equals(readableArray.getType(i))) { 35 | throw new IllegalArgumentException("Expecting array of numbers"); 36 | } 37 | array[i] = (float) readableArray.getDouble(i); 38 | } 39 | 40 | return array; 41 | } 42 | 43 | public static String[] convertToStringArray(ReadableArray readableArray) { 44 | String[] array = new String[readableArray.size()]; 45 | 46 | for (int i = 0; i < readableArray.size(); i++) { 47 | if (!ReadableType.String.equals(readableArray.getType(i))) { 48 | throw new IllegalArgumentException("Expecting array of strings"); 49 | } 50 | array[i] = readableArray.getString(i); 51 | } 52 | 53 | return array; 54 | } 55 | 56 | 57 | public static int[] parseColors(ReadableArray readableArray) { 58 | int[] array = new int[readableArray.size()]; 59 | 60 | for (int i = 0; i < readableArray.size(); i++) { 61 | if (!ReadableType.String.equals(readableArray.getType(i))) { 62 | throw new IllegalArgumentException("Expecting array of strings"); 63 | } 64 | array[i] = Color.parseColor(readableArray.getString(i)); 65 | } 66 | 67 | return array; 68 | } 69 | 70 | /** 71 | * fontStyle: NORMAL = 0, BOLD = 1, ITALIC = 2, BOLD_ITALIC = 3 72 | */ 73 | public static Typeface parseTypeface(Context context, ReadableMap propMap, String styleKey, String familyKey) { 74 | String fontFamily = null; 75 | if (propMap.hasKey(familyKey)) { 76 | fontFamily = propMap.getString(familyKey); 77 | } 78 | 79 | int style = 0; 80 | if (propMap.hasKey(styleKey)) { 81 | style = propMap.getInt(styleKey); 82 | } 83 | 84 | return ReactFontManager.getInstance().getTypeface(fontFamily, style, context.getAssets()); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/reactNativeMPAndroidChart/utils/ChartDataSetConfigUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.reactNativeMPAndroidChart.utils; 2 | 3 | import android.graphics.Color; 4 | import com.facebook.react.bridge.ReadableMap; 5 | import com.facebook.react.bridge.ReadableType; 6 | import com.github.mikephil.charting.data.BarLineScatterCandleBubbleDataSet; 7 | import com.github.mikephil.charting.data.DataSet; 8 | import com.github.mikephil.charting.data.LineRadarDataSet; 9 | import com.github.mikephil.charting.data.LineScatterCandleRadarDataSet; 10 | 11 | /** 12 | * https://github.com/PhilJay/MPAndroidChart/wiki/The-DataSet-class 13 | * https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail 14 | */ 15 | public class ChartDataSetConfigUtils { 16 | 17 | public static void commonConfig(DataSet dataSet, ReadableMap config) { 18 | // Setting main color 19 | if (BridgeUtils.validate(config, ReadableType.String, "color")) { 20 | dataSet.setColor(Color.parseColor(config.getString("color"))); 21 | } 22 | if (BridgeUtils.validate(config, ReadableType.Array, "colors")) { 23 | dataSet.setColors(BridgeUtils.parseColors(config.getArray("colors"))); 24 | } 25 | 26 | // TODO more config to add: https://github.com/PhilJay/MPAndroidChart/wiki/The-DataSet-class 27 | 28 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawValues")) { 29 | dataSet.setDrawValues(config.getBoolean("drawValues")); 30 | } 31 | } 32 | 33 | public static void commonBarLineScatterCandleBubbleConfig(BarLineScatterCandleBubbleDataSet dataSet, ReadableMap config) { 34 | if (BridgeUtils.validate(config, ReadableType.String, "highlightColor")) { 35 | dataSet.setHighLightColor(Color.parseColor(config.getString("highlightColor"))); 36 | } 37 | } 38 | 39 | public static void commonLineScatterCandleRadarConfig(LineScatterCandleRadarDataSet dataSet, ReadableMap config) { 40 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawHighlightIndicators")) { 41 | dataSet.setDrawHighlightIndicators(config.getBoolean("drawHighlightIndicators")); 42 | } 43 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawVerticalHighlightIndicator")) { 44 | dataSet.setDrawVerticalHighlightIndicator(config.getBoolean("drawVerticalHighlightIndicator")); 45 | } 46 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawHorizontalHighlightIndicator")) { 47 | dataSet.setDrawHorizontalHighlightIndicator(config.getBoolean("drawHorizontalHighlightIndicator")); 48 | } 49 | if (BridgeUtils.validate(config, ReadableType.Number, "highlightLineWidth")) { 50 | dataSet.setHighlightLineWidth((float) config.getDouble("highlightLineWidth")); 51 | } 52 | } 53 | 54 | public static void commonLineRadarConfig(LineRadarDataSet dataSet, ReadableMap config) { 55 | if (BridgeUtils.validate(config, ReadableType.String, "fillColor")) { 56 | dataSet.setFillColor(Color.parseColor(config.getString("fillColor"))); 57 | } 58 | if (BridgeUtils.validate(config, ReadableType.Number, "fillAlpha")) { 59 | dataSet.setFillAlpha(config.getInt("fillAlpha")); 60 | } 61 | // TODO setFillDrawable android.graphics.drawable.Drawable 62 | if (BridgeUtils.validate(config, ReadableType.Boolean, "drawFilled")) { 63 | dataSet.setDrawFilled(config.getBoolean("drawFilled")); 64 | } 65 | if (BridgeUtils.validate(config, ReadableType.Number, "lineWidth")) { 66 | float lineWidth = (float) config.getDouble("lineWidth"); 67 | if (lineWidth >= 0.2f && lineWidth < 10f) { 68 | dataSet.setLineWidth(lineWidth); 69 | } 70 | } 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /android/src/main/res/drawable-nodpi/oval_marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mskec/react-native-mp-android-chart/854e34d2befa9a7b81d953c5a7117711a9477f06/android/src/main/res/drawable-nodpi/oval_marker.png -------------------------------------------------------------------------------- /android/src/main/res/drawable-nodpi/rectangle_marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mskec/react-native-mp-android-chart/854e34d2befa9a7b81d953c5a7117711a9477f06/android/src/main/res/drawable-nodpi/rectangle_marker.png -------------------------------------------------------------------------------- /android/src/main/res/layout/oval_marker.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /android/src/main/res/layout/rectangle_marker.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /index.android.js: -------------------------------------------------------------------------------- 1 | import BarChart from './lib/BarChart'; 2 | import BubbleChart from './lib/BubbleChart'; 3 | import CandleStickChart from './lib/CandleStickChart'; 4 | import LineChart from './lib/LineChart'; 5 | import PieChart from './lib/PieChart'; 6 | import RadarChart from './lib/RadarChart'; 7 | import ScatterChart from './lib/ScatterChart'; 8 | 9 | module.exports = { 10 | BarChart, 11 | BubbleChart, 12 | CandleStickChart, 13 | LineChart, 14 | PieChart, 15 | RadarChart, 16 | ScatterChart 17 | }; 18 | -------------------------------------------------------------------------------- /lib/BarChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import BarLineChartBase from './BarLineChartBase'; 8 | import ChartDataSetConfig from './ChartDataSetConfig'; 9 | 10 | const iface = { 11 | name: 'BarChart', 12 | propTypes: { 13 | ...BarLineChartBase.propTypes, 14 | 15 | drawValueAboveBar: PropTypes.bool, 16 | drawBarShadow: PropTypes.bool, 17 | drawHighlightArrow: PropTypes.bool, 18 | 19 | data: PropTypes.shape({ 20 | datasets: PropTypes.arrayOf(PropTypes.shape({ 21 | yValues: PropTypes.arrayOf( 22 | PropTypes.oneOfType([ 23 | PropTypes.number, 24 | PropTypes.arrayOf(PropTypes.number) 25 | ]) 26 | ), 27 | label: PropTypes.string, 28 | config: PropTypes.shape({ 29 | ...ChartDataSetConfig.common, 30 | ...ChartDataSetConfig.barLineScatterCandleBubble, 31 | 32 | barSpacePercent: PropTypes.number, 33 | barShadowColor: PropTypes.string, 34 | highlightAlpha: PropTypes.number, 35 | stackLabels: PropTypes.arrayOf(PropTypes.string) 36 | }) 37 | })), 38 | xValues: PropTypes.arrayOf(PropTypes.string) 39 | }) 40 | } 41 | }; 42 | 43 | export default requireNativeComponent('MPAndroidBarChart', iface); 44 | -------------------------------------------------------------------------------- /lib/BarLineChartBase.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | View 4 | } from 'react-native'; 5 | 6 | import ChartBase from './ChartBase'; 7 | import {yAxisIface} from './YAxisIface'; 8 | 9 | const iface = { 10 | propTypes: { 11 | ...ChartBase.propTypes, 12 | 13 | drawGridBackground: PropTypes.bool, 14 | gridBackgroundColor: PropTypes.string, 15 | 16 | drawBorders: PropTypes.bool, 17 | borderColor: PropTypes.string, 18 | borderWidth: PropTypes.number, 19 | 20 | maxVisibleValueCount: PropTypes.number, 21 | autoScaleMinMaxEnabled: PropTypes.bool, 22 | keepPositionOnRotation: PropTypes.bool, 23 | 24 | scaleEnabled: PropTypes.bool, 25 | scaleXEnabled: PropTypes.bool, 26 | scaleYEnabled: PropTypes.bool, 27 | dragEnabled: PropTypes.bool, 28 | pinchZoom: PropTypes.bool, 29 | doubleTapToZoomEnabled: PropTypes.bool, 30 | 31 | yAxis: PropTypes.shape({ 32 | left: PropTypes.shape(yAxisIface), 33 | right: PropTypes.shape(yAxisIface) 34 | }), 35 | zoom: PropTypes.shape({ 36 | scaleX: PropTypes.number.isRequired, 37 | scaleY: PropTypes.number.isRequired, 38 | xValue: PropTypes.number.isRequired, 39 | yValue: PropTypes.number.isRequired, 40 | axisDependency: PropTypes.oneOf(['LEFT', 'RIGHT']) 41 | }), 42 | } 43 | }; 44 | 45 | export default iface; 46 | -------------------------------------------------------------------------------- /lib/BubbleChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import ChartBase from './ChartBase'; 8 | import ChartDataSetConfig from './ChartDataSetConfig'; 9 | 10 | const iface = { 11 | name: 'BubbleChart', 12 | propTypes: { 13 | ...ChartBase.propTypes, 14 | 15 | data: PropTypes.shape({ 16 | datasets: PropTypes.arrayOf(PropTypes.shape({ 17 | yValues: PropTypes.arrayOf( 18 | PropTypes.shape({ 19 | value: PropTypes.number.isRequired, 20 | size: PropTypes.number.isRequired 21 | }) 22 | ), 23 | label: PropTypes.string, 24 | config: PropTypes.shape({ 25 | ...ChartDataSetConfig.common, 26 | ...ChartDataSetConfig.barLineScatterCandleBubble, 27 | 28 | }) 29 | })), 30 | xValues: PropTypes.arrayOf(PropTypes.string) 31 | }) 32 | } 33 | }; 34 | 35 | export default requireNativeComponent('MPAndroidBubbleChart', iface); 36 | -------------------------------------------------------------------------------- /lib/CandleStickChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import BarLineChartBase from './BarLineChartBase'; 8 | import ChartDataSetConfig from './ChartDataSetConfig'; 9 | 10 | const iface = { 11 | name: 'CandleStickChart', 12 | propTypes: { 13 | ...BarLineChartBase.propTypes, 14 | 15 | data: PropTypes.shape({ 16 | datasets: PropTypes.arrayOf(PropTypes.shape({ 17 | yValues: PropTypes.arrayOf( 18 | PropTypes.shape({ 19 | shadowH: PropTypes.number.isRequired, 20 | shadowL: PropTypes.number.isRequired, 21 | open: PropTypes.number.isRequired, 22 | close: PropTypes.number.isRequired, 23 | }) 24 | ), 25 | label: PropTypes.string, 26 | config: PropTypes.shape({ 27 | ...ChartDataSetConfig.common, 28 | ...ChartDataSetConfig.barLineScatterCandleBubble, 29 | ...ChartDataSetConfig.lineScatterCandleRadar, 30 | 31 | barSpace: PropTypes.number, 32 | shadowWidth: PropTypes.number, 33 | shadowColor: PropTypes.string, 34 | shadowColorSameAsCandle: PropTypes.bool, 35 | neutralColor: PropTypes.string, 36 | decreasingColor: PropTypes.string, 37 | decreasingPaintStyle: PropTypes.string, 38 | increasingColor: PropTypes.string, 39 | increasingPaintStyle: PropTypes.string 40 | }) 41 | })), 42 | xValues: PropTypes.arrayOf(PropTypes.string) 43 | }) 44 | } 45 | }; 46 | 47 | export default requireNativeComponent('MPAndroidCandleStickChart', iface); 48 | -------------------------------------------------------------------------------- /lib/ChartBase.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | View 4 | } from 'react-native'; 5 | 6 | 7 | export const axisIface = { 8 | // what is drawn 9 | enabled: PropTypes.bool, 10 | drawLabels: PropTypes.bool, 11 | drawAxisLine: PropTypes.bool, 12 | drawGridLines: PropTypes.bool, 13 | 14 | // style 15 | textColor: PropTypes.string, 16 | textSize: PropTypes.number, 17 | fontFamily: PropTypes.string, 18 | fontStyle: PropTypes.number, 19 | gridColor: PropTypes.string, 20 | gridLineWidth: PropTypes.number, 21 | axisLineColor: PropTypes.string, 22 | axisLineWidth: PropTypes.number, 23 | gridDashedLine: PropTypes.shape({ 24 | lineLength: PropTypes.number, 25 | spaceLength: PropTypes.number, 26 | phase: PropTypes.number 27 | }), 28 | 29 | // limit lines 30 | limitLines: PropTypes.arrayOf( 31 | PropTypes.shape({ 32 | limit: PropTypes.number.isRequired, 33 | label: PropTypes.string, 34 | lineColor: PropTypes.string, 35 | lineWidth: PropTypes.number, 36 | }) 37 | ), 38 | drawLimitLinesBehindData: PropTypes.bool 39 | }; 40 | 41 | const descriptionIface = { 42 | text: PropTypes.string, 43 | textColor: PropTypes.string, 44 | textSize: PropTypes.number, 45 | 46 | positionX: PropTypes.number, 47 | positionY: PropTypes.number, 48 | 49 | fontFamily: PropTypes.string, 50 | fontStyle: PropTypes.number 51 | }; 52 | 53 | const legendIface = { 54 | enabled: PropTypes.bool, 55 | 56 | textColor: PropTypes.string, 57 | textSize: PropTypes.number, 58 | fontFamily: PropTypes.string, 59 | fontStyle: PropTypes.number, 60 | 61 | wordWrapEnabled: PropTypes.bool, 62 | maxSizePercent: PropTypes.number, 63 | 64 | position: PropTypes.string, 65 | form: PropTypes.string, 66 | formSize: PropTypes.number, 67 | xEntrySpace: PropTypes.number, 68 | yEntrySpace: PropTypes.number, 69 | formToTextSpace: PropTypes.number, 70 | 71 | custom: PropTypes.shape({ 72 | colors: PropTypes.arrayOf(PropTypes.string), 73 | labels: PropTypes.arrayOf(PropTypes.string) 74 | }) 75 | }; 76 | 77 | const chartIface = { 78 | propTypes: { 79 | ...View.propTypes, 80 | 81 | animation: PropTypes.shape({ 82 | durationX: PropTypes.number, 83 | durationY: PropTypes.number, 84 | 85 | easingX: PropTypes.string, 86 | easingY: PropTypes.string 87 | }), 88 | 89 | backgroundColor: PropTypes.string, 90 | logEnabled: PropTypes.bool, 91 | noDataText: PropTypes.string, 92 | noDataTextDescription: PropTypes.string, 93 | 94 | touchEnabled: PropTypes.bool, 95 | dragDecelerationEnabled: PropTypes.bool, 96 | dragDecelerationFrictionCoef: (props, propName, componentName) => { 97 | let coef = props[propName]; 98 | if (coef && (typeof coef !== 'number' || coef < 0 || coef > 1)) { 99 | return new Error( 100 | `Invalid prop ${propName} supplied to '${componentName}'. Value must be number and between 0 and 1.` 101 | ); 102 | } 103 | }, 104 | 105 | description: PropTypes.shape(descriptionIface), 106 | 107 | legend: PropTypes.shape(legendIface), 108 | 109 | xAxis: PropTypes.shape({ 110 | ...axisIface, 111 | 112 | labelsToSkip: PropTypes.number, 113 | avoidFirstLastClipping: PropTypes.bool, 114 | spaceBetweenLabels: PropTypes.number, 115 | position: PropTypes.string 116 | }), 117 | 118 | marker: PropTypes.shape({ 119 | enabled: PropTypes.bool, 120 | type: PropTypes.oneOfType([ 121 | PropTypes.oneOf(['rectangle', 'oval']), 122 | PropTypes.string 123 | ]), 124 | backgroundTint: PropTypes.string, 125 | textColor: PropTypes.string, 126 | textSize: PropTypes.number, 127 | fontFamily: PropTypes.string, 128 | fontStyle: PropTypes.number 129 | }), 130 | } 131 | }; 132 | 133 | export default chartIface; 134 | -------------------------------------------------------------------------------- /lib/ChartDataSetConfig.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | 8 | const chartDataSetConfig = { 9 | common: { 10 | color: PropTypes.string, 11 | colors: PropTypes.arrayOf(PropTypes.string), 12 | 13 | drawValues: PropTypes.bool 14 | }, 15 | 16 | barLineScatterCandleBubble: { 17 | highlightColor: PropTypes.string 18 | }, 19 | 20 | lineScatterCandleRadar: { 21 | drawHighlightIndicators: PropTypes.bool, 22 | drawVerticalHighlightIndicator: PropTypes.bool, 23 | drawHorizontalHighlightIndicator: PropTypes.bool, 24 | highlightLineWidth: PropTypes.number 25 | }, 26 | 27 | lineRadar: { 28 | fillColor: PropTypes.string, 29 | fillAlpha: PropTypes.number, 30 | drawFilled: PropTypes.bool, 31 | lineWidth: (props, propName, componentName) => { 32 | let lineWidth = props[propName]; 33 | if (lineWidth && (typeof lineWidth !== 'number' || lineWidth < 0.2 || lineWidth > 10)) { 34 | return new Error( 35 | `Invalid prop ${propName} supplied to '${componentName}'. Value must be number and between 0.2f and 10f` 36 | ); 37 | } 38 | } 39 | } 40 | }; 41 | 42 | export default chartDataSetConfig; 43 | -------------------------------------------------------------------------------- /lib/LineChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import BarLineChartBase from './BarLineChartBase'; 8 | import ChartDataSetConfig from './ChartDataSetConfig'; 9 | 10 | const iface = { 11 | name: 'LineChart', 12 | propTypes: { 13 | ...BarLineChartBase.propTypes, 14 | 15 | data: PropTypes.shape({ 16 | datasets: PropTypes.arrayOf(PropTypes.shape({ 17 | yValues: PropTypes.arrayOf(PropTypes.number), 18 | label: PropTypes.string, 19 | config: PropTypes.shape({ 20 | ...ChartDataSetConfig.common, 21 | ...ChartDataSetConfig.barLineScatterCandleBubble, 22 | ...ChartDataSetConfig.lineScatterCandleRadar, 23 | ...ChartDataSetConfig.lineRadar, 24 | 25 | circleRadius: PropTypes.number, 26 | drawCircles: PropTypes.bool, 27 | drawCubic: PropTypes.bool, 28 | drawCubicIntensity: PropTypes.number, 29 | circleColor: PropTypes.string, 30 | circleColors: PropTypes.arrayOf(PropTypes.string), 31 | circleColorHole: PropTypes.string, 32 | drawCircleHole: PropTypes.bool, 33 | 34 | dashedLine: PropTypes.shape({ 35 | lineLength: PropTypes.number.isRequired, 36 | spaceLength: PropTypes.number.isRequired, 37 | phase: PropTypes.number, 38 | }) 39 | }) 40 | })), 41 | xValues: PropTypes.arrayOf(PropTypes.string) 42 | }) 43 | } 44 | }; 45 | 46 | export default requireNativeComponent('MPAndroidLineChart', iface); 47 | -------------------------------------------------------------------------------- /lib/PieChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import ChartBase from './ChartBase'; 8 | import ChartDataSetConfig from './ChartDataSetConfig'; 9 | 10 | const iface = { 11 | name: 'PieChart', 12 | propTypes: { 13 | ...ChartBase.propTypes, 14 | 15 | drawSliceText: PropTypes.bool, 16 | usePercentValues: PropTypes.bool, 17 | centerText: PropTypes.string, 18 | centerTextRadiusPercent: PropTypes.number, 19 | holeRadius: PropTypes.number, 20 | holeColor: PropTypes.string, 21 | transparentCircleRadius: PropTypes.number, 22 | transparentCircleColor: PropTypes.string, 23 | transparentCircleAlpha: PropTypes.number, 24 | maxAngle: PropTypes.number, 25 | 26 | // TODO PieChart should have only one dataset 27 | data: PropTypes.shape({ 28 | datasets: PropTypes.arrayOf(PropTypes.shape({ 29 | yValues: PropTypes.arrayOf(PropTypes.number), 30 | label: PropTypes.string, 31 | config: PropTypes.shape({ 32 | ...ChartDataSetConfig.common, 33 | 34 | sliceSpace: PropTypes.number, 35 | selectionShift: PropTypes.number 36 | }) 37 | })), 38 | xValues: PropTypes.arrayOf(PropTypes.string) 39 | }) 40 | } 41 | }; 42 | 43 | export default requireNativeComponent('MPAndroidPieChart', iface); 44 | -------------------------------------------------------------------------------- /lib/RadarChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import ChartBase from './ChartBase'; 8 | import {yAxisIface} from './YAxisIface'; 9 | import ChartDataSetConfig from './ChartDataSetConfig'; 10 | 11 | const iface = { 12 | name: 'RadarChart', 13 | propTypes: { 14 | ...ChartBase.propTypes, 15 | 16 | yAxis: PropTypes.shape(yAxisIface), 17 | 18 | skipWebLineCount: PropTypes.number, 19 | 20 | data: PropTypes.shape({ 21 | datasets: PropTypes.arrayOf(PropTypes.shape({ 22 | yValues: PropTypes.arrayOf(PropTypes.number), 23 | label: PropTypes.string, 24 | config: PropTypes.shape({ 25 | ...ChartDataSetConfig.common, 26 | ...ChartDataSetConfig.lineScatterCandleRadar, 27 | ...ChartDataSetConfig.lineRadar 28 | 29 | }) 30 | })), 31 | xValues: PropTypes.arrayOf(PropTypes.string) 32 | }) 33 | } 34 | }; 35 | 36 | export default requireNativeComponent('MPAndroidRadarChart', iface); 37 | -------------------------------------------------------------------------------- /lib/ScatterChart.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | requireNativeComponent, 4 | View 5 | } from 'react-native'; 6 | 7 | import BarLineChartBase from './BarLineChartBase'; 8 | import ChartDataSetConfig from './ChartDataSetConfig'; 9 | 10 | const iface = { 11 | name: 'ScatterChart', 12 | propTypes: { 13 | ...BarLineChartBase.propTypes, 14 | 15 | data: PropTypes.shape({ 16 | datasets: PropTypes.arrayOf(PropTypes.shape({ 17 | yValues: PropTypes.arrayOf(PropTypes.number), 18 | label: PropTypes.string, 19 | config: PropTypes.shape({ 20 | ...ChartDataSetConfig.common, 21 | ...ChartDataSetConfig.barLineScatterCandleBubble, 22 | ...ChartDataSetConfig.lineScatterCandleRadar, 23 | 24 | scatterShapeSize: PropTypes.number, 25 | scatterShape: PropTypes.oneOf(['SQUARE', 'CIRCLE', 'TRIANGLE', 'CROSS', 'X']), 26 | scatterShapeHoleColor: PropTypes.string, 27 | scatterShapeHoleRadius: PropTypes.number 28 | }) 29 | })), 30 | xValues: PropTypes.arrayOf(PropTypes.string) 31 | }) 32 | } 33 | }; 34 | 35 | export default requireNativeComponent('MPAndroidScatterChart', iface); 36 | -------------------------------------------------------------------------------- /lib/YAxisIface.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react'; 2 | import { 3 | View 4 | } from 'react-native'; 5 | 6 | import {axisIface} from './ChartBase'; 7 | 8 | const yAxisIface = { 9 | ...axisIface, 10 | 11 | axisMaxValue: PropTypes.number, 12 | axisMinValue: PropTypes.number, 13 | inverted: PropTypes.bool, 14 | spaceTop: PropTypes.number, 15 | spaceBottom: PropTypes.number, 16 | showOnlyMinMax: PropTypes.bool, 17 | labelCount: PropTypes.number, 18 | labelCountForce: PropTypes.bool, 19 | position: PropTypes.string, 20 | granularity: PropTypes.number, 21 | granularityEnabled: PropTypes.bool, 22 | 23 | // formatting 24 | valueFormatter: PropTypes.oneOfType([ 25 | PropTypes.oneOf(['largeValue', 'percent']), 26 | PropTypes.string 27 | ]), 28 | 29 | // zero line 30 | zeroLine: PropTypes.shape({ 31 | enabled: PropTypes.bool, 32 | lineWidth: PropTypes.number, 33 | lineColor: PropTypes.string 34 | }) 35 | }; 36 | 37 | export default yAxisIface; 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-mp-android-chart", 3 | "version": "0.2.0", 4 | "description": "React Native wrapper around MPAndroidChart chart library", 5 | "main": "index.android.js", 6 | "author": "Martin Skec", 7 | "license": "MIT", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/mskec/react-native-mp-android-chart" 11 | }, 12 | "keywords": [ 13 | "react native", 14 | "charts", 15 | "android", 16 | "MPAndroidChart" 17 | ], 18 | "files": [ 19 | "android/", 20 | "lib/", 21 | "index.android.js" 22 | ] 23 | } 24 | --------------------------------------------------------------------------------