diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000000..0a213d6792
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,12 @@
+# These are supported funding model platforms
+
+github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
+patreon: mpandroidchart
+open_collective: philippjahoda
+ko_fi: # Replace with a single Ko-fi username
+tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+liberapay: # Replace with a single Liberapay username
+issuehunt: # Replace with a single IssueHunt username
+otechie: # Replace with a single Otechie username
+custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
index 49ed0dfc1d..b75838b907 100644
--- a/.github/ISSUE_TEMPLATE.md
+++ b/.github/ISSUE_TEMPLATE.md
@@ -28,10 +28,10 @@ cannot answer support questions here. We will close your issue without a respons
**Device (please complete the following information):**
- Device: [e.g. Google Pixel]
- Android Version [e.g. 7.0]
- - Library Version (e.g. 3.0.3)
+ - Library Version (e.g. 3.1.0-alpha)
**Additional Context**
diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md
index 496d0a0d8d..3a5938eee9 100644
--- a/.github/ISSUE_TEMPLATE/Bug_report.md
+++ b/.github/ISSUE_TEMPLATE/Bug_report.md
@@ -33,10 +33,12 @@ support questions here. We will close your issue without a response.
**Device (please complete the following information):**
- Device: [e.g. Google Pixel]
- Android Version [e.g. 7.0]
- - Library Version (e.g. 3.0.3)
+ - Library Version (e.g. 3.1.0-alpha)
**Additional Context**
+
+ADD A REWARD using [Speed](speedoss.com) to SOLVE this issue QUICKLY and SUPPORT this project.
diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md
index 823b940961..54b30c983b 100644
--- a/.github/ISSUE_TEMPLATE/Feature_request.md
+++ b/.github/ISSUE_TEMPLATE/Feature_request.md
@@ -31,3 +31,4 @@ support questions here. We will close your issue without a response.
**Additional context**
+ADD A REWARD using [Speed](speedoss.com) to SOLVE this issue QUICKLY and SUPPORT this project.
diff --git a/.github/ISSUE_TEMPLATE/Support_help.md b/.github/ISSUE_TEMPLATE/Support_help.md
index 64c87763df..70a086d3d7 100644
--- a/.github/ISSUE_TEMPLATE/Support_help.md
+++ b/.github/ISSUE_TEMPLATE/Support_help.md
@@ -14,7 +14,7 @@ Instead, do the following:
1. Download the [Example App](https://play.google.com/store/apps/details?id=com.xxmassdeveloper.mpchartexample) and check out the [source code](https://github.com/PhilJay/MPAndroidChart/tree/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample). 90% of the time there is an example that does exactly what you are trying to do.
-1. Look at the [Wiki](https://github.com/PhilJay/MPAndroidChart/wiki) for the official documentation for MPAndroidChart. You can also browse the [javadoc](https://jitpack.io/com/github/PhilJay/MPAndroidChart/v3.0.3/javadoc/) for a more detailed tutorial of the API.
+1. Look at the [Wiki](https://github.com/PhilJay/MPAndroidChart/wiki) for the official documentation for MPAndroidChart. You can also browse the [javadoc](https://jitpack.io/com/github/philjay/mpandroidchart/v3.1.0-alpha/javadoc/) for a more detailed tutorial of the API.
1. Go to [StackOverflow](https://stackoverflow.com/questions/tagged/mpandroidchart) and ask your questions there. The community will be much more helpful and willing to offer guidance.
@@ -22,3 +22,6 @@ Instead, do the following:
### You have been warned!
From now on, any issues asking for help will get closed with a link to this file.
+
+### Additional Context
+ADD A REWARD using [Speed](speedoss.com) to SOLVE this issue QUICKLY and SUPPORT this project.
diff --git a/.gitignore b/.gitignore
index a340b1d6b3..feed37b27d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@ gen/
generated/
docs/
finalOutput/
+projectFilesBackup/
build.xml
diff --git a/.idea/runConfigurations/MPChartExample.xml b/.idea/runConfigurations/MPChartExample.xml
new file mode 100644
index 0000000000..e6bcf50331
--- /dev/null
+++ b/.idea/runConfigurations/MPChartExample.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs b/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs
deleted file mode 100644
index 9383f623c6..0000000000
--- a/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences
-#Mon Jan 18 23:02:46 CET 2016
-build.family.org.gradle.tooling.model.eclipse.HierarchicalEclipseProject=;MPChartExample;MPChartLib;
-org.springsource.ide.eclipse.gradle.rootprojectloc=
diff --git a/LICENSE b/LICENSE
index 8dada3edaf..c1551a9dce 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,195 +1,7 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "{}"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright {yyyy} {name of copyright owner}
+ Copyright 2020 Philipp Jahoda
Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
+ you may not use this software except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
diff --git a/MPChartExample/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs b/MPChartExample/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs
deleted file mode 100644
index be975eb2db..0000000000
--- a/MPChartExample/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs
+++ /dev/null
@@ -1,3 +0,0 @@
-#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences
-#Mon Jan 18 23:02:46 CET 2016
-org.springsource.ide.eclipse.gradle.rootprojectloc=..
diff --git a/MPChartExample/AndroidManifest.xml b/MPChartExample/AndroidManifest.xml
deleted file mode 100644
index 3fa15cd69c..0000000000
--- a/MPChartExample/AndroidManifest.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/MPChartExample/build.gradle b/MPChartExample/build.gradle
index 8e6fe137b8..2d607e9991 100644
--- a/MPChartExample/build.gradle
+++ b/MPChartExample/build.gradle
@@ -1,24 +1,14 @@
apply plugin: 'com.android.application'
-apply plugin: 'realm-android'
android {
- compileSdkVersion 27
- buildToolsVersion '27.0.3'
+ compileSdkVersion 28
defaultConfig {
+ applicationId "com.xxmassdeveloper.mpchartexample"
minSdkVersion 16
- targetSdkVersion 27
- versionCode 56
- versionName '3.0.3'
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
-
- sourceSets {
- main {
- java.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- manifest.srcFile 'AndroidManifest.xml'
- }
- }
+ targetSdkVersion 28
+ versionCode 57
+ versionName '3.1.0'
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -27,39 +17,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
-
- lintOptions {
- abortOnError false
- }
-}
-
-buildscript {
- repositories {
- jcenter()
- google()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.1.2'
- //classpath 'io.realm:realm-gradle-plugin:0.88.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
-}
-
-repositories {
- maven { url "https://jitpack.io/" }
- maven { // this is for realm-db
- url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
- }
}
dependencies {
- //compile fileTree(dir: 'libs', include: ['*.jar'])
- //compile project(':MPChartLib-Realm') // clone "https://github.com/PhilJay/MPAndroidChart-Realm" to get this or uncomment the gradle dependency below:
- implementation 'com.github.PhilJay:MPAndroidChart-Realm:v2.0.2@aar'
-
+ implementation "androidx.appcompat:appcompat:1.0.2"
+ implementation 'com.google.android.material:material:1.0.0'
implementation project(':MPChartLib')
- implementation 'com.android.support:appcompat-v7:27.1.1'
- //compile 'io.realm:realm-android:0.87.5' // dependency for realm-database API (http://realm.io)
- //compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
}
diff --git a/MPChartExample/proguard-project.txt b/MPChartExample/proguard-project.txt
deleted file mode 100644
index f2fe1559a2..0000000000
--- a/MPChartExample/proguard-project.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-# To enable ProGuard in your project, edit project.properties
-# to define the proguard.config property as described in that file.
-#
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in ${sdk.dir}/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the ProGuard
-# include property in project.properties.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/MPChartExample/proguard-rules.pro b/MPChartExample/proguard-rules.pro
new file mode 100644
index 0000000000..f1b424510d
--- /dev/null
+++ b/MPChartExample/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/MPChartExample/project.properties b/MPChartExample/project.properties
deleted file mode 100644
index b32d807be6..0000000000
--- a/MPChartExample/project.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-23
-android.library.reference.1=../MPChartLib
diff --git a/MPChartExample/res/drawable-nodpi/marker.png b/MPChartExample/res/drawable-nodpi/marker.png
deleted file mode 100644
index 616cdd7b31..0000000000
Binary files a/MPChartExample/res/drawable-nodpi/marker.png and /dev/null differ
diff --git a/MPChartExample/res/drawable/new_background.xml b/MPChartExample/res/drawable/new_background.xml
deleted file mode 100644
index c2d3b9cfc5..0000000000
--- a/MPChartExample/res/drawable/new_background.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_bubblechart_noseekbar.xml b/MPChartExample/res/layout/activity_bubblechart_noseekbar.xml
deleted file mode 100644
index 6d7a7763df..0000000000
--- a/MPChartExample/res/layout/activity_bubblechart_noseekbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_candlechart_noseekbar.xml b/MPChartExample/res/layout/activity_candlechart_noseekbar.xml
deleted file mode 100644
index 8e5d4bc26e..0000000000
--- a/MPChartExample/res/layout/activity_candlechart_noseekbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_horizontalbarchart_noseekbar.xml b/MPChartExample/res/layout/activity_horizontalbarchart_noseekbar.xml
deleted file mode 100644
index a48307987e..0000000000
--- a/MPChartExample/res/layout/activity_horizontalbarchart_noseekbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_piechart_noseekbar.xml b/MPChartExample/res/layout/activity_piechart_noseekbar.xml
deleted file mode 100644
index 52c62806b0..0000000000
--- a/MPChartExample/res/layout/activity_piechart_noseekbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_radarchart_noseekbar.xml b/MPChartExample/res/layout/activity_radarchart_noseekbar.xml
deleted file mode 100644
index d8e3b35aab..0000000000
--- a/MPChartExample/res/layout/activity_radarchart_noseekbar.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_realm_wiki.xml b/MPChartExample/res/layout/activity_realm_wiki.xml
deleted file mode 100644
index d4e27933cf..0000000000
--- a/MPChartExample/res/layout/activity_realm_wiki.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_scatterchart_noseekbar.xml b/MPChartExample/res/layout/activity_scatterchart_noseekbar.xml
deleted file mode 100644
index 548a0c7a66..0000000000
--- a/MPChartExample/res/layout/activity_scatterchart_noseekbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/menu/candle.xml b/MPChartExample/res/menu/candle.xml
deleted file mode 100644
index cdf1c4e4dd..0000000000
--- a/MPChartExample/res/menu/candle.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/menu/dynamical.xml b/MPChartExample/res/menu/dynamical.xml
deleted file mode 100644
index c43a3a0ae6..0000000000
--- a/MPChartExample/res/menu/dynamical.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/menu/pie.xml b/MPChartExample/res/menu/pie.xml
deleted file mode 100644
index 0e5323a590..0000000000
--- a/MPChartExample/res/menu/pie.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/menu/realtime.xml b/MPChartExample/res/menu/realtime.xml
deleted file mode 100644
index a4b2d22a78..0000000000
--- a/MPChartExample/res/menu/realtime.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/values-sw600dp/dimens.xml b/MPChartExample/res/values-sw600dp/dimens.xml
deleted file mode 100644
index 44f01db75f..0000000000
--- a/MPChartExample/res/values-sw600dp/dimens.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
diff --git a/MPChartExample/res/values-sw720dp-land/dimens.xml b/MPChartExample/res/values-sw720dp-land/dimens.xml
deleted file mode 100644
index 61e3fa8fbc..0000000000
--- a/MPChartExample/res/values-sw720dp-land/dimens.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
- 128dp
-
-
diff --git a/MPChartExample/res/values-v11/styles.xml b/MPChartExample/res/values-v11/styles.xml
deleted file mode 100644
index 3c02242ad0..0000000000
--- a/MPChartExample/res/values-v11/styles.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
diff --git a/MPChartExample/res/values-v14/styles.xml b/MPChartExample/res/values-v14/styles.xml
deleted file mode 100644
index a91fd0372b..0000000000
--- a/MPChartExample/res/values-v14/styles.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
diff --git a/MPChartExample/res/values/dimens.xml b/MPChartExample/res/values/dimens.xml
deleted file mode 100644
index 55c1e5908c..0000000000
--- a/MPChartExample/res/values/dimens.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
- 16dp
- 16dp
-
-
diff --git a/MPChartExample/res/values/strings.xml b/MPChartExample/res/values/strings.xml
deleted file mode 100644
index 7f59af64bb..0000000000
--- a/MPChartExample/res/values/strings.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
- MPAndroidChart Example
- Settings
- Hello world!
-
-
diff --git a/MPChartExample/res/values/styles.xml b/MPChartExample/res/values/styles.xml
deleted file mode 100644
index 6ce89c7ba4..0000000000
--- a/MPChartExample/res/values/styles.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
deleted file mode 100644
index f6cffddcbe..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
+++ /dev/null
@@ -1,200 +0,0 @@
-
-package com.xxmassdeveloper.mpchartexample;
-
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.WindowManager;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.github.mikephil.charting.charts.BarChart;
-import com.github.mikephil.charting.components.XAxis;
-import com.github.mikephil.charting.components.XAxis.XAxisPosition;
-import com.github.mikephil.charting.data.BarData;
-import com.github.mikephil.charting.data.BarDataSet;
-import com.github.mikephil.charting.data.BarEntry;
-import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
-import com.github.mikephil.charting.interfaces.datasets.IDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-
-import java.util.ArrayList;
-
-public class AnotherBarActivity extends DemoBase implements OnSeekBarChangeListener {
-
- private BarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
- private TextView tvX, tvY;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_barchart);
-
- tvX = findViewById(R.id.tvXMax);
- tvY = findViewById(R.id.tvYMax);
-
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
-
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
-
- mChart = findViewById(R.id.chart1);
-
- mChart.getDescription().setEnabled(false);
-
- // if more than 60 entries are displayed in the chart, no values will be
- // drawn
- mChart.setMaxVisibleValueCount(60);
-
- // scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
-
- mChart.setDrawBarShadow(false);
- mChart.setDrawGridBackground(false);
-
- XAxis xAxis = mChart.getXAxis();
- xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setDrawGridLines(false);
-
- mChart.getAxisLeft().setDrawGridLines(false);
-
- // setting data
- mSeekBarX.setProgress(10);
- mSeekBarY.setProgress(100);
-
- // add a nice and smooth animation
- mChart.animateY(2500);
-
- mChart.getLegend().setEnabled(false);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.bar, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
-
- switch (item.getItemId()) {
- case R.id.actionToggleValues: {
-
- for (IDataSet set : mChart.getData().getDataSets())
- set.setDrawValues(!set.isDrawValuesEnabled());
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleHighlight: {
-
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
- }
- break;
- }
- case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
- else
- mChart.setPinchZoom(true);
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
- break;
- }
- case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
- ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
-
- mChart.invalidate();
- break;
- }
- case R.id.animateX: {
- mChart.animateX(3000);
- break;
- }
- case R.id.animateY: {
- mChart.animateY(3000);
- break;
- }
- case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
- break;
- }
- case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
- break;
- }
- }
- return true;
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
- float mult = (mSeekBarY.getProgress() + 1);
- float val = (float) (Math.random() * mult) + mult / 3;
- yVals1.add(new BarEntry(i, val));
- }
-
- BarDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals1);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set1 = new BarDataSet(yVals1, "Data Set");
- set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
- set1.setDrawValues(false);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1);
-
- BarData data = new BarData(dataSets);
- mChart.setData(data);
- mChart.setFitBars(true);
- }
-
- mChart.invalidate();
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
deleted file mode 100644
index 85d213e351..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
+++ /dev/null
@@ -1,464 +0,0 @@
-
-package com.xxmassdeveloper.mpchartexample;
-
-import android.graphics.Color;
-import android.graphics.DashPathEffect;
-import android.graphics.Typeface;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.support.v4.content.ContextCompat;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.WindowManager;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.LineChart;
-import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendForm;
-import com.github.mikephil.charting.components.LimitLine;
-import com.github.mikephil.charting.components.LimitLine.LimitLabelPosition;
-import com.github.mikephil.charting.components.XAxis;
-import com.github.mikephil.charting.components.YAxis;
-import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.data.LineData;
-import com.github.mikephil.charting.data.LineDataSet;
-import com.github.mikephil.charting.highlight.Highlight;
-import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
-import com.github.mikephil.charting.listener.ChartTouchListener;
-import com.github.mikephil.charting.listener.OnChartGestureListener;
-import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
-import com.github.mikephil.charting.utils.Utils;
-import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListener,
- OnChartGestureListener, OnChartValueSelectedListener {
-
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
- private TextView tvX, tvY;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_linechart);
-
- tvX = findViewById(R.id.tvXMax);
- tvY = findViewById(R.id.tvYMax);
-
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
-
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
-
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
-
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartGestureListener(this);
- mChart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
-
- // no description text
- mChart.getDescription().setEnabled(false);
-
- // enable touch gestures
- mChart.setTouchEnabled(true);
-
- // enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
- // mChart.setScaleXEnabled(true);
- // mChart.setScaleYEnabled(true);
-
- // if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(true);
-
- // set an alternative background color
- // mChart.setBackgroundColor(Color.GRAY);
-
- // create a custom MarkerView (extend MarkerView) and specify the layout
- // to use for it
- MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
-
- // x-axis limit line
- LimitLine llXAxis = new LimitLine(10f, "Index 10");
- llXAxis.setLineWidth(4f);
- llXAxis.enableDashedLine(10f, 10f, 0f);
- llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
- llXAxis.setTextSize(10f);
-
- XAxis xAxis = mChart.getXAxis();
- xAxis.enableGridDashedLine(10f, 10f, 0f);
- //xAxis.setValueFormatter(new MyCustomXAxisValueFormatter());
- //xAxis.addLimitLine(llXAxis); // add x-axis limit line
-
-
- Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
-
- LimitLine ll1 = new LimitLine(150f, "Upper Limit");
- ll1.setLineWidth(4f);
- ll1.enableDashedLine(10f, 10f, 0f);
- ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
- ll1.setTextSize(10f);
- ll1.setTypeface(tf);
-
- LimitLine ll2 = new LimitLine(-30f, "Lower Limit");
- ll2.setLineWidth(4f);
- ll2.enableDashedLine(10f, 10f, 0f);
- ll2.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
- ll2.setTextSize(10f);
- ll2.setTypeface(tf);
-
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
- leftAxis.addLimitLine(ll1);
- leftAxis.addLimitLine(ll2);
- leftAxis.setAxisMaximum(200f);
- leftAxis.setAxisMinimum(-50f);
- //leftAxis.setYOffset(20f);
- leftAxis.enableGridDashedLine(10f, 10f, 0f);
- leftAxis.setDrawZeroLine(false);
-
- // limit lines are drawn behind data (and not on top)
- leftAxis.setDrawLimitLinesBehindData(true);
-
- mChart.getAxisRight().setEnabled(false);
-
- //mChart.getViewPortHandler().setMaximumScaleY(2f);
- //mChart.getViewPortHandler().setMaximumScaleX(2f);
-
- // add data
- setData(45, 100);
-
-// mChart.setVisibleXRange(20);
-// mChart.setVisibleYRange(20f, AxisDependency.LEFT);
-// mChart.centerViewTo(20, 50, AxisDependency.LEFT);
-
- mChart.animateX(2500);
- //mChart.invalidate();
-
- // get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
-
- // modify the legend ...
- l.setForm(LegendForm.LINE);
-
- // // dont forget to refresh the drawing
- // mChart.invalidate();
- }
-
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- super.onWindowFocusChanged(hasFocus);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.line, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
-
- switch (item.getItemId()) {
- case R.id.actionToggleValues: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- set.setDrawValues(!set.isDrawValuesEnabled());
- }
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleIcons: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- set.setDrawIcons(!set.isDrawIconsEnabled());
- }
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
- }
- break;
- }
- case R.id.actionToggleFilled: {
-
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- if (set.isDrawFilledEnabled())
- set.setDrawFilled(false);
- else
- set.setDrawFilled(true);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleCircles: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- if (set.isDrawCirclesEnabled())
- set.setDrawCircles(false);
- else
- set.setDrawCircles(true);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleCubic: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER
- ? LineDataSet.Mode.LINEAR
- : LineDataSet.Mode.CUBIC_BEZIER);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleStepped: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- set.setMode(set.getMode() == LineDataSet.Mode.STEPPED
- ? LineDataSet.Mode.LINEAR
- : LineDataSet.Mode.STEPPED);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleHorizontalCubic: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER
- ? LineDataSet.Mode.LINEAR
- : LineDataSet.Mode.HORIZONTAL_BEZIER);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
- else
- mChart.setPinchZoom(true);
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
- break;
- }
- case R.id.animateX: {
- mChart.animateX(3000);
- break;
- }
- case R.id.animateY: {
- mChart.animateY(3000, Easing.EaseInCubic);
- break;
- }
- case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
- break;
- }
- case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
- break;
- }
- }
- return true;
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
-
- // redraw
- mChart.invalidate();
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList values = new ArrayList();
-
- for (int i = 0; i < count; i++) {
-
- float val = (float) (Math.random() * range) + 3;
- values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
- }
-
- LineDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(values);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- // create a dataset and give it a type
- set1 = new LineDataSet(values, "DataSet 1");
-
- set1.setDrawIcons(false);
-
- // set the line to be drawn like this "- - - - - -"
- set1.enableDashedLine(10f, 5f, 0f);
- set1.enableDashedHighlightLine(10f, 5f, 0f);
- set1.setColor(Color.BLACK);
- set1.setCircleColor(Color.BLACK);
- set1.setLineWidth(1f);
- set1.setCircleRadius(3f);
- set1.setDrawCircleHole(false);
- set1.setValueTextSize(9f);
- set1.setDrawFilled(true);
- set1.setFormLineWidth(1f);
- set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
- set1.setFormSize(15.f);
-
- if (Utils.getSDKInt() >= 18) {
- // fill drawable only supported on api level 18 and above
- Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
- set1.setFillDrawable(drawable);
- }
- else {
- set1.setFillColor(Color.BLACK);
- }
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1); // add the datasets
-
- // create a data object with the datasets
- LineData data = new LineData(dataSets);
-
- // set data
- mChart.setData(data);
- }
- }
-
- @Override
- public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
- Log.i("Gesture", "START, x: " + me.getX() + ", y: " + me.getY());
- }
-
- @Override
- public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
- Log.i("Gesture", "END, lastGesture: " + lastPerformedGesture);
-
- // un-highlight values after the gesture is finished and no single-tap
- if(lastPerformedGesture != ChartTouchListener.ChartGesture.SINGLE_TAP)
- mChart.highlightValues(null); // or highlightTouch(null) for callback to onNothingSelected(...)
- }
-
- @Override
- public void onChartLongPressed(MotionEvent me) {
- Log.i("LongPress", "Chart longpressed.");
- }
-
- @Override
- public void onChartDoubleTapped(MotionEvent me) {
- Log.i("DoubleTap", "Chart double-tapped.");
- }
-
- @Override
- public void onChartSingleTapped(MotionEvent me) {
- Log.i("SingleTap", "Chart single-tapped.");
- }
-
- @Override
- public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
- Log.i("Fling", "Chart flinged. VeloX: " + velocityX + ", VeloY: " + velocityY);
- }
-
- @Override
- public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
- Log.i("Scale / Zoom", "ScaleX: " + scaleX + ", ScaleY: " + scaleY);
- }
-
- @Override
- public void onChartTranslate(MotionEvent me, float dX, float dY) {
- Log.i("Translate / Move", "dX: " + dX + ", dY: " + dY);
- }
-
- @Override
- public void onValueSelected(Entry e, Highlight h) {
- Log.i("Entry selected", e.toString());
- Log.i("LOWHIGH", "low: " + mChart.getLowestVisibleX() + ", high: " + mChart.getHighestVisibleX());
- Log.i("MIN MAX", "xmin: " + mChart.getXChartMin() + ", xmax: " + mChart.getXChartMax() + ", ymin: " + mChart.getYChartMin() + ", ymax: " + mChart.getYChartMax());
- }
-
- @Override
- public void onNothingSelected() {
- Log.i("Nothing selected", "Nothing selected.");
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java
deleted file mode 100644
index e6acf01670..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java
+++ /dev/null
@@ -1,245 +0,0 @@
-
-package com.xxmassdeveloper.mpchartexample;
-
-import android.os.Bundle;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.WindowManager;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-
-import com.github.mikephil.charting.charts.LineChart;
-import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
-import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.data.LineData;
-import com.github.mikephil.charting.data.LineDataSet;
-import com.github.mikephil.charting.highlight.Highlight;
-import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
-import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
- OnChartValueSelectedListener {
-
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
- private TextView tvX, tvY;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_linechart);
-
- tvX = findViewById(R.id.tvXMax);
- tvY = findViewById(R.id.tvYMax);
-
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
-
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
-
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
-
- mChart.setDrawGridBackground(false);
- mChart.getDescription().setEnabled(false);
- mChart.setDrawBorders(false);
-
- mChart.getAxisLeft().setEnabled(false);
- mChart.getAxisRight().setDrawAxisLine(false);
- mChart.getAxisRight().setDrawGridLines(false);
- mChart.getXAxis().setDrawAxisLine(false);
- mChart.getXAxis().setDrawGridLines(false);
-
- // enable touch gestures
- mChart.setTouchEnabled(true);
-
- // enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
-
- // if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
-
- mSeekBarX.setProgress(20);
- mSeekBarY.setProgress(100);
-
- Legend l = mChart.getLegend();
- l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
- l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
- l.setOrientation(Legend.LegendOrientation.VERTICAL);
- l.setDrawInside(false);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.line, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
-
- switch (item.getItemId()) {
- case R.id.actionToggleValues: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- set.setDrawValues(!set.isDrawValuesEnabled());
- }
-
- mChart.invalidate();
- break;
- }
- case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
- else
- mChart.setPinchZoom(true);
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
- break;
- }
- case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
- }
- break;
- }
- case R.id.actionToggleFilled: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- if (set.isDrawFilledEnabled())
- set.setDrawFilled(false);
- else
- set.setDrawFilled(true);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleCircles: {
- List sets = mChart.getData()
- .getDataSets();
-
- for (ILineDataSet iSet : sets) {
-
- LineDataSet set = (LineDataSet) iSet;
- if (set.isDrawCirclesEnabled())
- set.setDrawCircles(false);
- else
- set.setDrawCircles(true);
- }
- mChart.invalidate();
- break;
- }
- case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
- break;
- }
- case R.id.animateX: {
- mChart.animateX(3000);
- break;
- }
- case R.id.animateY: {
- mChart.animateY(3000);
- break;
- }
- case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
- break;
- }
- }
- return true;
- }
-
- private int[] mColors = new int[] {
- ColorTemplate.VORDIPLOM_COLORS[0],
- ColorTemplate.VORDIPLOM_COLORS[1],
- ColorTemplate.VORDIPLOM_COLORS[2]
- };
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- mChart.resetTracking();
-
- tvX.setText("" + (mSeekBarX.getProgress()));
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- ArrayList dataSets = new ArrayList();
-
- for (int z = 0; z < 3; z++) {
-
- ArrayList values = new ArrayList();
-
- for (int i = 0; i < mSeekBarX.getProgress(); i++) {
- double val = (Math.random() * mSeekBarY.getProgress()) + 3;
- values.add(new Entry(i, (float) val));
- }
-
- LineDataSet d = new LineDataSet(values, "DataSet " + (z + 1));
- d.setLineWidth(2.5f);
- d.setCircleRadius(4f);
-
- int color = mColors[z % mColors.length];
- d.setColor(color);
- d.setCircleColor(color);
- dataSets.add(d);
- }
-
- // make the first DataSet dashed
- ((LineDataSet) dataSets.get(0)).enableDashedLine(10, 10, 0);
- ((LineDataSet) dataSets.get(0)).setColors(ColorTemplate.VORDIPLOM_COLORS);
- ((LineDataSet) dataSets.get(0)).setCircleColors(ColorTemplate.VORDIPLOM_COLORS);
-
- LineData data = new LineData(dataSets);
- mChart.setData(data);
- mChart.invalidate();
- }
-
- @Override
- public void onValueSelected(Entry e, Highlight h) {
- Log.i("VAL SELECTED",
- "Value: " + e.getY() + ", xIndex: " + e.getX()
- + ", DataSet index: " + h.getDataSetIndex());
- }
-
- @Override
- public void onNothingSelected() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java
deleted file mode 100644
index a2d4becadc..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java
+++ /dev/null
@@ -1,124 +0,0 @@
-
-package com.xxmassdeveloper.mpchartexample;
-
-import android.graphics.Color;
-import android.os.Bundle;
-import android.view.WindowManager;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-
-import com.github.mikephil.charting.charts.LineChart;
-import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.data.LineData;
-import com.github.mikephil.charting.data.LineDataSet;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-
-import java.util.ArrayList;
-
-public class PerformanceLineChart extends DemoBase implements OnSeekBarChangeListener {
-
- private LineChart mChart;
- private SeekBar mSeekBarValues;
- private TextView mTvCount;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_performance_linechart);
-
- mTvCount = findViewById(R.id.tvValueCount);
- mSeekBarValues = findViewById(R.id.seekbarValues);
- mTvCount.setText("500");
-
- mSeekBarValues.setProgress(500);
-
- mSeekBarValues.setOnSeekBarChangeListener(this);
-
- mChart = findViewById(R.id.chart1);
- mChart.setDrawGridBackground(false);
-
- // no description text
- mChart.getDescription().setEnabled(false);
-
- // enable touch gestures
- mChart.setTouchEnabled(true);
-
- // enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
-
- // if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
-
- mChart.getAxisLeft().setDrawGridLines(false);
- mChart.getAxisRight().setEnabled(false);
- mChart.getXAxis().setDrawGridLines(true);
- mChart.getXAxis().setDrawAxisLine(false);
-
- // dont forget to refresh the drawing
- mChart.invalidate();
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- int count = mSeekBarValues.getProgress() + 1000;
- mTvCount.setText("" + count);
-
- mChart.resetTracking();
-
- setData(count, 500f);
-
- // redraw
- mChart.invalidate();
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList yVals = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = (range + 1);
- float val = (float) (Math.random() * mult) + 3;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals.add(new Entry(i * 0.001f, val));
- }
-
- // create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
-
- set1.setColor(Color.BLACK);
- set1.setLineWidth(0.5f);
- set1.setDrawValues(false);
- set1.setDrawCircles(false);
- set1.setMode(LineDataSet.Mode.LINEAR);
- set1.setDrawFilled(false);
-
- // create a data object with the datasets
- LineData data = new LineData(set1);
-
- // set data
- mChart.setData(data);
-
- // get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
- l.setEnabled(false);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java
deleted file mode 100644
index 1aeb7f0f0c..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java
+++ /dev/null
@@ -1,70 +0,0 @@
-
-package com.xxmassdeveloper.mpchartexample;
-
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.charts.BarChart;
-import com.github.mikephil.charting.components.XAxis;
-import com.github.mikephil.charting.components.XAxis.XAxisPosition;
-import com.github.mikephil.charting.data.BarData;
-import com.github.mikephil.charting.data.BarDataSet;
-import com.github.mikephil.charting.data.BarEntry;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-
-import java.util.ArrayList;
-
-public class ScrollViewActivity extends DemoBase {
-
- private BarChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_scrollview);
-
- mChart = findViewById(R.id.chart1);
-
- mChart.getDescription().setEnabled(false);
-
- // scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
-
- mChart.setDrawBarShadow(false);
- mChart.setDrawGridBackground(false);
-
- XAxis xAxis = mChart.getXAxis();
- xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setDrawGridLines(false);
-
- mChart.getAxisLeft().setDrawGridLines(false);
-
- mChart.getLegend().setEnabled(false);
-
- setData(10);
- mChart.setFitBars(true);
- }
-
- private void setData(int count) {
-
- ArrayList yVals = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * count) + 15;
- yVals.add(new BarEntry(i, (int) val));
- }
-
- BarDataSet set = new BarDataSet(yVals, "Data Set");
- set.setColors(ColorTemplate.VORDIPLOM_COLORS);
- set.setDrawValues(false);
-
- BarData data = new BarData(set);
-
- mChart.setData(data);
- mChart.invalidate();
- mChart.animateY(800);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RealmDemoData.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RealmDemoData.java
deleted file mode 100644
index 7becc88c90..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RealmDemoData.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.custom;
-
-
-import io.realm.RealmList;
-import io.realm.RealmObject;
-
-/**
- * Demo class that encapsulates data stored in realm.io database.
- * This class represents data suitable for all chart-types.
- */
-public class RealmDemoData extends RealmObject {
-
- private float yValue;
- private float xValue;
-
- private float open, close, high, low;
-
- private float bubbleSize;
-
- private RealmList stackValues;
-
- private String someStringField;
-
- /**
- * label for pie entries
- */
- private String label;
-
- // ofc there could me more fields here...
-
- public RealmDemoData() {
-
- }
-
- public RealmDemoData(float yValue) {
- this.yValue = yValue;
- }
-
- public RealmDemoData(float xValue, float yValue) {
- this.xValue = xValue;
- this.yValue = yValue;
- }
-
- /**
- * Constructor for stacked bars.
- *
- * @param xValue
- * @param stackValues
- */
- public RealmDemoData(float xValue, float[] stackValues) {
- this.xValue = xValue;
- this.stackValues = new RealmList();
-
- for (float val : stackValues) {
- this.stackValues.add(new RealmFloat(val));
- }
- }
-
- /**
- * Constructor for candles.
- *
- * @param xValue
- * @param high
- * @param low
- * @param open
- * @param close
- */
- public RealmDemoData(float xValue, float high, float low, float open, float close) {
- this.yValue = (high + low) / 2f;
- this.high = high;
- this.low = low;
- this.open = open;
- this.close = close;
- this.xValue = xValue;
- }
-
- /**
- * Constructor for bubbles.
- *
- * @param xValue
- * @param yValue
- * @param bubbleSize
- */
- public RealmDemoData(float xValue, float yValue, float bubbleSize) {
- this.xValue = xValue;
- this.yValue = yValue;
- this.bubbleSize = bubbleSize;
- }
-
- /**
- * Constructor for pie chart.
- *
- * @param yValue
- * @param label
- */
- public RealmDemoData(float yValue, String label) {
- this.yValue = yValue;
- this.label = label;
- }
-
- public float getyValue() {
- return yValue;
- }
-
- public void setyValue(float yValue) {
- this.yValue = yValue;
- }
-
- public float getxValue() {
- return xValue;
- }
-
- public void setxValue(float xValue) {
- this.xValue = xValue;
- }
-
- public RealmList getStackValues() {
- return stackValues;
- }
-
- public void setStackValues(RealmList stackValues) {
- this.stackValues = stackValues;
- }
-
- public float getOpen() {
- return open;
- }
-
- public void setOpen(float open) {
- this.open = open;
- }
-
- public float getClose() {
- return close;
- }
-
- public void setClose(float close) {
- this.close = close;
- }
-
- public float getHigh() {
- return high;
- }
-
- public void setHigh(float high) {
- this.high = high;
- }
-
- public float getLow() {
- return low;
- }
-
- public void setLow(float low) {
- this.low = low;
- }
-
- public float getBubbleSize() {
- return bubbleSize;
- }
-
- public void setBubbleSize(float bubbleSize) {
- this.bubbleSize = bubbleSize;
- }
-
- public String getSomeStringField() {
- return someStringField;
- }
-
- public void setSomeStringField(String someStringField) {
- this.someStringField = someStringField;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-}
\ No newline at end of file
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RealmFloat.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RealmFloat.java
deleted file mode 100644
index 15b027b3ff..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RealmFloat.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.custom;
-
-import io.realm.RealmObject;
-
-/**
- * Created by Philipp Jahoda on 09/11/15.
- */
-public class RealmFloat extends RealmObject {
-
- private float floatValue;
-
- public RealmFloat() {
-
- }
-
- public RealmFloat(float floatValue) {
- this.floatValue = floatValue;
- }
-
- public float getFloatValue() {
- return floatValue;
- }
-
- public void setFloatValue(float value) {
- this.floatValue = value;
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/ContentItem.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/ContentItem.java
deleted file mode 100644
index 97bb230ec9..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/ContentItem.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.notimportant;
-
-/**
- * Created by Philipp Jahoda on 07/12/15.
- */
-public class ContentItem {
-
- String name;
- String desc;
- boolean isNew = false;
-
- public ContentItem(String n, String d) {
- name = n;
- desc = d;
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/DemoBase.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/DemoBase.java
deleted file mode 100644
index 59b73b1ad7..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/DemoBase.java
+++ /dev/null
@@ -1,50 +0,0 @@
-
-package com.xxmassdeveloper.mpchartexample.notimportant;
-
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.renderscript.Type;
-import android.support.annotation.Nullable;
-import android.support.v4.app.FragmentActivity;
-
-import com.xxmassdeveloper.mpchartexample.R;
-
-/**
- * Baseclass of all Activities of the Demo Application.
- *
- * @author Philipp Jahoda
- */
-public abstract class DemoBase extends FragmentActivity {
-
- protected String[] mMonths = new String[] {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"
- };
-
- protected String[] mParties = new String[] {
- "Party A", "Party B", "Party C", "Party D", "Party E", "Party F", "Party G", "Party H",
- "Party I", "Party J", "Party K", "Party L", "Party M", "Party N", "Party O", "Party P",
- "Party Q", "Party R", "Party S", "Party T", "Party U", "Party V", "Party W", "Party X",
- "Party Y", "Party Z"
- };
-
- protected Typeface mTfRegular;
- protected Typeface mTfLight;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mTfRegular = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
- mTfLight = Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf");
- }
-
- protected float getRandom(float range, float startsfrom) {
- return (float) (Math.random() * range) + startsfrom;
- }
-
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- overridePendingTransition(R.anim.move_left_in_activity, R.anim.move_right_out_activity);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/MyAdapter.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/MyAdapter.java
deleted file mode 100644
index 5b424e88a5..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/MyAdapter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.notimportant;
-
-import android.content.Context;
-import android.graphics.Typeface;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
-
-import com.xxmassdeveloper.mpchartexample.R;
-
-import java.util.List;
-
-/**
- * Created by Philipp Jahoda on 07/12/15.
- */
-public class MyAdapter extends ArrayAdapter {
-
- private Typeface mTypeFaceLight;
- private Typeface mTypeFaceRegular;
-
- public MyAdapter(Context context, List objects) {
- super(context, 0, objects);
-
- mTypeFaceLight = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
- mTypeFaceRegular = Typeface.createFromAsset(context.getAssets(), "OpenSans-Regular.ttf");
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
-
- ContentItem c = getItem(position);
-
- ViewHolder holder = null;
-
- if (convertView == null) {
-
- holder = new ViewHolder();
-
- convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
- holder.tvName = convertView.findViewById(R.id.tvName);
- holder.tvDesc = convertView.findViewById(R.id.tvDesc);
- holder.tvNew = convertView.findViewById(R.id.tvNew);
-
- convertView.setTag(holder);
-
- } else {
- holder = (ViewHolder) convertView.getTag();
- }
-
- holder.tvNew.setTypeface(mTypeFaceRegular);
- holder.tvName.setTypeface(mTypeFaceLight);
- holder.tvDesc.setTypeface(mTypeFaceLight);
-
- holder.tvName.setText(c.name);
- holder.tvDesc.setText(c.desc);
-
- if(c.isNew)
- holder.tvNew.setVisibility(View.VISIBLE);
- else
- holder.tvNew.setVisibility(View.GONE);
-
- return convertView;
- }
-
- private class ViewHolder {
-
- TextView tvName, tvDesc;
- TextView tvNew;
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmBaseActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmBaseActivity.java
deleted file mode 100644
index 9b98f00f92..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmBaseActivity.java
+++ /dev/null
@@ -1,202 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.graphics.Color;
-import android.graphics.Typeface;
-import android.os.Bundle;
-
-import com.github.mikephil.charting.charts.BarLineChartBase;
-import com.github.mikephil.charting.charts.Chart;
-import com.github.mikephil.charting.components.XAxis;
-import com.github.mikephil.charting.components.YAxis;
-import com.github.mikephil.charting.data.ChartData;
-import com.github.mikephil.charting.formatter.PercentFormatter;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-
-import io.realm.Realm;
-import io.realm.RealmConfiguration;
-
-/**
- * Created by Philipp Jahoda on 05/11/15.
- */
-public abstract class RealmBaseActivity extends DemoBase {
-
- protected Realm mRealm;
-
- protected Typeface mTf;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setTitle("Realm.io Examples");
- }
-
- protected void setup(Chart> chart) {
-
- mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
-
- // no description text
- chart.getDescription().setEnabled(false);
-
- // enable touch gestures
- chart.setTouchEnabled(true);
-
- if (chart instanceof BarLineChartBase) {
-
- BarLineChartBase mChart = (BarLineChartBase) chart;
-
- mChart.setDrawGridBackground(false);
-
- // enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
-
- // if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
-
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
- leftAxis.setTypeface(mTf);
- leftAxis.setTextSize(8f);
- leftAxis.setTextColor(Color.DKGRAY);
- leftAxis.setValueFormatter(new PercentFormatter());
-
- XAxis xAxis = mChart.getXAxis();
- xAxis.setTypeface(mTf);
- xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
- xAxis.setTextSize(8f);
- xAxis.setTextColor(Color.DKGRAY);
-
- mChart.getAxisRight().setEnabled(false);
- }
- }
-
- protected void styleData(ChartData data) {
- data.setValueTypeface(mTf);
- data.setValueTextSize(8f);
- data.setValueTextColor(Color.DKGRAY);
- data.setValueFormatter(new PercentFormatter());
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- // Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
- RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
- Realm.setDefaultConfiguration(realmConfig);
-
- mRealm = Realm.getDefaultInstance();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mRealm.close();
- }
-
- protected void writeToDB(int objectCount) {
-
- mRealm.beginTransaction();
-
- mRealm.delete(RealmDemoData.class);
-
- for (int i = 0; i < objectCount; i++) {
-
- float value = 40f + (float) (Math.random() * 60f);
-
- RealmDemoData d = new RealmDemoData(i, value);
- mRealm.copyToRealm(d);
- }
-
- mRealm.commitTransaction();
- }
-
- protected void writeToDBStack(int objectCount) {
-
- mRealm.beginTransaction();
-
- mRealm.delete(RealmDemoData.class);
-
- for (int i = 0; i < objectCount; i++) {
-
- float val1 = 34f + (float) (Math.random() * 12.0f);
- float val2 = 34f + (float) (Math.random() * 12.0f);
- float[] stack = new float[]{val1, val2, 100 - val1 - val2};
-
- RealmDemoData d = new RealmDemoData(i, stack);
- mRealm.copyToRealm(d);
- }
-
- mRealm.commitTransaction();
- }
-
- protected void writeToDBCandle(int objectCount) {
-
- mRealm.beginTransaction();
-
- mRealm.delete(RealmDemoData.class);
-
- for (int i = 0; i < objectCount; i++) {
-
- float mult = 50;
- float val = (float) (Math.random() * 40) + mult;
-
- float high = (float) (Math.random() * 9) + 8f;
- float low = (float) (Math.random() * 9) + 8f;
-
- float open = (float) (Math.random() * 6) + 1f;
- float close = (float) (Math.random() * 6) + 1f;
-
- boolean even = i % 2 == 0;
-
- RealmDemoData d = new RealmDemoData(i, val + high, val - low, even ? val + open : val - open,
- even ? val - close : val + close);
-
- mRealm.copyToRealm(d);
- }
-
- mRealm.commitTransaction();
- }
-
- protected void writeToDBBubble(int objectCount) {
-
- mRealm.beginTransaction();
-
- mRealm.delete(RealmDemoData.class);
-
- for (int i = 0; i < objectCount; i++) {
-
- float value = 30f + (float) (Math.random() * 100.0);
- float size = 15f + (float) (Math.random() * 20.0);
-
- RealmDemoData d = new RealmDemoData(i, value, size);
- mRealm.copyToRealm(d);
- }
-
- mRealm.commitTransaction();
- }
-
- protected void writeToDBPie() {
-
- mRealm.beginTransaction();
-
- mRealm.delete(RealmDemoData.class);
-
- float value1 = 15f + (float) (Math.random() * 8f);
- float value2 = 15f + (float) (Math.random() * 8f);
- float value3 = 15f + (float) (Math.random() * 8f);
- float value4 = 15f + (float) (Math.random() * 8f);
- float value5 = 100f - value1 - value2 - value3 - value4;
-
- float[] values = new float[]{value1, value2, value3, value4, value5};
- String[] labels = new String[]{"iOS", "Android", "WP 10", "BlackBerry", "Other"};
-
- for (int i = 0; i < values.length; i++) {
- RealmDemoData d = new RealmDemoData(values[i], labels[i]);
- mRealm.copyToRealm(d);
- }
-
- mRealm.commitTransaction();
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBar.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBar.java
deleted file mode 100644
index 1e5d5cb8d5..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBar.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.BarChart;
-import com.github.mikephil.charting.data.BarData;
-import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
-import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityBar extends RealmBaseActivity {
-
- private BarChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_barchart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDB(20);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- //RealmBarDataSet set = new RealmBarDataSet(result, "stackValues", "xIndex"); // normal entries
- RealmBarDataSet set = new RealmBarDataSet(result, "xValue", "yValue"); // stacked entries
- set.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
- set.setLabel("Realm BarDataSet");
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- BarData data = new BarData(dataSets);
- styleData(data);
-
- // set data
- mChart.setData(data);
- mChart.setFitBars(true);
- mChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBubble.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBubble.java
deleted file mode 100644
index ad65a3de18..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBubble.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.BubbleChart;
-import com.github.mikephil.charting.data.BubbleData;
-import com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet;
-import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityBubble extends RealmBaseActivity {
-
- private BubbleChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_bubblechart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.getXAxis().setDrawGridLines(false);
- mChart.getAxisLeft().setDrawGridLines(false);
- mChart.setPinchZoom(true);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDBBubble(10);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- RealmBubbleDataSet set = new RealmBubbleDataSet(result, "xValue", "yValue", "bubbleSize");
- set.setLabel("Realm BubbleDataSet");
- set.setColors(ColorTemplate.COLORFUL_COLORS, 110);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- BubbleData data = new BubbleData(dataSets);
- styleData(data);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityCandle.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityCandle.java
deleted file mode 100644
index 96fbade855..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityCandle.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.CandleStickChart;
-import com.github.mikephil.charting.data.CandleData;
-import com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet;
-import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityCandle extends RealmBaseActivity {
-
- private CandleStickChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_candlechart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.getAxisLeft().setDrawGridLines(false);
- mChart.getXAxis().setDrawGridLines(false);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDBCandle(50);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- RealmCandleDataSet set = new RealmCandleDataSet(result, "xValue", "high", "low", "open", "close");
- set.setLabel("Realm CandleDataSet");
- set.setShadowColor(Color.DKGRAY);
- set.setShadowWidth(0.7f);
- set.setDecreasingColor(Color.RED);
- set.setDecreasingPaintStyle(Paint.Style.FILL);
- set.setIncreasingColor(Color.rgb(122, 242, 84));
- set.setIncreasingPaintStyle(Paint.Style.STROKE);
- set.setNeutralColor(Color.BLUE);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- CandleData data = new CandleData(dataSets);
- styleData(data);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityHorizontalBar.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityHorizontalBar.java
deleted file mode 100644
index b5e3345134..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityHorizontalBar.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.graphics.Color;
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.HorizontalBarChart;
-import com.github.mikephil.charting.data.BarData;
-import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
-import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityHorizontalBar extends RealmBaseActivity {
-
- private HorizontalBarChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_horizontalbarchart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.getAxisLeft().setAxisMinimum(0f);
- mChart.setDrawValueAboveBar(false);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDBStack(50);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- //RealmBarDataSet set = new RealmBarDataSet(result, "stackValues", "xIndex"); // normal entries
- RealmBarDataSet set = new RealmBarDataSet(result, "xValue", "stackValues", "floatValue"); // stacked entries
- set.setColors(new int[]{ColorTemplate.rgb("#8BC34A"), ColorTemplate.rgb("#FFC107"), ColorTemplate.rgb("#9E9E9E")});
- set.setLabel("Mobile OS distribution");
- set.setStackLabels(new String[]{"iOS", "Android", "Other"});
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- BarData data = new BarData(dataSets);
- styleData(data);
- data.setValueTextColor(Color.WHITE);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityLine.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityLine.java
deleted file mode 100644
index 7d2e49fdff..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityLine.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.LineChart;
-import com.github.mikephil.charting.data.LineData;
-import com.github.mikephil.charting.data.LineDataSet;
-import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
-import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityLine extends RealmBaseActivity {
-
- private LineChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_linechart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.getAxisLeft().setAxisMaximum(150f);
- mChart.getAxisLeft().setAxisMinimum(0f);
- mChart.getAxisLeft().setDrawGridLines(false);
- mChart.getXAxis().setDrawGridLines(false);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDB(40);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- RealmLineDataSet set = new RealmLineDataSet(result, "xValue", "yValue");
- set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
- set.setLabel("Realm LineDataSet");
- set.setDrawCircleHole(false);
- set.setColor(ColorTemplate.rgb("#FF5722"));
- set.setCircleColor(ColorTemplate.rgb("#FF5722"));
- set.setLineWidth(1.8f);
- set.setCircleRadius(3.6f);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- LineData data = new LineData(dataSets);
- styleData(data);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityPie.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityPie.java
deleted file mode 100644
index 9fad49c617..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityPie.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.graphics.Color;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.text.SpannableString;
-import android.text.style.ForegroundColorSpan;
-import android.text.style.RelativeSizeSpan;
-import android.text.style.StyleSpan;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.charts.PieChart;
-import com.github.mikephil.charting.data.PieData;
-import com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityPie extends RealmBaseActivity {
-
- private PieChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_piechart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.setCenterText(generateCenterSpannableText());
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDBPie();
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- RealmPieDataSet set = new RealmPieDataSet(result, "yValue", "label");
- set.setColors(ColorTemplate.VORDIPLOM_COLORS);
- set.setLabel("Example market share");
- set.setSliceSpace(2);
-
- // create a data object with the dataset list
- PieData data = new PieData(set);
- styleData(data);
- data.setValueTextColor(Color.WHITE);
- data.setValueTextSize(12f);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400);
- }
-
- private SpannableString generateCenterSpannableText() {
-
- SpannableString s = new SpannableString("Realm.io\nmobile database");
- s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
- s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
- s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
- s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
- s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
- return s;
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityRadar.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityRadar.java
deleted file mode 100644
index 02f3ac0492..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityRadar.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.graphics.Color;
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.charts.RadarChart;
-import com.github.mikephil.charting.data.RadarData;
-import com.github.mikephil.charting.data.realm.implementation.RealmRadarDataSet;
-import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityRadar extends RealmBaseActivity {
-
- private RadarChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_radarchart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.getYAxis().setEnabled(false);
- mChart.getXAxis().setEnabled(false);
- mChart.setWebAlpha(180);
- mChart.setWebColorInner(Color.DKGRAY);
- mChart.setWebColor(Color.GRAY);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDB(7);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- //RealmBarDataSet set = new RealmBarDataSet(result, "stackValues", "xIndex"); // normal entries
- RealmRadarDataSet set = new RealmRadarDataSet(result, "yValue"); // stacked entries
- set.setLabel("Realm RadarDataSet");
- set.setDrawFilled(true);
- set.setColor(ColorTemplate.rgb("#009688"));
- set.setFillColor(ColorTemplate.rgb("#009688"));
- set.setFillAlpha(130);
- set.setLineWidth(2f);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- RadarData data = new RadarData(dataSets);
- styleData(data);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityScatter.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityScatter.java
deleted file mode 100644
index 9da64cbf1d..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityScatter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.ScatterChart;
-import com.github.mikephil.charting.data.ScatterData;
-import com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet;
-import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 21/10/15.
- */
-public class RealmDatabaseActivityScatter extends RealmBaseActivity {
-
- private ScatterChart mChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_scatterchart_noseekbar);
-
- mChart = findViewById(R.id.chart1);
- setup(mChart);
-
- mChart.getAxisLeft().setDrawGridLines(false);
- mChart.getXAxis().setDrawGridLines(false);
- mChart.setPinchZoom(true);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- // write some demo-data into the realm.io database
- writeToDB(45);
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- RealmResults result = mRealm.where(RealmDemoData.class).findAll();
-
- RealmScatterDataSet set = new RealmScatterDataSet(result, "xValue", "yValue");
- set.setLabel("Realm ScatterDataSet");
- set.setScatterShapeSize(9f);
- set.setColor(ColorTemplate.rgb("#CDDC39"));
- set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set); // add the dataset
-
- // create a data object with the dataset list
- ScatterData data = new ScatterData(dataSets);
- styleData(data);
-
- // set data
- mChart.setData(data);
- mChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmMainActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmMainActivity.java
deleted file mode 100644
index 1776a8bd7e..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmMainActivity.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.WindowManager;
-import android.widget.AdapterView;
-import android.widget.ListView;
-
-import com.xxmassdeveloper.mpchartexample.R;
-import com.xxmassdeveloper.mpchartexample.notimportant.ContentItem;
-import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-import com.xxmassdeveloper.mpchartexample.notimportant.MyAdapter;
-
-import java.util.ArrayList;
-
-import io.realm.Realm;
-import io.realm.RealmConfiguration;
-
-/**
- * Created by Philipp Jahoda on 07/12/15.
- */
-public class RealmMainActivity extends DemoBase implements AdapterView.OnItemClickListener {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_main);
-
- setTitle("Realm.io Examples");
-
- ArrayList objects = new ArrayList();
-
- objects.add(new ContentItem("Line Chart", "Creating a LineChart with Realm.io database"));
- objects.add(new ContentItem("Bar Chart",
- "Creating a BarChart with Realm.io database"));
- objects.add(new ContentItem("Horizontal Bar Chart",
- "Creating a HorizontalBarChart with Realm.io database"));
- objects.add(new ContentItem("Scatter Chart",
- "Creating a ScatterChart with Realm.io database"));
- objects.add(new ContentItem("Candle Stick Chart", "Creating a CandleStickChart with Realm.io database"));
- objects.add(new ContentItem("Bubble Chart", "Creating a BubbleChart with Realm.io database"));
- objects.add(new ContentItem("Pie Chart", "Creating a PieChart with Realm.io database"));
- objects.add(new ContentItem("Radar Chart", "Creating a RadarChart with Realm.io database"));
- objects.add(new ContentItem("Realm Wiki", "This is the code related to the wiki entry about realm.io on the MPAndroidChart github page."));
-
- MyAdapter adapter = new MyAdapter(this, objects);
-
- ListView lv = findViewById(R.id.listView1);
- lv.setAdapter(adapter);
-
- lv.setOnItemClickListener(this);
-
- Realm.init(this);
-
- // Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
- RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
- Realm.setDefaultConfiguration(realmConfig);
-
- Realm realm = Realm.getDefaultInstance();
- realm.beginTransaction();
- realm.deleteAll();
- realm.commitTransaction();
- }
-
- @Override
- public void onItemClick(AdapterView> av, View v, int pos, long arg3) {
-
- Intent i;
-
- switch (pos) {
- case 0:
- i = new Intent(this, RealmDatabaseActivityLine.class);
- startActivity(i);
- break;
- case 1:
- i = new Intent(this, RealmDatabaseActivityBar.class);
- startActivity(i);
- break;
- case 2:
- i = new Intent(this, RealmDatabaseActivityHorizontalBar.class);
- startActivity(i);
- break;
- case 3:
- i = new Intent(this, RealmDatabaseActivityScatter.class);
- startActivity(i);
- break;
- case 4:
- i = new Intent(this, RealmDatabaseActivityCandle.class);
- startActivity(i);
- break;
- case 5:
- i = new Intent(this, RealmDatabaseActivityBubble.class);
- startActivity(i);
- break;
- case 6:
- i = new Intent(this, RealmDatabaseActivityPie.class);
- startActivity(i);
- break;
- case 7:
- i = new Intent(this, RealmDatabaseActivityRadar.class);
- startActivity(i);
- break;
- case 8:
- i = new Intent(this, RealmWikiExample.class);
- startActivity(i);
- break;
- }
-
- overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.realm, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
-
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse("https://realm.io/"));
- startActivity(i);
-
- return super.onOptionsItemSelected(item);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmWikiExample.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmWikiExample.java
deleted file mode 100644
index f223be6093..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmWikiExample.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-import android.os.Bundle;
-import android.view.WindowManager;
-
-import com.github.mikephil.charting.animation.Easing;
-import com.github.mikephil.charting.charts.BarChart;
-import com.github.mikephil.charting.charts.LineChart;
-import com.github.mikephil.charting.components.AxisBase;
-import com.github.mikephil.charting.data.BarData;
-import com.github.mikephil.charting.data.LineData;
-import com.github.mikephil.charting.data.LineDataSet;
-import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
-import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
-import com.github.mikephil.charting.formatter.IAxisValueFormatter;
-import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
-import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
-import com.github.mikephil.charting.utils.ColorTemplate;
-import com.xxmassdeveloper.mpchartexample.R;
-
-import java.util.ArrayList;
-
-import io.realm.RealmResults;
-
-/**
- * Created by Philipp Jahoda on 18/12/15.
- */
-public class RealmWikiExample extends RealmBaseActivity {
-
- private LineChart lineChart;
- private BarChart barChart;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_realm_wiki);
-
- lineChart = findViewById(R.id.lineChart);
- barChart = findViewById(R.id.barChart);
- setup(lineChart);
- setup(barChart);
-
- lineChart.setExtraBottomOffset(5f);
- barChart.setExtraBottomOffset(5f);
-
- lineChart.getAxisLeft().setDrawGridLines(false);
- lineChart.getXAxis().setDrawGridLines(false);
- lineChart.getXAxis().setLabelCount(5);
- lineChart.getXAxis().setGranularity(1f);
- barChart.getAxisLeft().setDrawGridLines(false);
- barChart.getXAxis().setDrawGridLines(false);
- barChart.getXAxis().setLabelCount(5);
- barChart.getXAxis().setGranularity(1f);
- }
-
- @Override
- protected void onResume() {
- super.onResume(); // setup realm
-
- mRealm.beginTransaction();
-
- // write some demo-data into the realm.io database
- Score score1 = new Score(100f, 0f, "Peter");
- mRealm.copyToRealm(score1);
- Score score2 = new Score(110f, 1f, "Lisa");
- mRealm.copyToRealm(score2);
- Score score3 = new Score(130f, 2f, "Dennis");
- mRealm.copyToRealm(score3);
- Score score4 = new Score(70f, 3f, "Luke");
- mRealm.copyToRealm(score4);
- Score score5 = new Score(80f, 4f, "Sarah");
- mRealm.copyToRealm(score5);
-
- mRealm.commitTransaction();
-
- // add data to the chart
- setData();
- }
-
- private void setData() {
-
- // LINE-CHART
- final RealmResults results = mRealm.where(Score.class).findAll();
-
-
- IAxisValueFormatter formatter = new IAxisValueFormatter() {
- @Override
- public String getFormattedValue(float value, AxisBase axis) {
- return results.get((int) value).getPlayerName();
- }
- };
-
- lineChart.getXAxis().setValueFormatter(formatter);
- barChart.getXAxis().setValueFormatter(formatter);
-
- RealmLineDataSet lineDataSet = new RealmLineDataSet(results, "scoreNr", "totalScore");
- lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
- lineDataSet.setLabel("Result Scores");
- lineDataSet.setDrawCircleHole(false);
- lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
- lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
- lineDataSet.setLineWidth(1.8f);
- lineDataSet.setCircleRadius(3.6f);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(lineDataSet);
-
- LineData lineData = new LineData(dataSets);
- styleData(lineData);
-
- // set data
- lineChart.setData(lineData);
- lineChart.animateY(1400, Easing.EaseInOutQuart);
-
-
- // BAR-CHART
- RealmBarDataSet barDataSet = new RealmBarDataSet(results, "scoreNr", "totalScore");
- barDataSet.setColors(new int[]{ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
- barDataSet.setLabel("Realm BarDataSet");
-
- ArrayList barDataSets = new ArrayList();
- barDataSets.add(barDataSet);
-
- BarData barData = new BarData(barDataSets);
- styleData(barData);
-
- barChart.setData(barData);
- barChart.setFitBars(true);
- barChart.animateY(1400, Easing.EaseInOutQuart);
- }
-}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/Score.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/Score.java
deleted file mode 100644
index 870e371491..0000000000
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/Score.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.xxmassdeveloper.mpchartexample.realm;
-
-
-import io.realm.RealmObject;
-
-/**
- * our data object
- */
-public class Score extends RealmObject {
-
- private float totalScore;
-
- private float scoreNr;
-
- private String playerName;
-
- public Score() {
- }
-
- public Score(float totalScore, float scoreNr, String playerName) {
- this.scoreNr = scoreNr;
- this.playerName = playerName;
- this.totalScore = totalScore;
- }
-
- // all getters and setters...
-
- public float getTotalScore() {
- return totalScore;
- }
-
- public void setTotalScore(float totalScore) {
- this.totalScore = totalScore;
- }
-
- public float getScoreNr() {
- return scoreNr;
- }
-
- public void setScoreNr(float scoreNr) {
- this.scoreNr = scoreNr;
- }
-
- public String getPlayerName() {
- return playerName;
- }
-
- public void setPlayerName(String playerName) {
- this.playerName = playerName;
- }
-}
\ No newline at end of file
diff --git a/MPChartExample/src/main/AndroidManifest.xml b/MPChartExample/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..99334e601a
--- /dev/null
+++ b/MPChartExample/src/main/AndroidManifest.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MPChartExample/assets/OpenSans-Bold.ttf b/MPChartExample/src/main/assets/OpenSans-Bold.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-Bold.ttf
rename to MPChartExample/src/main/assets/OpenSans-Bold.ttf
diff --git a/MPChartExample/assets/OpenSans-BoldItalic.ttf b/MPChartExample/src/main/assets/OpenSans-BoldItalic.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-BoldItalic.ttf
rename to MPChartExample/src/main/assets/OpenSans-BoldItalic.ttf
diff --git a/MPChartExample/assets/OpenSans-ExtraBold.ttf b/MPChartExample/src/main/assets/OpenSans-ExtraBold.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-ExtraBold.ttf
rename to MPChartExample/src/main/assets/OpenSans-ExtraBold.ttf
diff --git a/MPChartExample/assets/OpenSans-ExtraBoldItalic.ttf b/MPChartExample/src/main/assets/OpenSans-ExtraBoldItalic.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-ExtraBoldItalic.ttf
rename to MPChartExample/src/main/assets/OpenSans-ExtraBoldItalic.ttf
diff --git a/MPChartExample/assets/OpenSans-Italic.ttf b/MPChartExample/src/main/assets/OpenSans-Italic.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-Italic.ttf
rename to MPChartExample/src/main/assets/OpenSans-Italic.ttf
diff --git a/MPChartExample/assets/OpenSans-Light.ttf b/MPChartExample/src/main/assets/OpenSans-Light.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-Light.ttf
rename to MPChartExample/src/main/assets/OpenSans-Light.ttf
diff --git a/MPChartExample/assets/OpenSans-LightItalic.ttf b/MPChartExample/src/main/assets/OpenSans-LightItalic.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-LightItalic.ttf
rename to MPChartExample/src/main/assets/OpenSans-LightItalic.ttf
diff --git a/MPChartExample/assets/OpenSans-Regular.ttf b/MPChartExample/src/main/assets/OpenSans-Regular.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-Regular.ttf
rename to MPChartExample/src/main/assets/OpenSans-Regular.ttf
diff --git a/MPChartExample/assets/OpenSans-Semibold.ttf b/MPChartExample/src/main/assets/OpenSans-Semibold.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-Semibold.ttf
rename to MPChartExample/src/main/assets/OpenSans-Semibold.ttf
diff --git a/MPChartExample/assets/OpenSans-SemiboldItalic.ttf b/MPChartExample/src/main/assets/OpenSans-SemiboldItalic.ttf
similarity index 100%
rename from MPChartExample/assets/OpenSans-SemiboldItalic.ttf
rename to MPChartExample/src/main/assets/OpenSans-SemiboldItalic.ttf
diff --git a/MPChartExample/assets/cosine.txt b/MPChartExample/src/main/assets/cosine.txt
similarity index 100%
rename from MPChartExample/assets/cosine.txt
rename to MPChartExample/src/main/assets/cosine.txt
diff --git a/MPChartExample/assets/hugecosine.txt b/MPChartExample/src/main/assets/hugecosine.txt
similarity index 100%
rename from MPChartExample/assets/hugecosine.txt
rename to MPChartExample/src/main/assets/hugecosine.txt
diff --git a/MPChartExample/assets/hugesine.txt b/MPChartExample/src/main/assets/hugesine.txt
similarity index 100%
rename from MPChartExample/assets/hugesine.txt
rename to MPChartExample/src/main/assets/hugesine.txt
diff --git a/MPChartExample/assets/n.txt b/MPChartExample/src/main/assets/n.txt
similarity index 100%
rename from MPChartExample/assets/n.txt
rename to MPChartExample/src/main/assets/n.txt
diff --git a/MPChartExample/assets/nlogn.txt b/MPChartExample/src/main/assets/nlogn.txt
similarity index 100%
rename from MPChartExample/assets/nlogn.txt
rename to MPChartExample/src/main/assets/nlogn.txt
diff --git a/MPChartExample/assets/othersine.txt b/MPChartExample/src/main/assets/othersine.txt
similarity index 100%
rename from MPChartExample/assets/othersine.txt
rename to MPChartExample/src/main/assets/othersine.txt
diff --git a/MPChartExample/assets/sine.txt b/MPChartExample/src/main/assets/sine.txt
similarity index 100%
rename from MPChartExample/assets/sine.txt
rename to MPChartExample/src/main/assets/sine.txt
diff --git a/MPChartExample/assets/square.txt b/MPChartExample/src/main/assets/square.txt
similarity index 100%
rename from MPChartExample/assets/square.txt
rename to MPChartExample/src/main/assets/square.txt
diff --git a/MPChartExample/assets/stacked_bars.txt b/MPChartExample/src/main/assets/stacked_bars.txt
similarity index 100%
rename from MPChartExample/assets/stacked_bars.txt
rename to MPChartExample/src/main/assets/stacked_bars.txt
diff --git a/MPChartExample/assets/three.txt b/MPChartExample/src/main/assets/three.txt
similarity index 100%
rename from MPChartExample/assets/three.txt
rename to MPChartExample/src/main/assets/three.txt
diff --git a/MPChartExample/ic_launcher-web.png b/MPChartExample/src/main/ic_launcher-web.png
similarity index 100%
rename from MPChartExample/ic_launcher-web.png
rename to MPChartExample/src/main/ic_launcher-web.png
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
new file mode 100644
index 0000000000..69b5a96c42
--- /dev/null
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
@@ -0,0 +1,214 @@
+
+package com.xxmassdeveloper.mpchartexample;
+
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Bundle;
+import androidx.core.content.ContextCompat;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.WindowManager;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+
+import com.github.mikephil.charting.charts.BarChart;
+import com.github.mikephil.charting.components.XAxis;
+import com.github.mikephil.charting.components.XAxis.XAxisPosition;
+import com.github.mikephil.charting.data.BarData;
+import com.github.mikephil.charting.data.BarDataSet;
+import com.github.mikephil.charting.data.BarEntry;
+import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
+import com.github.mikephil.charting.interfaces.datasets.IDataSet;
+import com.github.mikephil.charting.utils.ColorTemplate;
+import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
+
+import java.util.ArrayList;
+
+public class AnotherBarActivity extends DemoBase implements OnSeekBarChangeListener {
+
+ private BarChart chart;
+ private SeekBar seekBarX, seekBarY;
+ private TextView tvX, tvY;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setContentView(R.layout.activity_barchart);
+
+ setTitle("AnotherBarActivity");
+
+ tvX = findViewById(R.id.tvXMax);
+ tvY = findViewById(R.id.tvYMax);
+
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
+
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
+
+ chart = findViewById(R.id.chart1);
+
+ chart.getDescription().setEnabled(false);
+
+ // if more than 60 entries are displayed in the chart, no values will be
+ // drawn
+ chart.setMaxVisibleValueCount(60);
+
+ // scaling can now only be done on x- and y-axis separately
+ chart.setPinchZoom(false);
+
+ chart.setDrawBarShadow(false);
+ chart.setDrawGridBackground(false);
+
+ XAxis xAxis = chart.getXAxis();
+ xAxis.setPosition(XAxisPosition.BOTTOM);
+ xAxis.setDrawGridLines(false);
+
+ chart.getAxisLeft().setDrawGridLines(false);
+
+ // setting data
+ seekBarX.setProgress(10);
+ seekBarY.setProgress(100);
+
+ // add a nice and smooth animation
+ chart.animateY(1500);
+
+ chart.getLegend().setEnabled(false);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < seekBarX.getProgress(); i++) {
+ float multi = (seekBarY.getProgress() + 1);
+ float val = (float) (Math.random() * multi) + multi / 3;
+ values.add(new BarEntry(i, val));
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set1 = new BarDataSet(values, "Data Set");
+ set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
+ set1.setDrawValues(false);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
+
+ BarData data = new BarData(dataSets);
+ chart.setData(data);
+ chart.setFitBars(true);
+ }
+
+ chart.invalidate();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.bar, menu);
+ menu.removeItem(R.id.actionToggleIcons);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java"));
+ startActivity(i);
+ break;
+ }
+ case R.id.actionToggleValues: {
+
+ for (IDataSet set : chart.getData().getDataSets())
+ set.setDrawValues(!set.isDrawValuesEnabled());
+
+ chart.invalidate();
+ break;
+ }
+ /*
+ case R.id.actionToggleIcons: { break; }
+ */
+ case R.id.actionToggleHighlight: {
+
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
+ }
+ break;
+ }
+ case R.id.actionTogglePinch: {
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
+ else
+ chart.setPinchZoom(true);
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleAutoScaleMinMax: {
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
+ break;
+ }
+ case R.id.actionToggleBarBorders: {
+ for (IBarDataSet set : chart.getData().getDataSets())
+ ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.animateX: {
+ chart.animateX(2000);
+ break;
+ }
+ case R.id.animateY: {
+ chart.animateY(2000);
+ break;
+ }
+ case R.id.animateXY: {
+
+ chart.animateXY(2000, 2000);
+ break;
+ }
+ case R.id.actionSave: {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
+ break;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "AnotherBarActivity");
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {}
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
+}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
similarity index 56%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
index c0e3405625..0d83e3444a 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
@@ -1,10 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
-import android.annotation.SuppressLint;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.RectF;
+import android.net.Uri;
import android.os.Bundle;
-import android.support.v4.content.ContextCompat;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -12,7 +15,6 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.Legend;
@@ -31,8 +33,7 @@
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
-import com.github.mikephil.charting.model.GradientColor;
-import com.github.mikephil.charting.utils.ColorTemplate;
+import com.github.mikephil.charting.utils.Fill;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
@@ -45,8 +46,8 @@
public class BarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- protected BarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -56,35 +57,40 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
+ setTitle("BarChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
- mChart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart.setDrawBarShadow(false);
+ chart.setDrawValueAboveBar(true);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
- // mChart.setDrawYLabels(false);
+ chart.setDrawGridBackground(false);
+ // chart.setDrawYLabels(false);
- IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart);
+ IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setTypeface(mTfLight);
+ xAxis.setTypeface(tfLight);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f); // only intervals of 1 day
xAxis.setLabelCount(7);
@@ -92,23 +98,23 @@ protected void onCreate(Bundle savedInstanceState) {
IAxisValueFormatter custom = new MyAxisValueFormatter();
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(8, false);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
- rightAxis.setTypeface(mTfLight);
+ rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(8, false);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -117,25 +123,78 @@ protected void onCreate(Bundle savedInstanceState) {
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
- // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
- // "def", "ghj", "ikl", "mno" });
- // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
- // "def", "ghj", "ikl", "mno" });
XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
-
- setData(12, 50);
+ mv.setChartView(chart); // For bounds control
+ chart.setMarker(mv); // Set the marker to the chart
// setting data
- mSeekBarY.setProgress(50);
- mSeekBarX.setProgress(12);
+ seekBarY.setProgress(50);
+ seekBarX.setProgress(12);
+
+ // chart.setDrawLegend(false);
+ }
+
+ private void setData(int count, float range) {
+
+ float start = 1f;
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = (int) start; i < start + count; i++) {
+ float val = (float) (Math.random() * (range + 1));
+
+ if (Math.random() * 100 < 25) {
+ values.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
+ } else {
+ values.add(new BarEntry(i, val));
+ }
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+
+ } else {
+ set1 = new BarDataSet(values, "The year 2017");
+
+ set1.setDrawIcons(false);
+
+ int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
+ int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
+ int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
+ int startColor4 = ContextCompat.getColor(this, android.R.color.holo_green_light);
+ int startColor5 = ContextCompat.getColor(this, android.R.color.holo_red_light);
+ int endColor1 = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
+ int endColor2 = ContextCompat.getColor(this, android.R.color.holo_purple);
+ int endColor3 = ContextCompat.getColor(this, android.R.color.holo_green_dark);
+ int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
+ int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
+
+ List gradientFills = new ArrayList<>();
+ gradientFills.add(new Fill(startColor1, endColor1));
+ gradientFills.add(new Fill(startColor2, endColor2));
+ gradientFills.add(new Fill(startColor3, endColor3));
+ gradientFills.add(new Fill(startColor4, endColor4));
+ gradientFills.add(new Fill(startColor5, endColor5));
+
+ set1.setFills(gradientFills);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
- // mChart.setDrawLegend(false);
+ BarData data = new BarData(dataSets);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setBarWidth(0.9f);
+
+ chart.setData(data);
+ }
}
@Override
@@ -148,68 +207,72 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -219,110 +282,42 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 2));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1 , mSeekBarY.getProgress());
- mChart.invalidate();
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
+ protected void saveToGallery() {
+ saveToGallery(chart, "BarChartActivity");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
- }
-
- private void setData(int count, float range) {
-
- float start = 1f;
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = (int) start; i < start + count + 1; i++) {
- float mult = (range + 1);
- float val = (float) (Math.random() * mult);
-
- if (Math.random() * 100 < 25) {
- yVals1.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
- } else {
- yVals1.add(new BarEntry(i, val));
- }
- }
-
- BarDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals1);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set1 = new BarDataSet(yVals1, "The year 2017");
-
- set1.setDrawIcons(false);
-
-// set1.setColors(ColorTemplate.MATERIAL_COLORS);
-
- /*int startColor = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
- int endColor = ContextCompat.getColor(this, android.R.color.holo_blue_bright);
- set1.setGradientColor(startColor, endColor);*/
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
- int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
- int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
- int startColor4 = ContextCompat.getColor(this, android.R.color.holo_green_light);
- int startColor5 = ContextCompat.getColor(this, android.R.color.holo_red_light);
- int endColor1 = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
- int endColor2 = ContextCompat.getColor(this, android.R.color.holo_purple);
- int endColor3 = ContextCompat.getColor(this, android.R.color.holo_green_dark);
- int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
- int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
-
- List gradientColors = new ArrayList<>();
- gradientColors.add(new GradientColor(startColor1, endColor1));
- gradientColors.add(new GradientColor(startColor2, endColor2));
- gradientColors.add(new GradientColor(startColor3, endColor3));
- gradientColors.add(new GradientColor(startColor4, endColor4));
- gradientColors.add(new GradientColor(startColor5, endColor5));
-
- set1.setGradientColors(gradientColors);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1);
-
- BarData data = new BarData(dataSets);
- data.setValueTextSize(10f);
- data.setValueTypeface(mTfLight);
- data.setBarWidth(0.9f);
-
- mChart.setData(data);
- }
- }
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
- protected RectF mOnValueSelectedRectF = new RectF();
+ private final RectF onValueSelectedRectF = new RectF();
- @SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
if (e == null)
return;
- RectF bounds = mOnValueSelectedRectF;
- mChart.getBarBounds((BarEntry) e, bounds);
- MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);
+ RectF bounds = onValueSelectedRectF;
+ chart.getBarBounds((BarEntry) e, bounds);
+ MPPointF position = chart.getPosition(e, AxisDependency.LEFT);
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
Log.i("x-index",
- "low: " + mChart.getLowestVisibleX() + ", high: "
- + mChart.getHighestVisibleX());
+ "low: " + chart.getLowestVisibleX() + ", high: "
+ + chart.getHighestVisibleX());
MPPointF.recycleInstance(position);
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
similarity index 52%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
index 204dc1fe64..075af0edbc 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -29,12 +34,13 @@
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
+import java.util.Locale;
public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private BarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -44,51 +50,54 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
+ setTitle("BarChartActivityMultiDataset");
+
tvX = findViewById(R.id.tvXMax);
tvX.setTextSize(10);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setMax(50);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- mChart.getDescription().setEnabled(false);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ chart.getDescription().setEnabled(false);
-// mChart.setDrawBorders(true);
+// chart.setDrawBorders(true);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawBarShadow(false);
+ chart.setDrawBarShadow(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
+ mv.setChartView(chart); // For bounds control
+ chart.setMarker(mv); // Set the marker to the chart
- mSeekBarX.setProgress(10);
- mSeekBarY.setProgress(100);
+ seekBarX.setProgress(10);
+ seekBarY.setProgress(100);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(true);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
l.setYOffset(0f);
l.setXOffset(10f);
l.setYEntrySpace(0f);
l.setTextSize(8f);
- XAxis xAxis = mChart.getXAxis();
- xAxis.setTypeface(mTfLight);
+ XAxis xAxis = chart.getXAxis();
+ xAxis.setTypeface(tfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@@ -98,14 +107,88 @@ public String getFormattedValue(float value, AxisBase axis) {
}
});
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setValueFormatter(new LargeValueFormatter());
leftAxis.setDrawGridLines(false);
leftAxis.setSpaceTop(35f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- mChart.getAxisRight().setEnabled(false);
+ chart.getAxisRight().setEnabled(false);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ float groupSpace = 0.08f;
+ float barSpace = 0.03f; // x4 DataSet
+ float barWidth = 0.2f; // x4 DataSet
+ // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
+
+ int groupCount = seekBarX.getProgress() + 1;
+ int startYear = 1980;
+ int endYear = startYear + groupCount;
+
+ tvX.setText(String.format(Locale.ENGLISH, "%d-%d", startYear, endYear));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ ArrayList values1 = new ArrayList<>();
+ ArrayList values2 = new ArrayList<>();
+ ArrayList values3 = new ArrayList<>();
+ ArrayList values4 = new ArrayList<>();
+
+ float randomMultiplier = seekBarY.getProgress() * 100000f;
+
+ for (int i = startYear; i < endYear; i++) {
+ values1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ values2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ values3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ values4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ }
+
+ BarDataSet set1, set2, set3, set4;
+
+ if (chart.getData() != null && chart.getData().getDataSetCount() > 0) {
+
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set2 = (BarDataSet) chart.getData().getDataSetByIndex(1);
+ set3 = (BarDataSet) chart.getData().getDataSetByIndex(2);
+ set4 = (BarDataSet) chart.getData().getDataSetByIndex(3);
+ set1.setValues(values1);
+ set2.setValues(values2);
+ set3.setValues(values3);
+ set4.setValues(values4);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+
+ } else {
+ // create 4 DataSets
+ set1 = new BarDataSet(values1, "Company A");
+ set1.setColor(Color.rgb(104, 241, 175));
+ set2 = new BarDataSet(values2, "Company B");
+ set2.setColor(Color.rgb(164, 228, 251));
+ set3 = new BarDataSet(values3, "Company C");
+ set3.setColor(Color.rgb(242, 247, 158));
+ set4 = new BarDataSet(values4, "Company D");
+ set4.setColor(Color.rgb(255, 102, 0));
+
+ BarData data = new BarData(set1, set2, set3, set4);
+ data.setValueFormatter(new LargeValueFormatter());
+ data.setValueTypeface(tfLight);
+
+ chart.setData(data);
+ }
+
+ // specify the width each bar should have
+ chart.getBarData().setBarWidth(barWidth);
+
+ // restrict the x-axis range
+ chart.getXAxis().setAxisMinimum(startYear);
+
+ // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
+ chart.getXAxis().setAxisMaximum(startYear + chart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
+ chart.groupBars(startYear, groupSpace, barSpace);
+ chart.invalidate();
}
@Override
@@ -118,56 +201,65 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
}
@@ -175,88 +267,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- float groupSpace = 0.08f;
- float barSpace = 0.03f; // x4 DataSet
- float barWidth = 0.2f; // x4 DataSet
- // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
-
- int groupCount = mSeekBarX.getProgress() + 1;
- int startYear = 1980;
- int endYear = startYear + groupCount;
-
- tvX.setText(startYear + "-" + endYear);
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- ArrayList yVals1 = new ArrayList();
- ArrayList yVals2 = new ArrayList();
- ArrayList yVals3 = new ArrayList();
- ArrayList yVals4 = new ArrayList();
-
- float randomMultiplier = mSeekBarY.getProgress() * 100000f;
-
- for (int i = startYear; i < endYear; i++) {
- yVals1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- yVals2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- yVals3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- yVals4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- }
-
- BarDataSet set1, set2, set3, set4;
-
- if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
-
- set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
- set2 = (BarDataSet) mChart.getData().getDataSetByIndex(1);
- set3 = (BarDataSet) mChart.getData().getDataSetByIndex(2);
- set4 = (BarDataSet) mChart.getData().getDataSetByIndex(3);
- set1.setValues(yVals1);
- set2.setValues(yVals2);
- set3.setValues(yVals3);
- set4.setValues(yVals4);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
-
- } else {
- // create 4 DataSets
- set1 = new BarDataSet(yVals1, "Company A");
- set1.setColor(Color.rgb(104, 241, 175));
- set2 = new BarDataSet(yVals2, "Company B");
- set2.setColor(Color.rgb(164, 228, 251));
- set3 = new BarDataSet(yVals3, "Company C");
- set3.setColor(Color.rgb(242, 247, 158));
- set4 = new BarDataSet(yVals4, "Company D");
- set4.setColor(Color.rgb(255, 102, 0));
-
- BarData data = new BarData(set1, set2, set3, set4);
- data.setValueFormatter(new LargeValueFormatter());
- data.setValueTypeface(mTfLight);
-
- mChart.setData(data);
- }
-
- // specify the width each bar should have
- mChart.getBarData().setBarWidth(barWidth);
-
- // restrict the x-axis range
- mChart.getXAxis().setAxisMinimum(startYear);
-
- // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
- mChart.getXAxis().setAxisMaximum(startYear + mChart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
- mChart.groupBars(startYear, groupSpace, barSpace);
- mChart.invalidate();
+ protected void saveToGallery() {
+ saveToGallery(chart, "BarChartActivityMultiDataset");
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onValueSelected(Entry e, Highlight h) {
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
similarity index 55%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
index 82b039909f..95443e8214 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
@@ -1,20 +1,23 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
@@ -29,11 +32,11 @@
public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeListener {
- protected BarChart mChart;
- private SeekBar mSeekBarX;
+ private BarChart chart;
+ private SeekBar seekBarX;
private TextView tvX;
- private List mSinusData;
+ private List data;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -42,57 +45,59 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_sinus);
- mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
+ setTitle("BarChartActivitySinus");
+
+ data = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
tvX = findViewById(R.id.tvValueCount);
- mSeekBarX = findViewById(R.id.seekbarValues);
+ seekBarX = findViewById(R.id.seekbarValues);
- mChart = findViewById(R.id.chart1);
+ chart = findViewById(R.id.chart1);
- mChart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart.setDrawBarShadow(false);
+ chart.setDrawValueAboveBar(true);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
- // mChart.setDrawBarShadow(true);
+ // chart.setDrawBarShadow(true);
- // mChart.setDrawXLabels(false);
+ // chart.setDrawXLabels(false);
- mChart.setDrawGridBackground(false);
- // mChart.setDrawYLabels(false);
+ chart.setDrawGridBackground(false);
+ // chart.setDrawYLabels(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(6, false);
leftAxis.setAxisMinimum(-2.5f);
leftAxis.setAxisMaximum(2.5f);
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(0.1f);
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
- rightAxis.setTypeface(mTfLight);
+ rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(6, false);
rightAxis.setAxisMinimum(-2.5f);
rightAxis.setAxisMaximum(2.5f);
rightAxis.setGranularity(0.1f);
- mSeekBarX.setOnSeekBarChangeListener(this);
- mSeekBarX.setProgress(150); // set data
+ seekBarX.setOnSeekBarChangeListener(this);
+ seekBarX.setProgress(150); // set data
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -102,7 +107,37 @@ protected void onCreate(Bundle savedInstanceState) {
l.setTextSize(11f);
l.setXEntrySpace(4f);
- mChart.animateXY(2000, 2000);
+ chart.animateXY(1500, 1500);
+ }
+
+ private void setData(int count) {
+
+ ArrayList entries = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ entries.add(data.get(i));
+ }
+
+ BarDataSet set;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set.setValues(entries);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set = new BarDataSet(entries, "Sinus Function");
+ set.setColor(Color.rgb(240, 120, 124));
+ }
+
+ BarData data = new BarData(set);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setDrawValues(false);
+ data.setBarWidth(0.8f);
+
+ chart.setData(data);
}
@Override
@@ -115,61 +150,66 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(1500);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(1500);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(2000, 2000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -179,51 +219,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
- setData(mSeekBarX.getProgress());
- mChart.invalidate();
+ setData(seekBarX.getProgress());
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ protected void saveToGallery() {
+ saveToGallery(chart, "BarChartActivitySinus");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count) {
-
- ArrayList entries = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- entries.add(mSinusData.get(i));
- }
-
- BarDataSet set;
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set = (BarDataSet) mChart.getData().getDataSetByIndex(0);
- set.setValues(entries);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set = new BarDataSet(entries, "Sinus Function");
- set.setColor(Color.rgb(240, 120, 124));
- }
-
- BarData data = new BarData(set);
- data.setValueTextSize(10f);
- data.setValueTypeface(mTfLight);
- data.setDrawValues(false);
- data.setBarWidth(0.8f);
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
- mChart.setData(data);
- }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
similarity index 64%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
index 7d6bd44896..4fec7dd6ab 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
@@ -1,9 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
-import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.BarChart;
@@ -26,8 +29,7 @@
public class BarChartPositiveNegative extends DemoBase {
- protected BarChart mChart;
- private Typeface mTf;
+ private BarChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -36,27 +38,28 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_noseekbar);
- mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setExtraTopOffset(-30f);
- mChart.setExtraBottomOffset(10f);
- mChart.setExtraLeftOffset(70f);
- mChart.setExtraRightOffset(70f);
+ setTitle("BarChartPositiveNegative");
- mChart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setExtraTopOffset(-30f);
+ chart.setExtraBottomOffset(10f);
+ chart.setExtraLeftOffset(70f);
+ chart.setExtraRightOffset(70f);
- mChart.getDescription().setEnabled(false);
+ chart.setDrawBarShadow(false);
+ chart.setDrawValueAboveBar(true);
+
+ chart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setTypeface(mTf);
+ xAxis.setTypeface(tfRegular);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextColor(Color.LTGRAY);
@@ -65,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f);
- YAxis left = mChart.getAxisLeft();
+ YAxis left = chart.getAxisLeft();
left.setDrawLabels(false);
left.setSpaceTop(25f);
left.setSpaceBottom(25f);
@@ -74,8 +77,8 @@ protected void onCreate(Bundle savedInstanceState) {
left.setDrawZeroLine(true); // draw a zero line
left.setZeroLineColor(Color.GRAY);
left.setZeroLineWidth(0.7f);
- mChart.getAxisRight().setEnabled(false);
- mChart.getLegend().setEnabled(false);
+ chart.getAxisRight().setEnabled(false);
+ chart.getLegend().setEnabled(false);
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
final List data = new ArrayList<>();
@@ -97,8 +100,8 @@ public String getFormattedValue(float value, AxisBase axis) {
private void setData(List dataList) {
- ArrayList values = new ArrayList();
- List colors = new ArrayList();
+ ArrayList values = new ArrayList<>();
+ List colors = new ArrayList<>();
int green = Color.rgb(110, 190, 102);
int red = Color.rgb(211, 74, 88);
@@ -118,12 +121,12 @@ private void setData(List dataList) {
BarDataSet set;
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set = (BarDataSet)mChart.getData().getDataSetByIndex(0);
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set = (BarDataSet) chart.getData().getDataSetByIndex(0);
set.setValues(values);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
} else {
set = new BarDataSet(values, "Values");
set.setColors(colors);
@@ -131,12 +134,12 @@ private void setData(List dataList) {
BarData data = new BarData(set);
data.setValueTextSize(13f);
- data.setValueTypeface(mTf);
+ data.setValueTypeface(tfRegular);
data.setValueFormatter(new ValueFormatter());
data.setBarWidth(0.8f);
- mChart.setData(data);
- mChart.invalidate();
+ chart.setData(data);
+ chart.invalidate();
}
}
@@ -145,11 +148,11 @@ private void setData(List dataList) {
*/
private class Data {
- public String xAxisValue;
- public float yValue;
- public float xValue;
+ final String xAxisValue;
+ final float yValue;
+ final float xValue;
- public Data(float xValue, float yValue, String xAxisValue) {
+ Data(float xValue, float yValue, String xAxisValue) {
this.xAxisValue = xAxisValue;
this.yValue = yValue;
this.xValue = xValue;
@@ -159,9 +162,9 @@ public Data(float xValue, float yValue, String xAxisValue) {
private class ValueFormatter implements IValueFormatter
{
- private DecimalFormat mFormat;
+ private final DecimalFormat mFormat;
- public ValueFormatter() {
+ ValueFormatter() {
mFormat = new DecimalFormat("######.0");
}
@@ -170,4 +173,28 @@ public String getFormattedValue(float value, Entry entry, int dataSetIndex, View
return mFormat.format(value);
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
similarity index 52%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
index bc1750381e..6288dda2be 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -13,7 +18,6 @@
import com.github.mikephil.charting.charts.BubbleChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BubbleData;
@@ -33,10 +37,10 @@
public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private BubbleChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BubbleChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -44,52 +48,106 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_bubblechart);
+ setTitle("BubbleChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.getDescription().setEnabled(false);
+ chart = findViewById(R.id.chart1);
+ chart.getDescription().setEnabled(false);
- mChart.setOnChartValueSelectedListener(this);
+ chart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
- mChart.setMaxVisibleValueCount(200);
- mChart.setPinchZoom(true);
+ chart.setMaxVisibleValueCount(200);
+ chart.setPinchZoom(true);
- mSeekBarX.setProgress(10);
- mSeekBarY.setProgress(50);
+ seekBarX.setProgress(10);
+ seekBarY.setProgress(50);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
- YAxis yl = mChart.getAxisLeft();
- yl.setTypeface(mTfLight);
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfLight);
yl.setSpaceTop(30f);
yl.setSpaceBottom(30f);
yl.setDrawZeroLine(false);
-
- mChart.getAxisRight().setEnabled(false);
- XAxis xl = mChart.getXAxis();
+ chart.getAxisRight().setEnabled(false);
+
+ XAxis xl = chart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
- xl.setTypeface(mTfLight);
+ xl.setTypeface(tfLight);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ int count = seekBarX.getProgress();
+ int range = seekBarY.getProgress();
+
+ tvX.setText(String.valueOf(count));
+ tvY.setText(String.valueOf(range));
+
+ ArrayList values1 = new ArrayList<>();
+ ArrayList values2 = new ArrayList<>();
+ ArrayList values3 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ values1.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
+ values2.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
+ values3.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range)));
+ }
+
+ // create a dataset and give it a type
+ BubbleDataSet set1 = new BubbleDataSet(values1, "DS 1");
+ set1.setDrawIcons(false);
+ set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
+ set1.setDrawValues(true);
+
+ BubbleDataSet set2 = new BubbleDataSet(values2, "DS 2");
+ set2.setDrawIcons(false);
+ set2.setIconsOffset(new MPPointF(0, 15));
+ set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
+ set2.setDrawValues(true);
+
+ BubbleDataSet set3 = new BubbleDataSet(values3, "DS 3");
+ set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
+ set3.setDrawValues(true);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1); // add the data sets
+ dataSets.add(set2);
+ dataSets.add(set3);
+
+ // create a data object with the data sets
+ BubbleData data = new BubbleData(dataSets);
+ data.setDrawValues(false);
+ data.setValueTypeface(tfLight);
+ data.setValueTextSize(8f);
+ data.setValueTextColor(Color.WHITE);
+ data.setHighlightCircleWidth(1.5f);
+
+ chart.setData(data);
+ chart.invalidate();
}
@Override
@@ -102,56 +160,65 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
}
@@ -159,70 +226,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- int count = mSeekBarX.getProgress();
- int range = mSeekBarY.getProgress();
-
- tvX.setText("" + count);
- tvY.setText("" + range);
-
- ArrayList yVals1 = new ArrayList();
- ArrayList yVals2 = new ArrayList();
- ArrayList yVals3 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- float size = (float) (Math.random() * range);
-
- yVals1.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
- }
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- float size = (float) (Math.random() * range);
-
- yVals2.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
- }
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- float size = (float) (Math.random() * range);
-
- yVals3.add(new BubbleEntry(i, val, size));
- }
-
- // create a dataset and give it a type
- BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
- set1.setDrawIcons(false);
- set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
- set1.setDrawValues(true);
-
- BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
- set2.setDrawIcons(false);
- set2.setIconsOffset(new MPPointF(0, 15));
- set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
- set2.setDrawValues(true);
-
- BubbleDataSet set3 = new BubbleDataSet(yVals3, "DS 3");
- set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
- set3.setDrawValues(true);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1); // add the datasets
- dataSets.add(set2);
- dataSets.add(set3);
-
- // create a data object with the datasets
- BubbleData data = new BubbleData(dataSets);
- data.setDrawValues(false);
- data.setValueTypeface(mTfLight);
- data.setValueTextSize(8f);
- data.setValueTextColor(Color.WHITE);
- data.setHighlightCircleWidth(1.5f);
-
- mChart.setData(data);
- mChart.invalidate();
+ protected void saveToGallery() {
+ saveToGallery(chart, "BubbleChartActivity");
}
@Override
@@ -233,20 +238,11 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- // TODO Auto-generated method stub
-
- }
+ public void onNothingSelected() {}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
similarity index 57%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
index 54eb768a7b..ecf7167a62 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
@@ -1,16 +1,20 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Paint;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.components.XAxis;
@@ -28,8 +32,8 @@
public class CandleStickChartActivity extends DemoBase implements OnSeekBarChangeListener {
- private CandleStickChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private CandleStickChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -39,48 +43,103 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_candlechart);
+ setTitle("CandleStickChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
// leftAxis.setEnabled(false);
leftAxis.setLabelCount(7, false);
leftAxis.setDrawGridLines(false);
leftAxis.setDrawAxisLine(false);
-
- YAxis rightAxis = mChart.getAxisRight();
+
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// rightAxis.setStartAtZero(false);
// setting data
- mSeekBarX.setProgress(40);
- mSeekBarY.setProgress(100);
-
- mChart.getLegend().setEnabled(false);
+ seekBarX.setProgress(40);
+ seekBarY.setProgress(100);
+
+ chart.getLegend().setEnabled(false);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ progress = (seekBarX.getProgress());
+
+ tvX.setText(String.valueOf(progress));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ chart.resetTracking();
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < progress; i++) {
+ float multi = (seekBarY.getProgress() + 1);
+ float val = (float) (Math.random() * 40) + multi;
+
+ float high = (float) (Math.random() * 9) + 8f;
+ float low = (float) (Math.random() * 9) + 8f;
+
+ float open = (float) (Math.random() * 6) + 1f;
+ float close = (float) (Math.random() * 6) + 1f;
+
+ boolean even = i % 2 == 0;
+
+ values.add(new CandleEntry(
+ i, val + high,
+ val - low,
+ even ? val + open : val - open,
+ even ? val - close : val + close,
+ getResources().getDrawable(R.drawable.star)
+ ));
+ }
+
+ CandleDataSet set1 = new CandleDataSet(values, "Data Set");
+
+ set1.setDrawIcons(false);
+ set1.setAxisDependency(AxisDependency.LEFT);
+// set1.setColor(Color.rgb(80, 80, 80));
+ set1.setShadowColor(Color.DKGRAY);
+ set1.setShadowWidth(0.7f);
+ set1.setDecreasingColor(Color.RED);
+ set1.setDecreasingPaintStyle(Paint.Style.FILL);
+ set1.setIncreasingColor(Color.rgb(122, 242, 84));
+ set1.setIncreasingPaintStyle(Paint.Style.STROKE);
+ set1.setNeutralColor(Color.BLUE);
+ //set1.setHighlightLineWidth(1f);
+
+ CandleData data = new CandleData(set1);
+
+ chart.setData(data);
+ chart.invalidate();
}
@Override
@@ -93,69 +152,73 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleMakeShadowSameColorAsCandle: {
- for (ICandleDataSet set : mChart.getData().getDataSets()) {
- //TODO: set.setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
+ for (ICandleDataSet set : chart.getData().getDataSets()) {
+ ((CandleDataSet) set).setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -163,67 +226,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- int prog = (mSeekBarX.getProgress() + 1);
-
- tvX.setText("" + prog);
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- mChart.resetTracking();
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < prog; i++) {
- float mult = (mSeekBarY.getProgress() + 1);
- float val = (float) (Math.random() * 40) + mult;
-
- float high = (float) (Math.random() * 9) + 8f;
- float low = (float) (Math.random() * 9) + 8f;
-
- float open = (float) (Math.random() * 6) + 1f;
- float close = (float) (Math.random() * 6) + 1f;
-
- boolean even = i % 2 == 0;
-
- yVals1.add(new CandleEntry(
- i, val + high,
- val - low,
- even ? val + open : val - open,
- even ? val - close : val + close,
- getResources().getDrawable(R.drawable.star)
- ));
- }
-
- CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set");
-
- set1.setDrawIcons(false);
- set1.setAxisDependency(AxisDependency.LEFT);
-// set1.setColor(Color.rgb(80, 80, 80));
- set1.setShadowColor(Color.DKGRAY);
- set1.setShadowWidth(0.7f);
- set1.setDecreasingColor(Color.RED);
- set1.setDecreasingPaintStyle(Paint.Style.FILL);
- set1.setIncreasingColor(Color.rgb(122, 242, 84));
- set1.setIncreasingPaintStyle(Paint.Style.STROKE);
- set1.setNeutralColor(Color.BLUE);
- //set1.setHighlightLineWidth(1f);
-
- CandleData data = new CandleData(set1);
-
- mChart.setData(data);
- mChart.invalidate();
+ protected void saveToGallery() {
+ saveToGallery(chart, "CandleStickChartActivity");
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
similarity index 74%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
index e4d8fb2e3b..0308b9a891 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
@@ -1,7 +1,9 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@@ -38,8 +40,8 @@
public class CombinedChartActivity extends DemoBase {
- private CombinedChart mChart;
- private final int itemcount = 12;
+ private CombinedChart chart;
+ private final int count = 12;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -48,41 +50,43 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_combined);
- mChart = findViewById(R.id.chart1);
- mChart.getDescription().setEnabled(false);
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setDrawGridBackground(false);
- mChart.setDrawBarShadow(false);
- mChart.setHighlightFullBarEnabled(false);
+ setTitle("CombinedChartActivity");
+
+ chart = findViewById(R.id.chart1);
+ chart.getDescription().setEnabled(false);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setDrawGridBackground(false);
+ chart.setDrawBarShadow(false);
+ chart.setHighlightFullBarEnabled(false);
// draw bars behind lines
- mChart.setDrawOrder(new DrawOrder[]{
+ chart.setDrawOrder(new DrawOrder[]{
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
});
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
- return mMonths[(int) value % mMonths.length];
+ return months[(int) value % months.length];
}
});
@@ -93,21 +97,21 @@ public String getFormattedValue(float value, AxisBase axis) {
data.setData(generateBubbleData());
data.setData(generateScatterData());
data.setData(generateCandleData());
- data.setValueTypeface(mTfLight);
+ data.setValueTypeface(tfLight);
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
- mChart.setData(data);
- mChart.invalidate();
+ chart.setData(data);
+ chart.invalidate();
}
private LineData generateLineData() {
LineData d = new LineData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (int index = 0; index < itemcount; index++)
+ for (int index = 0; index < count; index++)
entries.add(new Entry(index + 0.5f, getRandom(15, 5)));
LineDataSet set = new LineDataSet(entries, "Line DataSet");
@@ -129,10 +133,10 @@ private LineData generateLineData() {
private BarData generateBarData() {
- ArrayList entries1 = new ArrayList();
- ArrayList entries2 = new ArrayList();
+ ArrayList entries1 = new ArrayList<>();
+ ArrayList entries2 = new ArrayList<>();
- for (int index = 0; index < itemcount; index++) {
+ for (int index = 0; index < count; index++) {
entries1.add(new BarEntry(0, getRandom(25, 25)));
// stacked
@@ -147,7 +151,7 @@ private BarData generateBarData() {
BarDataSet set2 = new BarDataSet(entries2, "");
set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
- set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
+ set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255));
set2.setValueTextColor(Color.rgb(61, 165, 255));
set2.setValueTextSize(10f);
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
@@ -166,13 +170,13 @@ private BarData generateBarData() {
return d;
}
- protected ScatterData generateScatterData() {
+ private ScatterData generateScatterData() {
ScatterData d = new ScatterData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (float index = 0; index < itemcount; index += 0.5f)
+ for (float index = 0; index < count; index += 0.5f)
entries.add(new Entry(index + 0.25f, getRandom(10, 55)));
ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet");
@@ -185,13 +189,13 @@ protected ScatterData generateScatterData() {
return d;
}
- protected CandleData generateCandleData() {
+ private CandleData generateCandleData() {
CandleData d = new CandleData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (int index = 0; index < itemcount; index += 2)
+ for (int index = 0; index < count; index += 2)
entries.add(new CandleEntry(index + 1f, 90, 70, 85, 75f));
CandleDataSet set = new CandleDataSet(entries, "Candle DataSet");
@@ -205,13 +209,13 @@ protected CandleData generateCandleData() {
return d;
}
- protected BubbleData generateBubbleData() {
+ private BubbleData generateBubbleData() {
BubbleData bd = new BubbleData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (int index = 0; index < itemcount; index++) {
+ for (int index = 0; index < count; index++) {
float y = getRandom(10, 105);
float size = getRandom(100, 105);
entries.add(new BubbleEntry(index + 0.5f, y, size));
@@ -237,34 +241,42 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleLineValues: {
- for (IDataSet set : mChart.getData().getDataSets()) {
+ for (IDataSet set : chart.getData().getDataSets()) {
if (set instanceof LineDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleBarValues: {
- for (IDataSet set : mChart.getData().getDataSets()) {
+ for (IDataSet set : chart.getData().getDataSets()) {
if (set instanceof BarDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionRemoveDataSet: {
-
- int rnd = (int) getRandom(mChart.getData().getDataSetCount(), 0);
- mChart.getData().removeDataSet(mChart.getData().getDataSetByIndex(rnd));
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ int rnd = (int) getRandom(chart.getData().getDataSetCount(), 0);
+ chart.getData().removeDataSet(chart.getData().getDataSetByIndex(rnd));
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
break;
}
}
return true;
}
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
similarity index 59%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
index 4a278c398e..996e088f43 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
@@ -1,15 +1,19 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
@@ -28,8 +32,8 @@
public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -39,60 +43,114 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("CubicLineChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
-
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
-
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
- mChart = findViewById(R.id.chart1);
- mChart.setViewPortOffsets(0, 0, 0, 0);
- mChart.setBackgroundColor(Color.rgb(104, 241, 175));
+ chart = findViewById(R.id.chart1);
+ chart.setViewPortOffsets(0, 0, 0, 0);
+ chart.setBackgroundColor(Color.rgb(104, 241, 175));
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
- mChart.setMaxHighlightDistance(300);
-
- XAxis x = mChart.getXAxis();
+ chart.setDrawGridBackground(false);
+ chart.setMaxHighlightDistance(300);
+
+ XAxis x = chart.getXAxis();
x.setEnabled(false);
-
- YAxis y = mChart.getAxisLeft();
- y.setTypeface(mTfLight);
+
+ YAxis y = chart.getAxisLeft();
+ y.setTypeface(tfLight);
y.setLabelCount(6, false);
y.setTextColor(Color.WHITE);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
-
- mChart.getAxisRight().setEnabled(false);
+
+ chart.getAxisRight().setEnabled(false);
// add data
- setData(45, 100);
-
- mChart.getLegend().setEnabled(false);
-
- mChart.animateXY(2000, 2000);
-
- // dont forget to refresh the drawing
- mChart.invalidate();
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
+
+ // lower max, as cubic runs significantly slower than linear
+ seekBarX.setMax(700);
+
+ seekBarX.setProgress(45);
+ seekBarY.setProgress(100);
+
+ chart.getLegend().setEnabled(false);
+
+ chart.animateXY(2000, 2000);
+
+ // don't forget to refresh the drawing
+ chart.invalidate();
+ }
+
+ private void setData(int count, float range) {
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * (range + 1)) + 20;
+ values.add(new Entry(i, val));
+ }
+
+ LineDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ // create a dataset and give it a type
+ set1 = new LineDataSet(values, "DataSet 1");
+
+ set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
+ set1.setCubicIntensity(0.2f);
+ set1.setDrawFilled(true);
+ set1.setDrawCircles(false);
+ set1.setLineWidth(1.8f);
+ set1.setCircleRadius(4f);
+ set1.setCircleColor(Color.WHITE);
+ set1.setHighLightColor(Color.rgb(244, 117, 117));
+ set1.setColor(Color.WHITE);
+ set1.setFillColor(Color.WHITE);
+ set1.setFillAlpha(100);
+ set1.setDrawHorizontalHighlightIndicator(false);
+ set1.setFillFormatter(new IFillFormatter() {
+ @Override
+ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
+ return chart.getAxisLeft().getAxisMinimum();
+ }
+ });
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1);
+ data.setValueTypeface(tfLight);
+ data.setValueTextSize(9f);
+ data.setDrawValues(false);
+
+ // set data
+ chart.setData(data);
+ }
}
@Override
@@ -105,23 +163,29 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -133,11 +197,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -148,11 +212,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -162,11 +226,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -176,11 +240,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHorizontalCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -190,44 +254,41 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -237,78 +298,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ protected void saveToGallery() {
+ saveToGallery(chart, "CubicLineChartActivity");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList yVals = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = (range + 1);
- float val = (float) (Math.random() * mult) + 20;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals.add(new Entry(i, val));
- }
-
- LineDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- // create a dataset and give it a type
- set1 = new LineDataSet(yVals, "DataSet 1");
-
- set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
- set1.setCubicIntensity(0.2f);
- //set1.setDrawFilled(true);
- set1.setDrawCircles(false);
- set1.setLineWidth(1.8f);
- set1.setCircleRadius(4f);
- set1.setCircleColor(Color.WHITE);
- set1.setHighLightColor(Color.rgb(244, 117, 117));
- set1.setColor(Color.WHITE);
- set1.setFillColor(Color.WHITE);
- set1.setFillAlpha(100);
- set1.setDrawHorizontalHighlightIndicator(false);
- set1.setFillFormatter(new IFillFormatter() {
- @Override
- public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
- return -10;
- }
- });
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- // create a data object with the datasets
- LineData data = new LineData(set1);
- data.setValueTypeface(mTfLight);
- data.setValueTextSize(9f);
- data.setDrawValues(false);
-
- // set data
- mChart.setData(data);
- }
- }
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
similarity index 65%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
index d3551068c1..7a32e5329c 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
@@ -1,8 +1,10 @@
-
+// TODO: Finish and add to main activity list
package com.xxmassdeveloper.mpchartexample;
-import android.graphics.Typeface;
+import android.Manifest;
+import android.content.pm.PackageManager;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -28,13 +30,13 @@
/**
* This Activity demonstrates drawing into the Chart with the finger. Both line,
* bar and scatter charts can be used for drawing.
- *
+ *
* @author Philipp Jahoda
*/
public class DrawChartActivity extends DemoBase implements OnChartValueSelectedListener,
OnDrawListener {
- private LineChart mChart;
+ private LineChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -43,49 +45,49 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_draw_chart);
- mChart = findViewById(R.id.chart1);
+ setTitle("DrawChartActivity");
+
+ chart = findViewById(R.id.chart1);
// listener for selecting and drawing
- mChart.setOnChartValueSelectedListener(this);
- mChart.setOnDrawListener(this);
+ chart.setOnChartValueSelectedListener(this);
+ chart.setOnDrawListener(this);
- // if disabled, drawn datasets with the finger will not be automatically
+ // if disabled, drawn data sets with the finger will not be automatically
// finished
- // mChart.setAutoFinish(true);
- mChart.setDrawGridBackground(false);
+ // chart.setAutoFinish(true);
+ chart.setDrawGridBackground(false);
// add dummy-data to the chart
initWithDummyData();
- Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
-
- XAxis xl = mChart.getXAxis();
- xl.setTypeface(tf);
+ XAxis xl = chart.getXAxis();
+ xl.setTypeface(tfRegular);
xl.setAvoidFirstLastClipping(true);
- YAxis yl = mChart.getAxisLeft();
- yl.setTypeface(tf);
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfRegular);
- mChart.getLegend().setEnabled(false);
+ chart.getLegend().setEnabled(false);
- // mChart.setYRange(-40f, 40f, true);
+ // chart.setYRange(-40f, 40f, true);
// call this to reset the changed y-range
- // mChart.resetYRange(true);
+ // chart.resetYRange(true);
}
private void initWithDummyData() {
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
// create a dataset and give it a type (0)
- LineDataSet set1 = new LineDataSet(yVals, "DataSet");
+ LineDataSet set1 = new LineDataSet(values, "DataSet");
set1.setLineWidth(3f);
set1.setCircleRadius(5f);
- // create a data object with the datasets
+ // create a data object with the data sets
LineData data = new LineData(set1);
- mChart.setData(data);
+ chart.setData(data);
}
@Override
@@ -99,7 +101,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -108,39 +110,47 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
return true;
}
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "DrawChartActivity");
+ }
+
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.i("VAL SELECTED",
@@ -164,7 +174,7 @@ public void onDrawFinished(DataSet> dataSet) {
Log.i(Chart.LOG_TAG, "DataSet drawn. " + dataSet.toSimpleString());
// prepare the legend again
- mChart.getLegendRenderer().computeLegend(mChart.getData());
+ chart.getLegendRenderer().computeLegend(chart.getData());
}
@Override
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
similarity index 57%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
index f8f64c374f..84de449283 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
@@ -23,7 +28,7 @@
public class DynamicalAddingActivity extends DemoBase implements OnChartValueSelectedListener {
- private LineChart mChart;
+ private LineChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -32,24 +37,30 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
- mChart.getDescription().setEnabled(false);
+ setTitle("DynamicalAddingActivity");
- // add an empty data object
- mChart.setData(new LineData());
-// mChart.getXAxis().setDrawLabels(false);
-// mChart.getXAxis().setDrawGridLines(false);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ chart.setDrawGridBackground(false);
+ chart.getDescription().setEnabled(false);
+ chart.setNoDataText("No chart data available. Use the menu to add entries and data sets!");
- mChart.invalidate();
+// chart.getXAxis().setDrawLabels(false);
+// chart.getXAxis().setDrawGridLines(false);
+
+ chart.invalidate();
}
- int[] mColors = ColorTemplate.VORDIPLOM_COLORS;
+ private final int[] colors = ColorTemplate.VORDIPLOM_COLORS;
private void addEntry() {
- LineData data = mChart.getData();
+ LineData data = chart.getData();
+
+ if (data == null) {
+ data = new LineData();
+ chart.setData(data);
+ }
ILineDataSet set = data.getDataSetByIndex(0);
// set.addEntry(...); // can be called as well
@@ -61,25 +72,26 @@ private void addEntry() {
// choose a random dataSet
int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
- float yValue = (float) (Math.random() * 10) + 50f;
+ ILineDataSet randomSet = data.getDataSetByIndex(randomDataSetIndex);
+ float value = (float) (Math.random() * 50) + 50f * (randomDataSetIndex + 1);
- data.addEntry(new Entry(data.getDataSetByIndex(randomDataSetIndex).getEntryCount(), yValue), randomDataSetIndex);
+ data.addEntry(new Entry(randomSet.getEntryCount(), value), randomDataSetIndex);
data.notifyDataChanged();
// let the chart know it's data has changed
- mChart.notifyDataSetChanged();
+ chart.notifyDataSetChanged();
- mChart.setVisibleXRangeMaximum(6);
- //mChart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
-//
+ chart.setVisibleXRangeMaximum(6);
+ //chart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
+//
// // this automatically refreshes the chart (calls invalidate())
- mChart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
+ chart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
}
private void removeLastEntry() {
- LineData data = mChart.getData();
+ LineData data = chart.getData();
if (data != null) {
@@ -93,31 +105,33 @@ private void removeLastEntry() {
// or remove by index
// mData.removeEntryByXValue(xIndex, dataSetIndex);
data.notifyDataChanged();
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
}
}
}
private void addDataSet() {
- LineData data = mChart.getData();
-
- if (data != null) {
+ LineData data = chart.getData();
+ if (data == null) {
+ chart.setData(new LineData());
+ } else {
int count = (data.getDataSetCount() + 1);
+ int amount = data.getDataSetByIndex(0).getEntryCount();
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
- for (int i = 0; i < data.getEntryCount(); i++) {
- yVals.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
+ for (int i = 0; i < amount; i++) {
+ values.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
}
- LineDataSet set = new LineDataSet(yVals, "DataSet " + count);
+ LineDataSet set = new LineDataSet(values, "DataSet " + count);
set.setLineWidth(2.5f);
set.setCircleRadius(4.5f);
- int color = mColors[count % mColors.length];
+ int color = colors[count % colors.length];
set.setColor(color);
set.setCircleColor(color);
@@ -127,33 +141,45 @@ private void addDataSet() {
data.addDataSet(set);
data.notifyDataChanged();
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
}
}
private void removeDataSet() {
- LineData data = mChart.getData();
+ LineData data = chart.getData();
if (data != null) {
data.removeDataSet(data.getDataSetByIndex(data.getDataSetCount() - 1));
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
}
}
+ private LineDataSet createSet() {
+
+ LineDataSet set = new LineDataSet(null, "DataSet 1");
+ set.setLineWidth(2.5f);
+ set.setCircleRadius(4.5f);
+ set.setColor(Color.rgb(240, 99, 99));
+ set.setCircleColor(Color.rgb(240, 99, 99));
+ set.setHighLightColor(Color.rgb(190, 190, 190));
+ set.setAxisDependency(AxisDependency.LEFT);
+ set.setValueTextSize(10f);
+
+ return set;
+ }
+
@Override
public void onValueSelected(Entry e, Highlight h) {
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
@Override
- public void onNothingSelected() {
-
- }
+ public void onNothingSelected() {}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -165,47 +191,52 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.actionAddEntry:
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java"));
+ startActivity(i);
+ break;
+ }
+ case R.id.actionAddEntry: {
addEntry();
Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionRemoveEntry:
+ }
+ case R.id.actionRemoveEntry: {
removeLastEntry();
Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionAddDataSet:
+ }
+ case R.id.actionAddDataSet: {
addDataSet();
Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionRemoveDataSet:
+ }
+ case R.id.actionRemoveDataSet: {
removeDataSet();
Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionAddEmptyLineData:
- mChart.setData(new LineData());
- mChart.invalidate();
- Toast.makeText(this, "Empty data added!", Toast.LENGTH_SHORT).show();
- break;
- case R.id.actionClear:
- mChart.clear();
+ }
+ case R.id.actionClear: {
+ chart.clear();
Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show();
break;
+ }
+ case R.id.actionSave: {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
+ break;
+ }
}
return true;
}
- private LineDataSet createSet() {
-
- LineDataSet set = new LineDataSet(null, "DataSet 1");
- set.setLineWidth(2.5f);
- set.setCircleRadius(4.5f);
- set.setColor(Color.rgb(240, 99, 99));
- set.setCircleColor(Color.rgb(240, 99, 99));
- set.setHighLightColor(Color.rgb(190, 190, 190));
- set.setAxisDependency(AxisDependency.LEFT);
- set.setValueTextSize(10f);
-
- return set;
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "DynamicalAddingActivity");
}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
similarity index 50%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
index 9109d5d29c..e821a04969 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
@@ -1,8 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.LineChart;
@@ -19,10 +23,19 @@
import java.util.ArrayList;
+/**
+ * This works by inverting the background and desired "fill" color. First, we draw the fill color
+ * that we want between the lines as the actual background of the chart. Then, we fill the area
+ * above the highest line and the area under the lowest line with the desired background color.
+ *
+ * This method makes it look like we filled the area between the lines, but really we are filling
+ * the area OUTSIDE the lines!
+ */
+@SuppressWarnings("SameParameterValue")
public class FilledLineActivity extends DemoBase {
- private LineChart mChart;
- private int mFillColor = Color.argb(150, 51, 181, 229);
+ private LineChart chart;
+ private final int fillColor = Color.argb(150, 51, 181, 229);
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -31,73 +44,71 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setGridBackgroundColor(mFillColor);
- mChart.setDrawGridBackground(true);
+ setTitle("FilledLineActivity");
- mChart.setDrawBorders(true);
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setGridBackgroundColor(fillColor);
+ chart.setDrawGridBackground(true);
+
+ chart.setDrawBorders(true);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setEnabled(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setAxisMaximum(900f);
leftAxis.setAxisMinimum(-250f);
leftAxis.setDrawAxisLine(false);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(false);
- mChart.getAxisRight().setEnabled(false);
+ chart.getAxisRight().setEnabled(false);
// add data
setData(100, 60);
- mChart.invalidate();
+ chart.invalidate();
}
private void setData(int count, float range) {
- ArrayList yVals1 = new ArrayList();
+ ArrayList values1 = new ArrayList<>();
for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range) + 50;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals1.add(new Entry(i, val));
+ float val = (float) (Math.random() * range) + 50;
+ values1.add(new Entry(i, val));
}
- ArrayList yVals2 = new ArrayList();
+ ArrayList values2 = new ArrayList<>();
for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range) + 450;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals2.add(new Entry(i, val));
+ float val = (float) (Math.random() * range) + 450;
+ values2.add(new Entry(i, val));
}
LineDataSet set1, set2;
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
- set2 = (LineDataSet)mChart.getData().getDataSetByIndex(1);
- set1.setValues(yVals1);
- set2.setValues(yVals2);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set2 = (LineDataSet) chart.getData().getDataSetByIndex(1);
+ set1.setValues(values1);
+ set2.setValues(values2);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
- set1 = new LineDataSet(yVals1, "DataSet 1");
+ set1 = new LineDataSet(values1, "DataSet 1");
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setColor(Color.rgb(255, 241, 46));
@@ -112,12 +123,14 @@ private void setData(int count, float range) {
set1.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
- return mChart.getAxisLeft().getAxisMinimum();
+ // change the return value here to better understand the effect
+ // return 0;
+ return chart.getAxisLeft().getAxisMinimum();
}
});
// create a dataset and give it a type
- set2 = new LineDataSet(yVals2, "DataSet 2");
+ set2 = new LineDataSet(values2, "DataSet 2");
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
set2.setColor(Color.rgb(255, 241, 46));
set2.setDrawCircles(false);
@@ -131,20 +144,46 @@ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProv
set2.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
- return mChart.getAxisLeft().getAxisMaximum();
+ // change the return value here to better understand the effect
+ // return 600;
+ return chart.getAxisLeft().getAxisMaximum();
}
});
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1); // add the datasets
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1); // add the data sets
dataSets.add(set2);
- // create a data object with the datasets
+ // create a data object with the data sets
LineData data = new LineData(dataSets);
data.setDrawValues(false);
// set data
- mChart.setData(data);
+ chart.setData(data);
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
similarity index 55%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
index 38a228b322..ed2adcc960 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
@@ -1,22 +1,24 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
-import android.graphics.Point;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
-import android.view.Display;
+import android.util.DisplayMetrics;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
@@ -26,9 +28,10 @@
import java.util.ArrayList;
+@SuppressWarnings("SameParameterValue")
public class HalfPieChartActivity extends DemoBase {
- private PieChart mChart;
+ private PieChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -37,40 +40,42 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart_half);
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
+ setTitle("HalfPieChartActivity");
+
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
moveOffScreen();
- mChart.setUsePercentValues(true);
- mChart.getDescription().setEnabled(false);
+ chart.setUsePercentValues(true);
+ chart.getDescription().setEnabled(false);
- mChart.setCenterTextTypeface(mTfLight);
- mChart.setCenterText(generateCenterSpannableText());
+ chart.setCenterTextTypeface(tfLight);
+ chart.setCenterText(generateCenterSpannableText());
- mChart.setDrawHoleEnabled(true);
- mChart.setHoleColor(Color.WHITE);
+ chart.setDrawHoleEnabled(true);
+ chart.setHoleColor(Color.WHITE);
- mChart.setTransparentCircleColor(Color.WHITE);
- mChart.setTransparentCircleAlpha(110);
+ chart.setTransparentCircleColor(Color.WHITE);
+ chart.setTransparentCircleAlpha(110);
- mChart.setHoleRadius(58f);
- mChart.setTransparentCircleRadius(61f);
+ chart.setHoleRadius(58f);
+ chart.setTransparentCircleRadius(61f);
- mChart.setDrawCenterText(true);
+ chart.setDrawCenterText(true);
- mChart.setRotationEnabled(false);
- mChart.setHighlightPerTapEnabled(true);
+ chart.setRotationEnabled(false);
+ chart.setHighlightPerTapEnabled(true);
- mChart.setMaxAngle(180f); // HALF CHART
- mChart.setRotationAngle(180f);
- mChart.setCenterTextOffset(0, -20);
+ chart.setMaxAngle(180f); // HALF CHART
+ chart.setRotationAngle(180f);
+ chart.setCenterTextOffset(0, -20);
setData(4, 100);
- mChart.animateY(1400, Easing.EaseInOutQuad);
+ chart.animateY(1400, Easing.EaseInOutQuad);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -80,17 +85,17 @@ protected void onCreate(Bundle savedInstanceState) {
l.setYOffset(0f);
// entry label styling
- mChart.setEntryLabelColor(Color.WHITE);
- mChart.setEntryLabelTypeface(mTfRegular);
- mChart.setEntryLabelTextSize(12f);
+ chart.setEntryLabelColor(Color.WHITE);
+ chart.setEntryLabelTypeface(tfRegular);
+ chart.setEntryLabelTextSize(12f);
}
private void setData(int count, float range) {
- ArrayList values = new ArrayList();
+ ArrayList values = new ArrayList<>();
for (int i = 0; i < count; i++) {
- values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.length]));
+ values.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.length]));
}
PieDataSet dataSet = new PieDataSet(values, "Election Results");
@@ -104,10 +109,10 @@ private void setData(int count, float range) {
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.WHITE);
- data.setValueTypeface(mTfLight);
- mChart.setData(data);
+ data.setValueTypeface(tfLight);
+ chart.setData(data);
- mChart.invalidate();
+ chart.invalidate();
}
private SpannableString generateCenterSpannableText() {
@@ -124,14 +129,40 @@ private SpannableString generateCenterSpannableText() {
private void moveOffScreen() {
- Display display = getWindowManager().getDefaultDisplay();
- int height = display.getHeight(); // deprecated
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+
+ int height = displayMetrics.heightPixels;
int offset = (int)(height * 0.65); /* percent to move */
RelativeLayout.LayoutParams rlParams =
- (RelativeLayout.LayoutParams)mChart.getLayoutParams();
+ (RelativeLayout.LayoutParams) chart.getLayoutParams();
rlParams.setMargins(0, 0, 0, -offset);
- mChart.setLayoutParams(rlParams);
+ chart.setLayoutParams(rlParams);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
}
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
similarity index 55%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
index 95e138aade..27f7f29627 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
@@ -1,9 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
-import android.annotation.SuppressLint;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.RectF;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -11,11 +15,9 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.components.YAxis;
@@ -35,8 +37,8 @@
public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- protected HorizontalBarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private HorizontalBarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -46,67 +48,68 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_horizontalbarchart);
+ setTitle("HorizontalBarChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- // mChart.setHighlightEnabled(false);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ // chart.setHighlightEnabled(false);
- mChart.setDrawBarShadow(false);
+ chart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart.setDrawValueAboveBar(true);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
- // mChart.setDrawBarShadow(true);
+ // chart.setDrawBarShadow(true);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- XAxis xl = mChart.getXAxis();
+ XAxis xl = chart.getXAxis();
xl.setPosition(XAxisPosition.BOTTOM);
- xl.setTypeface(mTfLight);
+ xl.setTypeface(tfLight);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
xl.setGranularity(10f);
- YAxis yl = mChart.getAxisLeft();
- yl.setTypeface(mTfLight);
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfLight);
yl.setDrawAxisLine(true);
yl.setDrawGridLines(true);
yl.setAxisMinimum(0f); // this replaces setStartAtZero(true)
// yl.setInverted(true);
- YAxis yr = mChart.getAxisRight();
- yr.setTypeface(mTfLight);
+ YAxis yr = chart.getAxisRight();
+ yr.setTypeface(tfLight);
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
yr.setAxisMinimum(0f); // this replaces setStartAtZero(true)
// yr.setInverted(true);
- setData(12, 50);
- mChart.setFitBars(true);
- mChart.animateY(2500);
+ chart.setFitBars(true);
+ chart.animateY(2500);
// setting data
- mSeekBarY.setProgress(50);
- mSeekBarX.setProgress(12);
+ seekBarY.setProgress(50);
+ seekBarX.setProgress(12);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
-
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -115,6 +118,42 @@ protected void onCreate(Bundle savedInstanceState) {
l.setXEntrySpace(4f);
}
+ private void setData(int count, float range) {
+
+ float barWidth = 9f;
+ float spaceForBar = 10f;
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range);
+ values.add(new BarEntry(i * spaceForBar, val,
+ getResources().getDrawable(R.drawable.star)));
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set1 = new BarDataSet(values, "DataSet 1");
+
+ set1.setDrawIcons(false);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
+
+ BarData data = new BarData(dataSets);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setBarWidth(barWidth);
+ chart.setData(data);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
@@ -125,80 +164,80 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
-
- IBarDataSet set = (BarDataSet) iSet;
- set.setDrawValues(!set.isDrawValuesEnabled());
+ iSet.setDrawValues(!iSet.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
-
- IBarDataSet set = (BarDataSet) iSet;
- set.setDrawIcons(!set.isDrawIconsEnabled());
+ iSet.setDrawIcons(!iSet.isDrawIconsEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -208,64 +247,27 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
- mChart.setFitBars(true);
- mChart.invalidate();
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
+ chart.setFitBars(true);
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ protected void saveToGallery() {
+ saveToGallery(chart, "HorizontalBarChartActivity");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- float barWidth = 9f;
- float spaceForBar = 10f;
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- yVals1.add(new BarEntry(i * spaceForBar, val,
- getResources().getDrawable(R.drawable.star)));
- }
-
- BarDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals1);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set1 = new BarDataSet(yVals1, "DataSet 1");
-
- set1.setDrawIcons(false);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1);
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
- BarData data = new BarData(dataSets);
- data.setValueTextSize(10f);
- data.setValueTypeface(mTfLight);
- data.setBarWidth(barWidth);
- mChart.setData(data);
- }
- }
+ private final RectF mOnValueSelectedRectF = new RectF();
- protected RectF mOnValueSelectedRectF = new RectF();
- @SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
@@ -273,9 +275,9 @@ public void onValueSelected(Entry e, Highlight h) {
return;
RectF bounds = mOnValueSelectedRectF;
- mChart.getBarBounds((BarEntry) e, bounds);
+ chart.getBarBounds((BarEntry) e, bounds);
- MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
+ MPPointF position = chart.getPosition(e, chart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency());
Log.i("bounds", bounds.toString());
@@ -285,6 +287,5 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- };
+ public void onNothingSelected() {}
}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java
new file mode 100644
index 0000000000..86d578cc43
--- /dev/null
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java
@@ -0,0 +1,292 @@
+
+package com.xxmassdeveloper.mpchartexample;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.RectF;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.WindowManager;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.core.content.ContextCompat;
+
+import com.github.mikephil.charting.charts.HorizontalBarChart;
+import com.github.mikephil.charting.components.Legend;
+import com.github.mikephil.charting.components.XAxis;
+import com.github.mikephil.charting.components.XAxis.XAxisPosition;
+import com.github.mikephil.charting.components.YAxis;
+import com.github.mikephil.charting.data.BarData;
+import com.github.mikephil.charting.data.BarDataSet;
+import com.github.mikephil.charting.data.BarEntry;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.highlight.Highlight;
+import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
+import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
+import com.github.mikephil.charting.utils.MPPointF;
+import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class HorizontalBarNegativeChartActivity extends DemoBase implements OnSeekBarChangeListener,
+ OnChartValueSelectedListener {
+
+ private HorizontalBarChart chart;
+ private SeekBar seekBarX, seekBarY;
+ private TextView tvX, tvY;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setContentView(R.layout.activity_horizontalbarchart);
+
+ setTitle("HorizontalBarChartActivity");
+
+ tvX = findViewById(R.id.tvXMax);
+ tvY = findViewById(R.id.tvYMax);
+
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
+
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ // chart.setHighlightEnabled(false);
+
+ chart.setDrawBarShadow(false);
+
+ chart.setDrawValueAboveBar(true);
+
+ chart.getDescription().setEnabled(false);
+
+ // if more than 60 entries are displayed in the chart, no values will be
+ // drawn
+ chart.setMaxVisibleValueCount(60);
+
+ // scaling can now only be done on x- and y-axis separately
+ chart.setPinchZoom(false);
+
+ // draw shadows for each bar that show the maximum value
+ // chart.setDrawBarShadow(true);
+
+ chart.setDrawGridBackground(false);
+
+ XAxis xl = chart.getXAxis();
+ xl.setPosition(XAxisPosition.BOTTOM);
+ xl.setTypeface(tfLight);
+ xl.setDrawAxisLine(true);
+ xl.setDrawGridLines(false);
+ xl.setGranularity(10f);
+
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfLight);
+ yl.setDrawAxisLine(true);
+ yl.setDrawGridLines(true);
+// yl.setInverted(true);
+
+ YAxis yr = chart.getAxisRight();
+ yr.setTypeface(tfLight);
+ yr.setDrawAxisLine(true);
+ yr.setDrawGridLines(false);
+// yr.setInverted(true);
+
+ chart.setFitBars(true);
+ chart.animateY(2500);
+
+ // setting data
+ seekBarY.setProgress(50);
+ seekBarX.setProgress(12);
+
+ Legend l = chart.getLegend();
+ l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
+ l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
+ l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
+ l.setDrawInside(false);
+ l.setFormSize(8f);
+ l.setXEntrySpace(4f);
+ }
+
+ private void setData(int count, float range) {
+
+ float barWidth = 9f;
+ float spaceForBar = 10f;
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range - range / 2);
+ values.add(new BarEntry(i * spaceForBar, val,
+ getResources().getDrawable(R.drawable.star)));
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set1 = new BarDataSet(values, "DataSet 1");
+
+ set1.setDrawIcons(false);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
+
+ BarData data = new BarData(dataSets);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setBarWidth(barWidth);
+ chart.setData(data);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.bar, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
+ case R.id.actionToggleValues: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (IBarDataSet iSet : sets) {
+ iSet.setDrawValues(!iSet.isDrawValuesEnabled());
+ }
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleIcons: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (IBarDataSet iSet : sets) {
+ iSet.setDrawIcons(!iSet.isDrawIconsEnabled());
+ }
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleHighlight: {
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
+ }
+ break;
+ }
+ case R.id.actionTogglePinch: {
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
+ else
+ chart.setPinchZoom(true);
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleAutoScaleMinMax: {
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
+ break;
+ }
+ case R.id.actionToggleBarBorders: {
+ for (IBarDataSet set : chart.getData().getDataSets())
+ ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.animateX: {
+ chart.animateX(2000);
+ break;
+ }
+ case R.id.animateY: {
+ chart.animateY(2000);
+ break;
+ }
+ case R.id.animateXY: {
+ chart.animateXY(2000, 2000);
+ break;
+ }
+ case R.id.actionSave: {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
+ break;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
+ chart.setFitBars(true);
+ chart.invalidate();
+ }
+
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "HorizontalBarChartActivity");
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {}
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
+
+ private final RectF mOnValueSelectedRectF = new RectF();
+
+ @Override
+ public void onValueSelected(Entry e, Highlight h) {
+
+ if (e == null)
+ return;
+
+ RectF bounds = mOnValueSelectedRectF;
+ chart.getBarBounds((BarEntry) e, bounds);
+
+ MPPointF position = chart.getPosition(e, chart.getData().getDataSetByIndex(h.getDataSetIndex())
+ .getAxisDependency());
+
+ Log.i("bounds", bounds.toString());
+ Log.i("position", position.toString());
+
+ MPPointF.recycleInstance(position);
+ }
+
+ @Override
+ public void onNothingSelected() {}
+}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
similarity index 62%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
index 4ad4e691ef..08983710f2 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
@@ -1,7 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -9,7 +14,6 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
@@ -33,8 +37,8 @@
public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -44,72 +48,98 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("InvertedLineChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ chart.setDrawGridBackground(false);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
-
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
// set an alternative background color
- // mChart.setBackgroundColor(Color.GRAY);
+ // chart.setBackgroundColor(Color.GRAY);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
-
- XAxis xl = mChart.getXAxis();
+ mv.setChartView(chart); // For bounds control
+ chart.setMarker(mv); // Set the marker to the chart
+
+ XAxis xl = chart.getXAxis();
xl.setAvoidFirstLastClipping(true);
xl.setAxisMinimum(0f);
-
- YAxis leftAxis = mChart.getAxisLeft();
+
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setInverted(true);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
-
- YAxis rightAxis = mChart.getAxisRight();
+
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// add data
- setData(25, 50);
+ seekBarX.setProgress(25);
+ seekBarY.setProgress(50);
// // restrain the maximum scale-out factor
- // mChart.setScaleMinima(3f, 3f);
+ // chart.setScaleMinima(3f, 3f);
//
// // center the view to a specific position inside the chart
- // mChart.centerViewPort(10, 50);
+ // chart.centerViewPort(10, 50);
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
- // dont forget to refresh the drawing
- mChart.invalidate();
+ // don't forget to refresh the drawing
+ chart.invalidate();
+ }
+
+ private void setData(int count, float range) {
+
+ ArrayList entries = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float xVal = (float) (Math.random() * range);
+ float yVal = (float) (Math.random() * range);
+ entries.add(new Entry(xVal, yVal));
+ }
+
+ // sort by x-value
+ Collections.sort(entries, new EntryXComparator());
+
+ // create a dataset and give it a type
+ LineDataSet set1 = new LineDataSet(entries, "DataSet 1");
+
+ set1.setLineWidth(1.5f);
+ set1.setCircleRadius(4f);
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1);
+
+ // set data
+ chart.setData(data);
}
@Override
@@ -122,8 +152,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -132,19 +168,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -155,11 +191,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -170,45 +206,42 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -218,13 +251,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
+ chart.invalidate();
+ }
+
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "InvertedLineChartActivity");
}
@Override
@@ -235,46 +273,11 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- // TODO Auto-generated method stub
-
- }
+ public void onNothingSelected() {}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList entries = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float xVal = (float) (Math.random() * range);
- float yVal = (float) (Math.random() * range);
- entries.add(new Entry(xVal, yVal));
- }
-
- // sort by x-value
- Collections.sort(entries, new EntryXComparator());
-
- // create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(entries, "DataSet 1");
-
- set1.setLineWidth(1.5f);
- set1.setCircleRadius(4f);
-
- // create a data object with the datasets
- LineData data = new LineData(set1);
-
- // set data
- mChart.setData(data);
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
new file mode 100644
index 0000000000..dd43b056eb
--- /dev/null
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
@@ -0,0 +1,454 @@
+
+package com.xxmassdeveloper.mpchartexample;
+
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.graphics.DashPathEffect;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.os.Bundle;
+import androidx.core.content.ContextCompat;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.WindowManager;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+
+import com.github.mikephil.charting.animation.Easing;
+import com.github.mikephil.charting.charts.LineChart;
+import com.github.mikephil.charting.components.Legend;
+import com.github.mikephil.charting.components.Legend.LegendForm;
+import com.github.mikephil.charting.components.LimitLine;
+import com.github.mikephil.charting.components.LimitLine.LimitLabelPosition;
+import com.github.mikephil.charting.components.XAxis;
+import com.github.mikephil.charting.components.YAxis;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.data.LineData;
+import com.github.mikephil.charting.data.LineDataSet;
+import com.github.mikephil.charting.formatter.IFillFormatter;
+import com.github.mikephil.charting.highlight.Highlight;
+import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
+import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
+import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
+import com.github.mikephil.charting.utils.Utils;
+import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
+import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Example of a heavily customized {@link LineChart} with limit lines, custom line shapes, etc.
+ *
+ * @since 1.7.4
+ * @version 3.1.0
+ */
+public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListener,
+ OnChartValueSelectedListener {
+
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
+ private TextView tvX, tvY;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setContentView(R.layout.activity_linechart);
+
+ setTitle("LineChartActivity1");
+
+ tvX = findViewById(R.id.tvXMax);
+ tvY = findViewById(R.id.tvYMax);
+
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
+
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setMax(180);
+ seekBarY.setOnSeekBarChangeListener(this);
+
+
+ { // // Chart Style // //
+ chart = findViewById(R.id.chart1);
+
+ // background color
+ chart.setBackgroundColor(Color.WHITE);
+
+ // disable description text
+ chart.getDescription().setEnabled(false);
+
+ // enable touch gestures
+ chart.setTouchEnabled(true);
+
+ // set listeners
+ chart.setOnChartValueSelectedListener(this);
+ chart.setDrawGridBackground(false);
+
+ // create marker to display box when values are selected
+ MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
+
+ // Set the marker to the chart
+ mv.setChartView(chart);
+ chart.setMarker(mv);
+
+ // enable scaling and dragging
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
+ // chart.setScaleXEnabled(true);
+ // chart.setScaleYEnabled(true);
+
+ // force pinch zoom along both axis
+ chart.setPinchZoom(true);
+ }
+
+ XAxis xAxis;
+ { // // X-Axis Style // //
+ xAxis = chart.getXAxis();
+
+ // vertical grid lines
+ xAxis.enableGridDashedLine(10f, 10f, 0f);
+ }
+
+ YAxis yAxis;
+ { // // Y-Axis Style // //
+ yAxis = chart.getAxisLeft();
+
+ // disable dual axis (only use LEFT axis)
+ chart.getAxisRight().setEnabled(false);
+
+ // horizontal grid lines
+ yAxis.enableGridDashedLine(10f, 10f, 0f);
+
+ // axis range
+ yAxis.setAxisMaximum(200f);
+ yAxis.setAxisMinimum(-50f);
+ }
+
+
+ { // // Create Limit Lines // //
+ LimitLine llXAxis = new LimitLine(9f, "Index 10");
+ llXAxis.setLineWidth(4f);
+ llXAxis.enableDashedLine(10f, 10f, 0f);
+ llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
+ llXAxis.setTextSize(10f);
+ llXAxis.setTypeface(tfRegular);
+
+ LimitLine ll1 = new LimitLine(150f, "Upper Limit");
+ ll1.setLineWidth(4f);
+ ll1.enableDashedLine(10f, 10f, 0f);
+ ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
+ ll1.setTextSize(10f);
+ ll1.setTypeface(tfRegular);
+
+ LimitLine ll2 = new LimitLine(-30f, "Lower Limit");
+ ll2.setLineWidth(4f);
+ ll2.enableDashedLine(10f, 10f, 0f);
+ ll2.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
+ ll2.setTextSize(10f);
+ ll2.setTypeface(tfRegular);
+
+ // draw limit lines behind data instead of on top
+ yAxis.setDrawLimitLinesBehindData(true);
+ xAxis.setDrawLimitLinesBehindData(true);
+
+ // add limit lines
+ yAxis.addLimitLine(ll1);
+ yAxis.addLimitLine(ll2);
+ //xAxis.addLimitLine(llXAxis);
+ }
+
+ // add data
+ seekBarX.setProgress(45);
+ seekBarY.setProgress(180);
+ setData(45, 180);
+
+ // draw points over time
+ chart.animateX(1500);
+
+ // get the legend (only possible after setting data)
+ Legend l = chart.getLegend();
+
+ // draw legend entries as lines
+ l.setForm(LegendForm.LINE);
+ }
+
+ private void setData(int count, float range) {
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+
+ float val = (float) (Math.random() * range) - 30;
+ values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
+ }
+
+ LineDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ set1.notifyDataSetChanged();
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ // create a dataset and give it a type
+ set1 = new LineDataSet(values, "DataSet 1");
+
+ set1.setDrawIcons(false);
+
+ // draw dashed line
+ set1.enableDashedLine(10f, 5f, 0f);
+
+ // black lines and points
+ set1.setColor(Color.BLACK);
+ set1.setCircleColor(Color.BLACK);
+
+ // line thickness and point size
+ set1.setLineWidth(1f);
+ set1.setCircleRadius(3f);
+
+ // draw points as solid circles
+ set1.setDrawCircleHole(false);
+
+ // customize legend entry
+ set1.setFormLineWidth(1f);
+ set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
+ set1.setFormSize(15.f);
+
+ // text size of values
+ set1.setValueTextSize(9f);
+
+ // draw selection line as dashed
+ set1.enableDashedHighlightLine(10f, 5f, 0f);
+
+ // set the filled area
+ set1.setDrawFilled(true);
+ set1.setFillFormatter(new IFillFormatter() {
+ @Override
+ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
+ return chart.getAxisLeft().getAxisMinimum();
+ }
+ });
+
+ // set color of filled area
+ if (Utils.getSDKInt() >= 18) {
+ // drawables only supported on api level 18 and above
+ Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
+ set1.setFillDrawable(drawable);
+ } else {
+ set1.setFillColor(Color.BLACK);
+ }
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1); // add the data sets
+
+ // create a data object with the data sets
+ LineData data = new LineData(dataSets);
+
+ // set data
+ chart.setData(data);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.line, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java"));
+ startActivity(i);
+ break;
+ }
+ case R.id.actionToggleValues: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setDrawValues(!set.isDrawValuesEnabled());
+ }
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleIcons: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setDrawIcons(!set.isDrawIconsEnabled());
+ }
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleHighlight: {
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
+ }
+ break;
+ }
+ case R.id.actionToggleFilled: {
+
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ if (set.isDrawFilledEnabled())
+ set.setDrawFilled(false);
+ else
+ set.setDrawFilled(true);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleCircles: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ if (set.isDrawCirclesEnabled())
+ set.setDrawCircles(false);
+ else
+ set.setDrawCircles(true);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleCubic: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER
+ ? LineDataSet.Mode.LINEAR
+ : LineDataSet.Mode.CUBIC_BEZIER);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleStepped: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setMode(set.getMode() == LineDataSet.Mode.STEPPED
+ ? LineDataSet.Mode.LINEAR
+ : LineDataSet.Mode.STEPPED);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleHorizontalCubic: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER
+ ? LineDataSet.Mode.LINEAR
+ : LineDataSet.Mode.HORIZONTAL_BEZIER);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionTogglePinch: {
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
+ else
+ chart.setPinchZoom(true);
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleAutoScaleMinMax: {
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
+ break;
+ }
+ case R.id.animateX: {
+ chart.animateX(2000);
+ break;
+ }
+ case R.id.animateY: {
+ chart.animateY(2000, Easing.EaseInCubic);
+ break;
+ }
+ case R.id.animateXY: {
+ chart.animateXY(2000, 2000);
+ break;
+ }
+ case R.id.actionSave: {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
+ break;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
+
+ // redraw
+ chart.invalidate();
+ }
+
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "LineChartActivity1");
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {}
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
+
+ @Override
+ public void onValueSelected(Entry e, Highlight h) {
+ Log.i("Entry selected", e.toString());
+ Log.i("LOW HIGH", "low: " + chart.getLowestVisibleX() + ", high: " + chart.getHighestVisibleX());
+ Log.i("MIN MAX", "xMin: " + chart.getXChartMin() + ", xMax: " + chart.getXChartMax() + ", yMin: " + chart.getYChartMin() + ", yMax: " + chart.getYChartMax());
+ }
+
+ @Override
+ public void onNothingSelected() {
+ Log.i("Nothing selected", "Nothing selected.");
+ }
+}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
similarity index 62%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
index e2a381ff91..6b9cbb5f22 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -10,7 +15,6 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
@@ -30,11 +34,17 @@
import java.util.ArrayList;
import java.util.List;
+/**
+ * Example of a dual axis {@link LineChart} with multiple data sets.
+ *
+ * @since 1.7.4
+ * @version 3.1.0
+ */
public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -44,51 +54,52 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("LineChartActivity2");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
- mChart.setDragDecelerationFrictionCoef(0.9f);
+ chart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
- mChart.setDrawGridBackground(false);
- mChart.setHighlightPerDragEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
+ chart.setDrawGridBackground(false);
+ chart.setHighlightPerDragEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
// set an alternative background color
- mChart.setBackgroundColor(Color.LTGRAY);
+ chart.setBackgroundColor(Color.LTGRAY);
// add data
- setData(20, 30);
+ seekBarX.setProgress(20);
+ seekBarY.setProgress(30);
- mChart.animateX(2500);
+ chart.animateX(1500);
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
l.setTextSize(11f);
l.setTextColor(Color.WHITE);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
@@ -97,23 +108,23 @@ protected void onCreate(Bundle savedInstanceState) {
l.setDrawInside(false);
// l.setYOffset(11f);
- XAxis xAxis = mChart.getXAxis();
- xAxis.setTypeface(mTfLight);
+ XAxis xAxis = chart.getXAxis();
+ xAxis.setTypeface(tfLight);
xAxis.setTextSize(11f);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setAxisMaximum(200f);
leftAxis.setAxisMinimum(0f);
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
- YAxis rightAxis = mChart.getAxisRight();
- rightAxis.setTypeface(mTfLight);
+ YAxis rightAxis = chart.getAxisRight();
+ rightAxis.setTypeface(tfLight);
rightAxis.setTextColor(Color.RED);
rightAxis.setAxisMaximum(900);
rightAxis.setAxisMinimum(-200);
@@ -122,6 +133,93 @@ protected void onCreate(Bundle savedInstanceState) {
rightAxis.setGranularityEnabled(false);
}
+ private void setData(int count, float range) {
+
+ ArrayList values1 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * (range / 2f)) + 50;
+ values1.add(new Entry(i, val));
+ }
+
+ ArrayList values2 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range) + 450;
+ values2.add(new Entry(i, val));
+ }
+
+ ArrayList values3 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range) + 500;
+ values3.add(new Entry(i, val));
+ }
+
+ LineDataSet set1, set2, set3;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set2 = (LineDataSet) chart.getData().getDataSetByIndex(1);
+ set3 = (LineDataSet) chart.getData().getDataSetByIndex(2);
+ set1.setValues(values1);
+ set2.setValues(values2);
+ set3.setValues(values3);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ // create a dataset and give it a type
+ set1 = new LineDataSet(values1, "DataSet 1");
+
+ set1.setAxisDependency(AxisDependency.LEFT);
+ set1.setColor(ColorTemplate.getHoloBlue());
+ set1.setCircleColor(Color.WHITE);
+ set1.setLineWidth(2f);
+ set1.setCircleRadius(3f);
+ set1.setFillAlpha(65);
+ set1.setFillColor(ColorTemplate.getHoloBlue());
+ set1.setHighLightColor(Color.rgb(244, 117, 117));
+ set1.setDrawCircleHole(false);
+ //set1.setFillFormatter(new MyFillFormatter(0f));
+ //set1.setDrawHorizontalHighlightIndicator(false);
+ //set1.setVisible(false);
+ //set1.setCircleHoleColor(Color.WHITE);
+
+ // create a dataset and give it a type
+ set2 = new LineDataSet(values2, "DataSet 2");
+ set2.setAxisDependency(AxisDependency.RIGHT);
+ set2.setColor(Color.RED);
+ set2.setCircleColor(Color.WHITE);
+ set2.setLineWidth(2f);
+ set2.setCircleRadius(3f);
+ set2.setFillAlpha(65);
+ set2.setFillColor(Color.RED);
+ set2.setDrawCircleHole(false);
+ set2.setHighLightColor(Color.rgb(244, 117, 117));
+ //set2.setFillFormatter(new MyFillFormatter(900f));
+
+ set3 = new LineDataSet(values3, "DataSet 3");
+ set3.setAxisDependency(AxisDependency.RIGHT);
+ set3.setColor(Color.YELLOW);
+ set3.setCircleColor(Color.WHITE);
+ set3.setLineWidth(2f);
+ set3.setCircleRadius(3f);
+ set3.setFillAlpha(65);
+ set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
+ set3.setDrawCircleHole(false);
+ set3.setHighLightColor(Color.rgb(244, 117, 117));
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1, set2, set3);
+ data.setValueTextColor(Color.WHITE);
+ data.setValueTextSize(9f);
+
+ // set data
+ chart.setData(data);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
@@ -132,8 +230,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -142,19 +246,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -165,11 +269,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -180,11 +284,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -194,11 +298,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -208,11 +312,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHorizontalCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -222,46 +326,41 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
- //mChart.highlightValue(9.7f, 1, false);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
-
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -271,117 +370,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
+ chart.invalidate();
}
- private void setData(int count, float range) {
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = range / 2f;
- float val = (float) (Math.random() * mult) + 50;
- yVals1.add(new Entry(i, val));
- }
-
- ArrayList yVals2 = new ArrayList();
-
- for (int i = 0; i < count-1; i++) {
- float mult = range;
- float val = (float) (Math.random() * mult) + 450;
- yVals2.add(new Entry(i, val));
-// if(i == 10) {
-// yVals2.add(new Entry(i, val + 50));
-// }
- }
-
- ArrayList yVals3 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = range;
- float val = (float) (Math.random() * mult) + 500;
- yVals3.add(new Entry(i, val));
- }
-
- LineDataSet set1, set2, set3;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
- set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
- set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2);
- set1.setValues(yVals1);
- set2.setValues(yVals2);
- set3.setValues(yVals3);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- // create a dataset and give it a type
- set1 = new LineDataSet(yVals1, "DataSet 1");
-
- set1.setAxisDependency(AxisDependency.LEFT);
- set1.setColor(ColorTemplate.getHoloBlue());
- set1.setCircleColor(Color.WHITE);
- set1.setLineWidth(2f);
- set1.setCircleRadius(3f);
- set1.setFillAlpha(65);
- set1.setFillColor(ColorTemplate.getHoloBlue());
- set1.setHighLightColor(Color.rgb(244, 117, 117));
- set1.setDrawCircleHole(false);
- //set1.setFillFormatter(new MyFillFormatter(0f));
- //set1.setDrawHorizontalHighlightIndicator(false);
- //set1.setVisible(false);
- //set1.setCircleHoleColor(Color.WHITE);
-
- // create a dataset and give it a type
- set2 = new LineDataSet(yVals2, "DataSet 2");
- set2.setAxisDependency(AxisDependency.RIGHT);
- set2.setColor(Color.RED);
- set2.setCircleColor(Color.WHITE);
- set2.setLineWidth(2f);
- set2.setCircleRadius(3f);
- set2.setFillAlpha(65);
- set2.setFillColor(Color.RED);
- set2.setDrawCircleHole(false);
- set2.setHighLightColor(Color.rgb(244, 117, 117));
- //set2.setFillFormatter(new MyFillFormatter(900f));
-
- set3 = new LineDataSet(yVals3, "DataSet 3");
- set3.setAxisDependency(AxisDependency.RIGHT);
- set3.setColor(Color.YELLOW);
- set3.setCircleColor(Color.WHITE);
- set3.setLineWidth(2f);
- set3.setCircleRadius(3f);
- set3.setFillAlpha(65);
- set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
- set3.setDrawCircleHole(false);
- set3.setHighLightColor(Color.rgb(244, 117, 117));
-
- // create a data object with the datasets
- LineData data = new LineData(set1, set2, set3);
- data.setValueTextColor(Color.WHITE);
- data.setValueTextSize(9f);
-
- // set data
- mChart.setData(data);
- }
+ @Override
+ protected void saveToGallery() {
+ saveToGallery(chart, "LineChartActivity2");
}
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.i("Entry selected", e.toString());
- mChart.centerViewToAnimated(e.getX(), e.getY(), mChart.getData().getDataSetByIndex(h.getDataSetIndex())
+ chart.centerViewToAnimated(e.getX(), e.getY(), chart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency(), 500);
- //mChart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex)
+ //chart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex)
// .getAxisDependency(), 1000);
- //mChart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex)
+ //chart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex)
// .getAxisDependency(), 1000);
}
@@ -391,14 +402,8 @@ public void onNothingSelected() {
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
similarity index 63%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
index 39730d55b1..6a12e8f95d 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
@@ -1,9 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.LineChart;
@@ -15,10 +19,10 @@
import java.util.ArrayList;
+@SuppressWarnings("SameParameterValue")
public class LineChartActivityColored extends DemoBase {
- private LineChart[] mCharts = new LineChart[4];
- private Typeface mTf;
+ private final LineChart[] charts = new LineChart[4];
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -27,26 +31,28 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_colored_lines);
- mCharts[0] = findViewById(R.id.chart1);
- mCharts[1] = findViewById(R.id.chart2);
- mCharts[2] = findViewById(R.id.chart3);
- mCharts[3] = findViewById(R.id.chart4);
+ setTitle("LineChartActivityColored");
- mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");
+ charts[0] = findViewById(R.id.chart1);
+ charts[1] = findViewById(R.id.chart2);
+ charts[2] = findViewById(R.id.chart3);
+ charts[3] = findViewById(R.id.chart4);
- for (int i = 0; i < mCharts.length; i++) {
+ Typeface mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");
+
+ for (int i = 0; i < charts.length; i++) {
LineData data = getData(36, 100);
data.setValueTypeface(mTf);
// add some transparency to the color with "& 0x90FFFFFF"
- setupChart(mCharts[i], data, mColors[i % mColors.length]);
+ setupChart(charts[i], data, colors[i % colors.length]);
}
}
- private int[] mColors = new int[] {
- Color.rgb(137, 230, 81),
- Color.rgb(240, 240, 30),
+ private final int[] colors = new int[] {
+ Color.rgb(137, 230, 81),
+ Color.rgb(240, 240, 30),
Color.rgb(89, 199, 250),
Color.rgb(250, 104, 104)
};
@@ -57,8 +63,8 @@ private void setupChart(LineChart chart, LineData data, int color) {
// no description text
chart.getDescription().setEnabled(false);
-
- // mChart.setDrawHorizontalGrid(false);
+
+ // chart.setDrawHorizontalGrid(false);
//
// enable / disable grid background
chart.setDrawGridBackground(false);
@@ -75,7 +81,7 @@ private void setupChart(LineChart chart, LineData data, int color) {
chart.setPinchZoom(false);
chart.setBackgroundColor(color);
-
+
// set custom chart offsets (automatic offset calculation is hereby disabled)
chart.setViewPortOffsets(10, 0, 10, 0);
@@ -96,18 +102,18 @@ private void setupChart(LineChart chart, LineData data, int color) {
// animate calls invalidate()...
chart.animateX(2500);
}
-
+
private LineData getData(int count, float range) {
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) + 3;
- yVals.add(new Entry(i, val));
+ values.add(new Entry(i, val));
}
// create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
+ LineDataSet set1 = new LineDataSet(values, "DataSet 1");
// set1.setFillAlpha(110);
// set1.setFillColor(Color.RED);
@@ -119,9 +125,31 @@ private LineData getData(int count, float range) {
set1.setHighLightColor(Color.WHITE);
set1.setDrawValues(false);
- // create a data object with the datasets
- LineData data = new LineData(set1);
+ // create a data object with the data sets
+ return new LineData(set1);
+ }
- return data;
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
}
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java
similarity index 67%
rename from MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java
rename to MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java
index 6bf96f02a7..212b90ff87 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java
@@ -1,15 +1,19 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
@@ -25,17 +29,17 @@
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.concurrent.TimeUnit;
public class LineChartTime extends DemoBase implements OnSeekBarChangeListener {
- private LineChart mChart;
- private SeekBar mSeekBarX;
+ private LineChart chart;
+ private SeekBar seekBarX;
private TextView tvX;
@Override
@@ -45,44 +49,42 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_time);
- tvX = findViewById(R.id.tvXMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setProgress(100);
- tvX.setText("100");
+ setTitle("LineChartTime");
- mSeekBarX.setOnSeekBarChangeListener(this);
+ tvX = findViewById(R.id.tvXMax);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
+ chart = findViewById(R.id.chart1);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
- mChart.setDragDecelerationFrictionCoef(0.9f);
+ chart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
- mChart.setDrawGridBackground(false);
- mChart.setHighlightPerDragEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
+ chart.setDrawGridBackground(false);
+ chart.setHighlightPerDragEnabled(true);
// set an alternative background color
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setViewPortOffsets(0f, 0f, 0f, 0f);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setViewPortOffsets(0f, 0f, 0f, 0f);
// add data
- setData(100, 30);
- mChart.invalidate();
+ seekBarX.setProgress(100);
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setEnabled(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
- xAxis.setTypeface(mTfLight);
+ xAxis.setTypeface(tfLight);
xAxis.setTextSize(10f);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawAxisLine(false);
@@ -92,7 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {
xAxis.setGranularity(1f); // one hour
xAxis.setValueFormatter(new IAxisValueFormatter() {
- private SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm");
+ private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);
@Override
public String getFormattedValue(float value, AxisBase axis) {
@@ -102,9 +104,9 @@ public String getFormattedValue(float value, AxisBase axis) {
}
});
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
- leftAxis.setTypeface(mTfLight);
+ leftAxis.setTypeface(tfLight);
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
@@ -113,10 +115,49 @@ public String getFormattedValue(float value, AxisBase axis) {
leftAxis.setYOffset(-9f);
leftAxis.setTextColor(Color.rgb(255, 192, 56));
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
}
+ private void setData(int count, float range) {
+
+ // now in hours
+ long now = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis());
+
+ ArrayList values = new ArrayList<>();
+
+ // count = hours
+ float to = now + count;
+
+ // increment by 1 hour
+ for (float x = now; x < to; x++) {
+
+ float y = getRandom(range, 50);
+ values.add(new Entry(x, y)); // add one entry per hour
+ }
+
+ // create a dataset and give it a type
+ LineDataSet set1 = new LineDataSet(values, "DataSet 1");
+ set1.setAxisDependency(AxisDependency.LEFT);
+ set1.setColor(ColorTemplate.getHoloBlue());
+ set1.setValueTextColor(ColorTemplate.getHoloBlue());
+ set1.setLineWidth(1.5f);
+ set1.setDrawCircles(false);
+ set1.setDrawValues(false);
+ set1.setFillAlpha(65);
+ set1.setFillColor(ColorTemplate.getHoloBlue());
+ set1.setHighLightColor(Color.rgb(244, 117, 117));
+ set1.setDrawCircleHole(false);
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1);
+ data.setValueTextColor(Color.WHITE);
+ data.setValueTextSize(9f);
+
+ // set data
+ chart.setData(data);
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
@@ -127,8 +168,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -137,19 +184,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -160,11 +207,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -175,11 +222,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List