Compare commits
377 commits
v3.0.0-bet
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
a6c3808fd5 | ||
|
941579e10f | ||
|
21c811ff9a | ||
|
f3a2ec21c9 | ||
|
9347dd1af7 | ||
|
90e523042c | ||
|
33240f9225 | ||
|
4b67673da9 | ||
|
cef967fd71 | ||
|
eae977306e | ||
|
c0e7f56b5d | ||
|
351e341ee7 | ||
|
f05337768d | ||
|
f8d068d377 | ||
|
5e4a32eb41 | ||
|
1de836ac65 | ||
|
0668d30a6b | ||
|
34fefd28e1 | ||
|
45240c3723 | ||
|
14456f475f | ||
|
e02e9be2fa | ||
|
fcc5af71ce | ||
|
13aee592b1 | ||
|
c97c8d247f | ||
|
ae59e7a19e | ||
|
7752efef7e | ||
|
58545bbbfa | ||
|
4ce14e6cc9 | ||
|
8df9eda7af | ||
|
34c3ceaa05 | ||
|
ea816e8d6d | ||
|
bafb0fbbe4 | ||
|
4549ae17b7 | ||
|
912427e543 | ||
|
3f5475077e | ||
|
2e725e49d3 | ||
|
a4ca1f3fba | ||
|
634a690d6a | ||
|
1987d7eb64 | ||
|
6ebf3fa57a | ||
|
95027fa6a7 | ||
|
d86f39cc91 | ||
|
cb26ed4ef4 | ||
|
dc59171524 | ||
|
726616d079 | ||
|
fffe9a297e | ||
|
2340e12800 | ||
|
c5667d4f14 | ||
|
0563fb48b0 | ||
|
ed8876cef2 | ||
|
12b4351d0c | ||
|
adb56e75bd | ||
|
e95c1eb26a | ||
|
0c2ac2d9cc | ||
|
2058f7bf5d | ||
|
971640b29d | ||
|
7df8a4cedc | ||
|
59028d3bf3 | ||
|
c886bb342a | ||
|
aea2ff3417 | ||
|
42cdba535f | ||
|
29f4cc5c2c | ||
|
fc0e234298 | ||
|
e5b66192e7 | ||
|
608d9e29f5 | ||
|
9148f37f9e | ||
|
6ce99326ae | ||
|
129ad15fd0 | ||
|
5030b36c86 | ||
|
db7dda2b7e | ||
|
d67ea481af | ||
|
20bca4a8ca | ||
|
e2a9110d38 | ||
|
2316f8500f | ||
|
6f0b7432ac | ||
|
073ad3c877 | ||
|
c1f6fcebf0 | ||
|
b65ba08324 | ||
|
fe7a0f8bc3 | ||
|
536a35a6fd | ||
|
75dd04cc42 | ||
|
1485cdc687 | ||
|
53de181607 | ||
|
9ee3a74633 | ||
|
73054bedc3 | ||
|
5869c9de23 | ||
|
89436221db | ||
|
92c14db5b4 | ||
|
0b6632f2cb | ||
|
7abc9cd669 | ||
|
9583a18b84 | ||
|
03c538fc34 | ||
|
c08ec81fc0 | ||
|
e4ba3cdc20 | ||
|
689d484615 | ||
|
9b9d2a68cb | ||
|
0378e763ae | ||
|
1ff676ecaf | ||
|
00e284c043 | ||
|
a7eb395b81 | ||
|
11bf7aa812 | ||
|
89e50c8c9b | ||
|
640208c8ff | ||
|
5519c5170d | ||
|
35c9fc937e | ||
|
89d18a7f67 | ||
|
6fbd492761 | ||
|
7286f8703f | ||
|
9997a33524 | ||
|
d8ea67aa21 | ||
|
40adb57f68 | ||
|
215e0dfc05 | ||
|
e1411f169e | ||
|
993a8554c0 | ||
|
508cc565a9 | ||
|
1e6e58d2c0 | ||
|
aee6058dbb | ||
|
3e1eb1445a | ||
|
82668ebc34 | ||
|
a5250888b9 | ||
|
297ce9f2cc | ||
|
b3e2358334 | ||
|
8fd1a86b0a | ||
|
6ccaf940d8 | ||
|
c50f03cf39 | ||
|
c867d7cb37 | ||
|
2c08b560d6 | ||
|
779e0f5665 | ||
|
8954409575 | ||
|
44125a87dd | ||
|
4b7eb1fd04 | ||
|
21ad19661b | ||
|
b06439f36d | ||
|
62910171f1 | ||
|
16a9be8ea0 | ||
|
e416736ad5 | ||
|
d9000987c7 | ||
|
1ac72ea811 | ||
|
41aff3f13d | ||
|
5e97f561f7 | ||
|
47485f8364 | ||
|
0868d9bf89 | ||
|
23aef1a0ab | ||
|
dfaffa39cc | ||
|
ed9340ea51 | ||
|
796dfb21f8 | ||
|
f2dedb30de | ||
|
a5a482fbdc | ||
|
d3c339da10 | ||
|
c97b8d531d | ||
|
72031d33ca | ||
|
ea93823f63 | ||
|
ed770762fb | ||
|
98f97f0df1 | ||
|
4f77a154bf | ||
|
ad3c82f634 | ||
|
43ae497ecf | ||
|
695f481077 | ||
|
fcb506c219 | ||
|
acf985ff0c | ||
|
0af86819ea | ||
|
f6a398b6b2 | ||
|
208bf181ad | ||
|
557e55653b | ||
|
b564704b82 | ||
|
6df13dd66e | ||
|
2eb12901a9 | ||
|
993d273a52 | ||
|
6c54f0b0a9 | ||
|
0c919ab02d | ||
|
493e3d238d | ||
|
3ec493fc0c | ||
|
31b60225d0 | ||
|
886cc9f85d | ||
|
528e2e8d61 | ||
|
28166a01d1 | ||
|
a5e0a9b86c | ||
|
94957fad33 | ||
|
23e0178dbb | ||
|
144af7b295 | ||
|
a02e108f46 | ||
|
749827798b | ||
|
ed618084f9 | ||
|
30a331781f | ||
|
6966b8117e | ||
|
ccf6b7e3b1 | ||
|
d5e5ec3a92 | ||
|
a934501315 | ||
|
34e7f44979 | ||
|
8abe7e84ad | ||
|
9aaa3328f0 | ||
|
345b4bc97e | ||
|
08f295eae1 | ||
|
a7fd778fc8 | ||
|
2e80fada31 | ||
|
4cb83a7b91 | ||
|
0818d766db | ||
|
ee020bba67 | ||
|
262d877b9f | ||
|
3928e285ae | ||
|
00f36054c7 | ||
|
3a879e9402 | ||
|
8045d64260 | ||
|
6a5580b101 | ||
|
70691bea41 | ||
|
49b4d1a96b | ||
|
fb8094e9f2 | ||
|
bc13bc2c17 | ||
|
9a19bf6670 | ||
|
9b7cffa274 | ||
|
49b61e92a4 | ||
|
3ce2016048 | ||
|
b618524a19 | ||
|
810c99c579 | ||
|
0fec2ef06b | ||
|
d65ffb8871 | ||
|
730e5d3d9b | ||
|
c83d2f4ff4 | ||
|
8ed6dd24bf | ||
|
221cd1313a | ||
|
555176bcdb | ||
|
e10628958f | ||
|
8d65596266 | ||
|
b77063d818 | ||
|
815dee86a0 | ||
|
463ef829d7 | ||
|
3398cf4462 | ||
|
323329d8a6 | ||
|
6f1d365176 | ||
|
cf0f1fca34 | ||
|
c8553da89c | ||
|
06bed3332d | ||
|
aa14ab262b | ||
|
028328b986 | ||
|
01d8b24686 | ||
|
d4e2e697e6 | ||
|
6c0b9c1aab | ||
|
b1fe859ce8 | ||
|
63684f02ca | ||
|
21e778cb1f | ||
|
7ffa9caaa1 | ||
|
b53c8cdbd1 | ||
|
89f10e928e | ||
|
865c3dae18 | ||
|
5b9bd6e633 | ||
|
0aeddb025e | ||
|
e9459fb592 | ||
|
d34670fa62 | ||
|
643f901b15 | ||
|
a3c1fe6bbf | ||
|
a6dd5bb4a1 | ||
|
8f5a898a95 | ||
|
7b33554d5b | ||
|
02cf2c1b97 | ||
|
01419f795b | ||
|
fd3b71f780 | ||
|
afcb72f50f | ||
|
e5d03ba640 | ||
|
8134d7f056 | ||
|
e3c240bd9b | ||
|
2b04973813 | ||
|
26a69592d3 | ||
|
9d0b0fd955 | ||
|
918950b6ad | ||
|
cc971a7d02 | ||
|
5daa6dc23c | ||
|
73148a6aa4 | ||
|
e556275e29 | ||
|
6c17ca45de | ||
|
1bbf4be1ee | ||
|
336dfb93e5 | ||
|
66ea845e14 | ||
|
62bc0de28a | ||
|
dab8db488f | ||
|
38cdf1b206 | ||
|
7a10c05e3a | ||
|
ea6b0e8e1c | ||
|
7747c34552 | ||
|
12d5b858f2 | ||
|
092e8a80f7 | ||
|
be12f155ba | ||
|
bab5b9dd6c | ||
|
3c8bf8cb94 | ||
|
d342760357 | ||
|
d912964dd3 | ||
|
7462c083f9 | ||
|
0f04e9c6f5 | ||
|
5a4a6d4065 | ||
|
f0e1deb763 | ||
|
077365c9af | ||
|
e158ef15e2 | ||
|
788539001f | ||
|
31b0fd9ff9 | ||
|
30cb069974 | ||
|
86d05e989a | ||
|
71ac434a2d | ||
|
2176873271 | ||
|
18eec8f0e6 | ||
|
02bf21df50 | ||
|
e841b697be | ||
|
8cf2a6c3d0 | ||
|
713f467ba8 | ||
|
4d9dc0aa06 | ||
|
339fa16324 | ||
|
aaec1f5d2c | ||
|
51f0e53a7f | ||
|
f63002e196 | ||
|
77c10fc9e5 | ||
|
2d54fd1f3f | ||
|
79f5ed0200 | ||
|
99379d7bcf | ||
|
d2e8ee220a | ||
|
9c5a46c9f8 | ||
|
1096719e8f | ||
|
0c00b09bdb | ||
|
1eae18b657 | ||
|
b2250e0155 | ||
|
164bfd7fca | ||
|
f9108b9ad9 | ||
|
342d41cbc4 | ||
|
79e6a5d747 | ||
|
946475b6d5 | ||
|
099a9cf8c1 | ||
|
2f6fb103a2 | ||
|
a91de26a52 | ||
|
3ea1db57ab | ||
|
e000c42744 | ||
|
ef575decbb | ||
|
37c4eef38e | ||
|
4d5ce149dd | ||
|
d7e659a1fa | ||
|
8c67ec19f7 | ||
|
c3dc2822ce | ||
|
9ccf58feab | ||
|
2fa4a094e7 | ||
|
89104c2858 | ||
|
eb44a13434 | ||
|
16738ef480 | ||
|
e2cbafa049 | ||
|
75ba4f69fc | ||
|
db70835cbc | ||
|
1a39ac9b12 | ||
|
bad43a5e13 | ||
|
83a4bf9075 | ||
|
a4ac12aebf | ||
|
08b2d55049 | ||
|
3f0f3a82c2 | ||
|
360cc24b97 | ||
|
94a67ccea0 | ||
|
6d21817c8a | ||
|
43fa1e6cec | ||
|
40c5c87d13 | ||
|
b5da8dcdb5 | ||
|
87758604d3 | ||
|
d5df3ad795 | ||
|
523c7e5b21 | ||
|
66094db764 | ||
|
37f2498487 | ||
|
38fbefe66b | ||
|
5a18d0ef22 | ||
|
b037f55d73 | ||
|
afdbd2c5f0 | ||
|
69f17b2a79 | ||
|
7fd18d2177 | ||
|
424ee02ce2 | ||
|
a04ad28cec | ||
|
d372fd305c | ||
|
0b72b5588b | ||
|
bd45d73bc6 | ||
|
c59b46affc | ||
|
56cfd2b42b | ||
|
d946f3e3ff | ||
|
f86c1632a7 | ||
|
0f2e2133d3 | ||
|
fcf26aa6ad | ||
|
d299546ebd | ||
|
cb6dabbdec |
365 changed files with 16490 additions and 12498 deletions
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
|
@ -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']
|
37
.github/ISSUE_TEMPLATE.md
vendored
Normal file
37
.github/ISSUE_TEMPLATE.md
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!---
|
||||
BEFORE YOU SUBMIT please read the following:
|
||||
|
||||
Please search open/closed issues before submitting since someone might have asked
|
||||
the same thing before!
|
||||
|
||||
If you have a support request or question please submit them on StackOverflow:
|
||||
https://stackoverflow.com/questions/tagged/mpandroidchart
|
||||
using the tags `android` & `mpandroidchart`
|
||||
|
||||
Please also look at the CONTRIBUTING file before opening an issue:
|
||||
https://github.com/PhilJay/MPAndroidChart/blob/master/CONTRIBUTING.md
|
||||
|
||||
Issues on GitHub are only related to problems with MPAndroidChart itself and we
|
||||
cannot answer support questions here. We will close your issue without a response.
|
||||
-->
|
||||
|
||||
**Summary**
|
||||
<!-- A clear and concise description of what the bug is. -->
|
||||
|
||||
**Expected Behavior**
|
||||
<!-- A clear and concise description of what you expected to happen. -->
|
||||
|
||||
**Possible Solution**
|
||||
<!-- Not required, but suggest a fix/ reason for the bug, -->
|
||||
<!-- or ideas how to implement the addition or change -->
|
||||
|
||||
**Device (please complete the following information):**
|
||||
- Device: [e.g. Google Pixel]
|
||||
- Android Version [e.g. 7.0]
|
||||
- Library Version (e.g. 3.1.0-alpha)
|
||||
|
||||
**Additional Context**
|
||||
<!-- Add any other context about the problem here.
|
||||
If you have source code demonstrating this bug, create a Gist:
|
||||
https://help.github.com/articles/creating-gists/
|
||||
and link to it here. -->
|
44
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
44
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
name: Bugs
|
||||
about: Create a bug report to help us improve
|
||||
|
||||
---
|
||||
|
||||
<!---
|
||||
BEFORE YOU SUBMIT please read the following:
|
||||
|
||||
Please search open/closed issues before submitting since someone might have asked the same thing before!
|
||||
|
||||
If you have a support request or question please submit them on StackOverflow:
|
||||
https://stackoverflow.com/questions/tagged/mpandroidchart
|
||||
using the tags `android` & `mpandroidchart`
|
||||
|
||||
Please also look at the CONTRIBUTING file before opening an issue:
|
||||
https://github.com/PhilJay/MPAndroidChart/blob/master/CONTRIBUTING.md
|
||||
|
||||
Issues on GitHub are only related to problems with MPAndroidChart itself and we cannot answer
|
||||
support questions here. We will close your issue without a response.
|
||||
-->
|
||||
|
||||
**Summary**
|
||||
<!-- A clear and concise description of what the bug is. -->
|
||||
|
||||
**Expected Behavior**
|
||||
<!-- A clear and concise description of what you expected to happen. -->
|
||||
|
||||
**Possible Solution**
|
||||
<!-- Not required, but suggest a fix/ reason for the bug, -->
|
||||
<!-- or ideas how to implement the addition or change -->
|
||||
|
||||
**Device (please complete the following information):**
|
||||
- Device: [e.g. Google Pixel]
|
||||
- Android Version [e.g. 7.0]
|
||||
- Library Version (e.g. 3.1.0-alpha)
|
||||
|
||||
**Additional Context**
|
||||
<!-- Add any other context about the problem here.
|
||||
If you have source code demonstrating this bug, create a Gist:
|
||||
https://help.github.com/articles/creating-gists/
|
||||
and link to it here. -->
|
||||
|
||||
ADD A REWARD using [Speed](speedoss.com) to SOLVE this issue QUICKLY and SUPPORT this project.
|
34
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
34
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
name: Feature Request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
<!---
|
||||
BEFORE YOU SUBMIT please read the following:
|
||||
|
||||
Please search open/closed issues before submitting since someone might have asked the same thing before!
|
||||
|
||||
If you have a support request or question please submit them on StackOverflow:
|
||||
https://stackoverflow.com/questions/tagged/mpandroidchart
|
||||
using the tags `android` & `mpandroidchart`
|
||||
|
||||
Please also look at the CONTRIBUTING file before opening an issue:
|
||||
https://github.com/PhilJay/MPAndroidChart/blob/master/CONTRIBUTING.md
|
||||
|
||||
Issues on GitHub are only related to problems with MPAndroidChart itself and we cannot answer
|
||||
support questions here. We will close your issue without a response.
|
||||
-->
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
||||
|
||||
**Describe the solution you'd like**
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
**Additional context**
|
||||
<!-- Add any other context or screenshots about the feature request here. -->
|
||||
ADD A REWARD using [Speed](speedoss.com) to SOLVE this issue QUICKLY and SUPPORT this project.
|
27
.github/ISSUE_TEMPLATE/Support_help.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/Support_help.md
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
name: Support
|
||||
about: I need help!
|
||||
|
||||
---
|
||||
|
||||
# *STOP RIGHT THERE!*
|
||||
|
||||
Issues are ***NOT*** for getting help, only for reporting bugs and feature requests.
|
||||
|
||||
Search open and closed issues to see if your question already has an answer. However, **do not create a new issue.**
|
||||
|
||||
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.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.
|
||||
|
||||
|
||||
### 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.
|
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
## PR Checklist:
|
||||
- [ ] I have tested this extensively and it does not break any existing behavior.
|
||||
- [ ] I have added/updated examples and tests for any new behavior.
|
||||
- [ ] If this is a significant change, an issue has already been created where the problem / solution was discussed: [N/A, or add link to issue here]
|
||||
<!-- If you'd like to suggest a significant change, please
|
||||
create an issue to discuss those changes and gather
|
||||
feedback BEFORE submitting your PR. -->
|
||||
|
||||
|
||||
## PR Description
|
||||
<!-- Describe Your PR Here! -->
|
||||
|
||||
<!-- What does this add/ remove/ fix/ change? -->
|
||||
|
||||
<!-- WHY should this PR be merged into the main library? -->
|
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -12,8 +12,8 @@
|
|||
bin/
|
||||
gen/
|
||||
generated/
|
||||
docs/
|
||||
finalOutput/
|
||||
projectFilesBackup/
|
||||
|
||||
build.xml
|
||||
|
||||
|
@ -23,6 +23,8 @@ local.properties
|
|||
# Eclipse project files
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
.vscode/
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
@ -31,7 +33,8 @@ proguard/
|
|||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
/.idea/*
|
||||
!/.idea/runConfigurations
|
||||
|
||||
.directory
|
||||
|
||||
|
@ -42,3 +45,5 @@ build/
|
|||
|
||||
# maven
|
||||
target/
|
||||
|
||||
.DS_Store
|
||||
|
|
52
.idea/runConfigurations/MPChartExample.xml
generated
Normal file
52
.idea/runConfigurations/MPChartExample.xml
generated
Normal file
|
@ -0,0 +1,52 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="MPChartExample" type="AndroidRunConfigurationType" factoryName="Android App" activateToolWindowBeforeRun="false">
|
||||
<module name="MPChartExample" />
|
||||
<option name="DEPLOY" value="true" />
|
||||
<option name="DEPLOY_APK_FROM_BUNDLE" value="false" />
|
||||
<option name="ARTIFACT_NAME" value="" />
|
||||
<option name="PM_INSTALL_OPTIONS" value="" />
|
||||
<option name="DYNAMIC_FEATURES_DISABLED_LIST" value="" />
|
||||
<option name="ACTIVITY_EXTRA_FLAGS" value="" />
|
||||
<option name="MODE" value="default_activity" />
|
||||
<option name="CLEAR_LOGCAT" value="false" />
|
||||
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
|
||||
<option name="SKIP_NOOP_APK_INSTALLATIONS" value="true" />
|
||||
<option name="FORCE_STOP_RUNNING_APP" value="true" />
|
||||
<option name="TARGET_SELECTION_MODE" value="SHOW_DIALOG" />
|
||||
<option name="USE_LAST_SELECTED_DEVICE" value="false" />
|
||||
<option name="PREFERRED_AVD" value="" />
|
||||
<option name="SELECTED_CLOUD_MATRIX_CONFIGURATION_ID" value="-1" />
|
||||
<option name="SELECTED_CLOUD_MATRIX_PROJECT_ID" value="" />
|
||||
<option name="DEBUGGER_TYPE" value="Auto" />
|
||||
<Auto>
|
||||
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||
<option name="SHOW_STATIC_VARS" value="true" />
|
||||
<option name="WORKING_DIR" value="" />
|
||||
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||
</Auto>
|
||||
<Hybrid>
|
||||
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||
<option name="SHOW_STATIC_VARS" value="true" />
|
||||
<option name="WORKING_DIR" value="" />
|
||||
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||
</Hybrid>
|
||||
<Java />
|
||||
<Native>
|
||||
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||
<option name="SHOW_STATIC_VARS" value="true" />
|
||||
<option name="WORKING_DIR" value="" />
|
||||
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||
</Native>
|
||||
<Profilers>
|
||||
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
|
||||
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
|
||||
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Sampled (Java)" />
|
||||
</Profilers>
|
||||
<option name="DEEP_LINK" value="" />
|
||||
<option name="ACTIVITY_CLASS" value="" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -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=
|
|
@ -1,49 +1,66 @@
|
|||
> ### Notice
|
||||
> *Before you continue, this is the* **ANDROID** *library. If you have an* **iOS** *device, please go here instead*:
|
||||
>
|
||||
> – https://github.com/danielgindi/Charts
|
||||
>
|
||||
> They might tell you to come back here, if they do, listen to them and ignore this notice.
|
||||
|
||||
# How to contribute
|
||||
|
||||
Bug-fixes and features often come from users of the MPAndroidChart library and improve it greatly. We want to keep it as easy as possible to contribute changes that improve the experience for users all around the world. There are a few guidelines that we
|
||||
need contributors to follow so that we can have a chance of keeping on
|
||||
top of things.
|
||||
Bug-fixes and features often come from users of the MPAndroidChart library and improve it greatly. We want to keep it as easy as possible to contribute changes that improve the experience for users all around the world. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
|
||||
|
||||
## Simple issues and bug reports
|
||||
## Creating Issues
|
||||
|
||||
If you are reporting a bug which can be observed visually, please add to your issue either:
|
||||
There are two main issue templates, one for bugs and another for feature requests. Please use them! You're issue will be much easier to understand, and bugs easier to fix, if you follow the templates. If your issue doesn't fit into those, just use the generic template.
|
||||
|
||||
* Screenshots, if the bug is easily explainable
|
||||
* A working sample project that we can compile, run, and immediately observe the issue
|
||||
Search existing [issues] to see if your bug has already been reported or if a feature request already exists. Don't forget to remove `is:open` so you see all the issues! If you find that one already exists, use reactions to show how much you care!
|
||||
|
||||
## Getting Started with Contributions
|
||||
## Making Pull Requests
|
||||
|
||||
* Make sure you have a [GitHub account](https://github.com/signup/free)
|
||||
* Submit a ticket for your issue, assuming one does not already exist.
|
||||
* Clearly describe the issue including steps to reproduce when it is a bug.
|
||||
* Make sure you fill in the earliest version (or commit number) that you know has the issue.
|
||||
* Fork the repository on GitHub
|
||||
Careful! If you fail to follow these guidlines, you're pull request may be closed, *even if it's really awesome*.
|
||||
|
||||
## Making Changes
|
||||
0. **Search** open [pull requests] AND existing [issues] to make sure what you want to do isn't already being worked on or already has an open pull request.
|
||||
1. **Fork** the repository
|
||||
1. **Create** a new branch based on `master`, and name it according to your changes
|
||||
1. **Add** your commits, they MUST follow the [Commit Style](#commit-style) below
|
||||
1. **Test** your changes by actually running the example app, or create a new example
|
||||
1. **Create** a pull request, following the auto-generated template
|
||||
1. ???
|
||||
1. Profit :money_with_wings:
|
||||
|
||||
You are encouraged to use [GitHub Desktop] to inspect your code changes before committing them. It can reveal small changes that might have gone unnoticed, and would be requested for removal before merging.
|
||||
|
||||
* Create a topic branch from where you want to base your work. This is usually the master branch.
|
||||
* Make commits of logical units.
|
||||
* Make sure your code conforms to the code style around it. It's easy, just look around!
|
||||
* If you have made changes back and forth, or have made merges, your commit history might look messy and hard to understand. A single issue or change should still be in one commit. So please squash those commits together and rebase them however you need to - to make our lives easier when reading it later.
|
||||
* Check for unnecessary whitespace with `git diff --check` before committing.
|
||||
* Make sure your commit messages are in the proper format.
|
||||
Check out [#3975](https://github.com/PhilJay/MPAndroidChart/pull/3975) for an example of a good-made-better pull request.
|
||||
|
||||
````
|
||||
First line must be up to 50 chars (Fixes #1234)
|
||||
## Commit Style
|
||||
|
||||
The first line should be a short statement as to what have changed, and should also include an issue number, prefixed with a dash.
|
||||
The body of the message comes after an empty new line, and describes the changes
|
||||
more thoroughly, especially if there was a special case handled there,
|
||||
or maybe some trickery that only code wizards can understand.
|
||||
````
|
||||
* **Make commits of logical units**
|
||||
Don't load your commits with tons of changes, this makes it hard to follow what is happening. However, if you have done a lot of work, and there are commits and merges all over the place, squash them down into fewer commits.
|
||||
|
||||
* **Conform to the code style**
|
||||
It's easy, just look around!
|
||||
|
||||
* **Write good commit messages**
|
||||
You may prefer [Tim Pope's style], you might like the [commitizen-friendly] way. Regardless of the color you pick, you MUST stay within the lines!
|
||||
```
|
||||
The commit title CANNOT exceed 50 characters
|
||||
|
||||
* Make sure you have tested your changes well.
|
||||
* If your changes could theoretically affect some other component or case, which you do not necessarily use, you still have to test it.
|
||||
* Create a Pull Request from your topic branch to the relevant branch in the main repo. If you go to the main repo of the framework, you'll see a big green button which pretty much prepares the PR for you. You just have to hit it.
|
||||
The body of the message comes after an empty new line, and describes the
|
||||
changes more thoroughly. If the change is obvious and self-explanatory
|
||||
from the title, you can omit the body. You should describe all changes
|
||||
if many were made, or maybe some trickery that only code wizards can
|
||||
understand.
|
||||
|
||||
## Making Trivial Changes
|
||||
Be polite and wrap your lines to 72 characters, but if you prefer going
|
||||
to 100 characters then I guess we can't stop you.
|
||||
```
|
||||
|
||||
For changes of a trivial nature to comments and documentation, it is not
|
||||
always necessary to create a new ticket. In this case, it is
|
||||
appropriate to start the first line of a commit with '(doc)' instead of
|
||||
a ticket number. Even the default commit message the GitHub generates is fine with us.
|
||||
## Final Notes
|
||||
|
||||
Thanks for reading the contributing file! Have some cake! :cake:
|
||||
|
||||
[issues]: https://github.com/PhilJay/MPAndroidChart/issues
|
||||
[pull requests]: https://github.com/PhilJay/MPAndroidChart/pulls
|
||||
[GitHub Desktop]: https://desktop.github.com/
|
||||
[Tim Pope's style]: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
||||
[commitizen-friendly]: https://github.com/commitizen/cz-cli
|
||||
|
|
201
LICENSE
Normal file
201
LICENSE
Normal file
|
@ -0,0 +1,201 @@
|
|||
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}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
1
MPChartExample/.gitignore
vendored
1
MPChartExample/.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/build
|
||||
/release
|
||||
|
|
|
@ -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=..
|
|
@ -1,71 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.xxmassdeveloper.mpchartexample"
|
||||
android:versionCode="52"
|
||||
android:versionName="3.0.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="16"
|
||||
android:targetSdkVersion="23" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name="com.xxmassdeveloper.mpchartexample.notimportant.MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="LineChartActivity1"></activity> <!-- android:configChanges="keyboardHidden|orientation|screenSize" -->
|
||||
<activity android:name="LineChartActivity2"></activity>
|
||||
<activity android:name=".LineChartTime"></activity>
|
||||
<activity android:name="BarChartActivity"></activity>
|
||||
<activity android:name="HorizontalBarChartActivity"></activity>
|
||||
<activity android:name="PieChartActivity"></activity>
|
||||
<activity android:name="PiePolylineChartActivity"></activity>
|
||||
<activity android:name="MultiLineChartActivity"></activity>
|
||||
<activity android:name="BarChartActivityMultiDataset"></activity>
|
||||
<activity android:name="DrawChartActivity"></activity>
|
||||
<activity android:name="ScatterChartActivity"></activity>
|
||||
<activity android:name="BubbleChartActivity"></activity>
|
||||
<activity android:name="com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo"></activity>
|
||||
<activity android:name="ListViewBarChartActivity"></activity>
|
||||
<activity android:name="ListViewMultiChartActivity"></activity>
|
||||
<activity android:name="StackedBarActivity"></activity>
|
||||
<activity android:name="AnotherBarActivity"></activity>
|
||||
<activity android:name="InvertedLineChartActivity"></activity>
|
||||
<activity android:name="CandleStickChartActivity"></activity>
|
||||
<activity android:name="CubicLineChartActivity"></activity>
|
||||
<activity android:name="RadarChartActivitry"></activity>
|
||||
<activity android:name="LineChartActivityColored"></activity>
|
||||
<activity android:name="DynamicalAddingActivity"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityLine"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityBar"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityHorizontalBar"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityScatter"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityCandle"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityBubble"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityPie"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityRadar"></activity>
|
||||
<activity android:name=".realm.RealmMainActivity"></activity>
|
||||
<activity android:name="RealtimeLineChartActivity"></activity>
|
||||
<activity android:name="CombinedChartActivity"></activity>
|
||||
<activity android:name="PerformanceLineChart"></activity>
|
||||
<activity android:name="BarChartActivitySinus"></activity>
|
||||
<activity android:name="ScrollViewActivity"></activity>
|
||||
<activity android:name="StackedBarActivityNegative"></activity>
|
||||
<activity android:name=".realm.RealmWikiExample"></activity>
|
||||
<activity android:name=".BarChartPositiveNegative"></activity>
|
||||
<activity android:name=".FilledLineActivity"></activity>
|
||||
<activity android:name=".HalfPieChartActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,65 +1,26 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion '23.0.2'
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "com.xxmassdeveloper.mpchartexample"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
versionCode 52
|
||||
versionName '3.0.0'
|
||||
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 {
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.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:
|
||||
compile 'com.github.PhilJay:MPAndroidChart-Realm:v1.0.0@aar'
|
||||
|
||||
compile project(':MPChartLib')
|
||||
compile 'com.android.support:appcompat-v7:23.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'
|
||||
implementation "androidx.appcompat:appcompat:1.0.2"
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation project(':MPChartLib')
|
||||
}
|
||||
|
|
|
@ -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 *;
|
||||
#}
|
21
MPChartExample/proguard-rules.pro
vendored
Normal file
21
MPChartExample/proguard-rules.pro
vendored
Normal file
|
@ -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
|
|
@ -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
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:color="#FA6185" />
|
||||
|
||||
<solid android:color="#FA6185" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<com.github.mikephil.charting.charts.BubbleChart
|
||||
android:id="@+id/chart1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<com.github.mikephil.charting.charts.CandleStickChart
|
||||
android:id="@+id/chart1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<com.github.mikephil.charting.charts.HorizontalBarChart
|
||||
android:id="@+id/chart1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/chart1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.6"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="YOUR PREFERENCES"
|
||||
android:id="@+id/textView"/>
|
||||
|
||||
<com.github.mikephil.charting.charts.RadarChart
|
||||
android:id="@+id/chart1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/lineChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/barChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<com.github.mikephil.charting.charts.ScatterChart
|
||||
android:id="@+id/chart1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,41 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionToggleValues"
|
||||
android:title="Toggle Values">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleHighlight"
|
||||
android:title="Toggle Highlight">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleAdjustXLegend"
|
||||
android:title="Toggle AdjustXLegend">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateX"
|
||||
android:title="Animate X">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateY"
|
||||
android:title="Animate Y">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateXY"
|
||||
android:title="Animate XY">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionSave"
|
||||
android:title="Save to Gallery">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionTogglePinch"
|
||||
android:title="Toggle PinchZoom">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleAutoScaleMinMax"
|
||||
android:title="Toggle auto scale min/max">
|
||||
</item>
|
||||
|
||||
</menu>
|
|
@ -1,41 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionToggleHighlight"
|
||||
android:title="Toggle Highlight">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateX"
|
||||
android:title="Animate X">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateY"
|
||||
android:title="Animate Y">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateXY"
|
||||
android:title="Animate XY">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleAdjustXLegend"
|
||||
android:title="Toggle AdjustXLegend">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionSave"
|
||||
android:title="Save to SD-Card">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionTogglePinch"
|
||||
android:title="Toggle PinchZoom">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleAutoScaleMinMax"
|
||||
android:title="Toggle auto scale min/max">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleMakeShadowSameColorAsCandle"
|
||||
android:title="Toggle shadow same color">
|
||||
</item>
|
||||
|
||||
</menu>
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionAddEntry"
|
||||
android:title="Add Entry">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionRemoveEntry"
|
||||
android:title="Remove Entry">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionAddDataSet"
|
||||
android:title="Add DataSet">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionRemoveDataSet"
|
||||
android:title="Remove DataSet">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionAddEmptyLineData"
|
||||
android:title="Add empty LineData">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionClear"
|
||||
android:title="Clear chart">
|
||||
</item>
|
||||
</menu>
|
|
@ -1,45 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionToggleValues"
|
||||
android:title="Toggle Y-Values">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleXVals"
|
||||
android:title="Toggle X-Values">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionTogglePercent"
|
||||
android:title="Toggle Percent">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleHole"
|
||||
android:title="Toggle Hole">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateX"
|
||||
android:title="Animate X">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateY"
|
||||
android:title="Animate Y">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/animateXY"
|
||||
android:title="Animate XY">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionDrawCenter"
|
||||
android:title="Draw CenterText">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionSave"
|
||||
android:title="Save to Gallery">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleSpin"
|
||||
android:title="Spin Animation">
|
||||
</item>
|
||||
|
||||
</menu>
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionAdd"
|
||||
android:title="Feed new Entry">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionClear"
|
||||
android:title="Clear Values">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionFeedMultiple"
|
||||
android:title="Fast feed multiple">
|
||||
</item>
|
||||
</menu>
|
|
@ -1,8 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Customize dimensions originally defined in res/values/dimens.xml (such as
|
||||
screen margins) for sw600dp devices (e.g. 7" tablets) here.
|
||||
-->
|
||||
|
||||
</resources>
|
|
@ -1,9 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Customize dimensions originally defined in res/values/dimens.xml (such as
|
||||
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
|
||||
-->
|
||||
<dimen name="activity_horizontal_margin">128dp</dimen>
|
||||
|
||||
</resources>
|
|
@ -1,11 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -1,12 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -1,7 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
|
||||
</resources>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">MPAndroidChart Example</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
|
||||
</resources>
|
|
@ -1,20 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
</style>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -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 = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// 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<BarEntry> yVals1 = new ArrayList<BarEntry>();
|
||||
|
||||
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<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
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
|
||||
|
||||
}
|
||||
}
|
|
@ -1,279 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
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 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.XAxis.XAxisPosition;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.components.YAxis.AxisDependency;
|
||||
import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition;
|
||||
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.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
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.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BarChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
protected 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 = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
mChart.setDrawBarShadow(false);
|
||||
mChart.setDrawValueAboveBar(true);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// 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.setDrawGridBackground(false);
|
||||
// mChart.setDrawYLabels(false);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setPosition(XAxisPosition.BOTTOM);
|
||||
xAxis.setTypeface(mTfLight);
|
||||
xAxis.setDrawGridLines(false);
|
||||
xAxis.setGranularity(1f); // only intervals of 1 day
|
||||
xAxis.setLabelCount(7);
|
||||
xAxis.setValueFormatter(new DayAxisValueFormatter(mChart));
|
||||
|
||||
AxisValueFormatter custom = new MyAxisValueFormatter();
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.setTypeface(mTfLight);
|
||||
leftAxis.setLabelCount(8, false);
|
||||
leftAxis.setValueFormatter(custom);
|
||||
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
|
||||
leftAxis.setSpaceTop(15f);
|
||||
leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
|
||||
YAxis rightAxis = mChart.getAxisRight();
|
||||
rightAxis.setDrawGridLines(false);
|
||||
rightAxis.setTypeface(mTfLight);
|
||||
rightAxis.setLabelCount(8, false);
|
||||
rightAxis.setValueFormatter(custom);
|
||||
rightAxis.setSpaceTop(15f);
|
||||
rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setForm(LegendForm.SQUARE);
|
||||
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" });
|
||||
|
||||
setData(12, 50);
|
||||
|
||||
// setting data
|
||||
mSeekBarY.setProgress(50);
|
||||
mSeekBarX.setProgress(12);
|
||||
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
// mChart.setDrawLegend(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() + 2));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
setData(mSeekBarX.getProgress() + 1 , mSeekBarY.getProgress());
|
||||
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) {
|
||||
|
||||
float start = 0f;
|
||||
|
||||
mChart.getXAxis().setAxisMinValue(start);
|
||||
mChart.getXAxis().setAxisMaxValue(start + count + 2);
|
||||
|
||||
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
|
||||
|
||||
for (int i = (int) start; i < start + count + 1; i++) {
|
||||
float mult = (range + 1);
|
||||
float val = (float) (Math.random() * mult);
|
||||
yVals1.add(new BarEntry(i + 1f, 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.setColors(ColorTemplate.MATERIAL_COLORS);
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set1);
|
||||
|
||||
BarData data = new BarData(dataSets);
|
||||
data.setValueTextSize(10f);
|
||||
data.setValueTypeface(mTfLight);
|
||||
data.setBarWidth(0.9f);
|
||||
|
||||
mChart.setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onValueSelected(Entry e, Highlight h) {
|
||||
|
||||
if (e == null)
|
||||
return;
|
||||
|
||||
RectF bounds = mChart.getBarBounds((BarEntry) e);
|
||||
PointF position = mChart.getPosition(e, AxisDependency.LEFT);
|
||||
|
||||
Log.i("bounds", bounds.toString());
|
||||
Log.i("position", position.toString());
|
||||
|
||||
Log.i("x-index",
|
||||
"low: " + mChart.getLowestVisibleX() + ", high: "
|
||||
+ mChart.getHighestVisibleX());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() { }
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
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.BarChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
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.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.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.formatter.LargeValueFormatter;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
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 = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setDescription("");
|
||||
|
||||
// mChart.setDrawBorders(true);
|
||||
|
||||
// scaling can now only be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
mChart.setDrawBarShadow(false);
|
||||
|
||||
mChart.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);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
|
||||
mSeekBarX.setProgress(10);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART_INSIDE);
|
||||
l.setTypeface(mTfLight);
|
||||
l.setYOffset(0f);
|
||||
l.setYEntrySpace(0f);
|
||||
l.setTextSize(8f);
|
||||
|
||||
XAxis xl = mChart.getXAxis();
|
||||
xl.setTypeface(mTfLight);
|
||||
xl.setGranularity(1f);
|
||||
xl.setCenterAxisLabels(true);
|
||||
xl.setValueFormatter(new AxisValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return String.valueOf((int) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.setTypeface(mTfLight);
|
||||
leftAxis.setValueFormatter(new LargeValueFormatter());
|
||||
leftAxis.setDrawGridLines(false);
|
||||
leftAxis.setSpaceTop(30f);
|
||||
leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
|
||||
mChart.getAxisRight().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 (IBarDataSet set : mChart.getData().getDataSets())
|
||||
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.actionToggleBarBorders: {
|
||||
for (IBarDataSet set : mChart.getData().getDataSets())
|
||||
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlight: {
|
||||
if(mChart.getData() != null) {
|
||||
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
float groupSpace = 0.04f;
|
||||
float barSpace = 0.02f; // x3 dataset
|
||||
float barWidth = 0.3f; // x3 dataset
|
||||
// (0.3 + 0.02) * 3 + 0.04 = 1.00 -> interval per "group"
|
||||
|
||||
int startYear = 1980;
|
||||
int endYear = startYear + mSeekBarX.getProgress();
|
||||
|
||||
tvX.setText(startYear + "\n-" + endYear);
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
|
||||
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
|
||||
ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
|
||||
|
||||
float mult = mSeekBarY.getProgress() * 100000f;
|
||||
|
||||
for (int i = startYear; i < endYear; i++) {
|
||||
float val = (float) (Math.random() * mult) + 3;
|
||||
yVals1.add(new BarEntry(i, val));
|
||||
}
|
||||
|
||||
for (int i = startYear; i < endYear; i++) {
|
||||
float val = (float) (Math.random() * mult) + 3;
|
||||
yVals2.add(new BarEntry(i, val));
|
||||
}
|
||||
|
||||
for (int i = startYear; i < endYear; i++) {
|
||||
float val = (float) (Math.random() * mult) + 3;
|
||||
yVals3.add(new BarEntry(i, val));
|
||||
}
|
||||
|
||||
BarDataSet set1, set2, set3;
|
||||
|
||||
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);
|
||||
set1.setValues(yVals1);
|
||||
set2.setValues(yVals2);
|
||||
set3.setValues(yVals3);
|
||||
mChart.getData().notifyDataChanged();
|
||||
mChart.notifyDataSetChanged();
|
||||
} else {
|
||||
// create 3 datasets with different types
|
||||
set1 = new BarDataSet(yVals1, "Company A");
|
||||
// set1.setColors(ColorTemplate.createColors(getApplicationContext(),
|
||||
// ColorTemplate.FRESH_COLORS));
|
||||
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));
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set1);
|
||||
dataSets.add(set2);
|
||||
dataSets.add(set3);
|
||||
|
||||
BarData data = new BarData(dataSets);
|
||||
data.setValueFormatter(new LargeValueFormatter());
|
||||
|
||||
// add space between the dataset groups in percent of bar-width
|
||||
data.setValueTypeface(mTfLight);
|
||||
|
||||
mChart.setData(data);
|
||||
}
|
||||
|
||||
mChart.getBarData().setBarWidth(barWidth);
|
||||
mChart.getXAxis().setAxisMinValue(startYear);
|
||||
mChart.getXAxis().setAxisMaxValue(mChart.getBarData().getGroupWidth(groupSpace, barSpace) * mSeekBarX.getProgress() + startYear);
|
||||
mChart.groupBars(startYear, groupSpace, barSpace);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueSelected(Entry e, Highlight h) {
|
||||
Log.i("Activity", "Selected: " + e.toString() + ", dataSet: " + h.getDataSetIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
Log.i("Activity", "Nothing selected.");
|
||||
}
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
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.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;
|
||||
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.utils.FileUtils;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeListener {
|
||||
|
||||
protected BarChart mChart;
|
||||
private SeekBar mSeekBarX;
|
||||
private TextView tvX;
|
||||
|
||||
private List<BarEntry> mSinusData;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_barchart_sinus);
|
||||
|
||||
mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvValueCount);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekbarValues);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
mChart.setDrawBarShadow(false);
|
||||
mChart.setDrawValueAboveBar(true);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// 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);
|
||||
|
||||
// draw shadows for each bar that show the maximum value
|
||||
// mChart.setDrawBarShadow(true);
|
||||
|
||||
// mChart.setDrawXLabels(false);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
// mChart.setDrawYLabels(false);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setEnabled(false);
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.setTypeface(mTfLight);
|
||||
leftAxis.setLabelCount(6, false);
|
||||
leftAxis.setAxisMinValue(-2.5f);
|
||||
leftAxis.setAxisMaxValue(2.5f);
|
||||
leftAxis.setGranularityEnabled(true);
|
||||
leftAxis.setGranularity(0.1f);
|
||||
|
||||
YAxis rightAxis = mChart.getAxisRight();
|
||||
rightAxis.setDrawGridLines(false);
|
||||
rightAxis.setTypeface(mTfLight);
|
||||
rightAxis.setLabelCount(6, false);
|
||||
rightAxis.setAxisMinValue(-2.5f);
|
||||
rightAxis.setAxisMaxValue(2.5f);
|
||||
rightAxis.setGranularity(0.1f);
|
||||
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX.setProgress(150); // set data
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setForm(LegendForm.SQUARE);
|
||||
l.setFormSize(9f);
|
||||
l.setTextSize(11f);
|
||||
l.setXEntrySpace(4f);
|
||||
|
||||
mChart.animateXY(2000, 2000);
|
||||
}
|
||||
|
||||
@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 (IBarDataSet 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(1500);
|
||||
break;
|
||||
}
|
||||
case R.id.animateY: {
|
||||
mChart.animateY(1500);
|
||||
break;
|
||||
}
|
||||
case R.id.animateXY: {
|
||||
|
||||
mChart.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();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress()));
|
||||
|
||||
setData(mSeekBarX.getProgress());
|
||||
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) {
|
||||
|
||||
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
entries.add(mSinusData.get(i));
|
||||
}
|
||||
|
||||
BarDataSet set;
|
||||
|
||||
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);
|
||||
|
||||
mChart.setData(data);
|
||||
}
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
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.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;
|
||||
import com.github.mikephil.charting.data.BubbleDataSet;
|
||||
import com.github.mikephil.charting.data.BubbleEntry;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
private BubbleChart 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_bubblechart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (BubbleChart) findViewById(R.id.chart1);
|
||||
mChart.setDescription("");
|
||||
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
mChart.setTouchEnabled(true);
|
||||
|
||||
// enable scaling and dragging
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setScaleEnabled(true);
|
||||
|
||||
mChart.setMaxVisibleValueCount(200);
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mSeekBarX.setProgress(10);
|
||||
mSeekBarY.setProgress(50);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setTypeface(mTfLight);
|
||||
|
||||
YAxis yl = mChart.getAxisLeft();
|
||||
yl.setTypeface(mTfLight);
|
||||
yl.setSpaceTop(30f);
|
||||
yl.setSpaceBottom(30f);
|
||||
yl.setDrawZeroLine(false);
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
|
||||
XAxis xl = mChart.getXAxis();
|
||||
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||
xl.setTypeface(mTfLight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.bubble, 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.actionSave: {
|
||||
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;
|
||||
}
|
||||
|
||||
@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<BubbleEntry> yVals1 = new ArrayList<BubbleEntry>();
|
||||
ArrayList<BubbleEntry> yVals2 = new ArrayList<BubbleEntry>();
|
||||
ArrayList<BubbleEntry> yVals3 = new ArrayList<BubbleEntry>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
|
||||
set1.setDrawValues(true);
|
||||
BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
|
||||
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<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
|
||||
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();
|
||||
}
|
||||
|
||||
@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) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
|
@ -1,207 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
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.CandleStickChart;
|
||||
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.components.YAxis.AxisDependency;
|
||||
import com.github.mikephil.charting.data.CandleData;
|
||||
import com.github.mikephil.charting.data.CandleDataSet;
|
||||
import com.github.mikephil.charting.data.CandleEntry;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CandleStickChartActivity extends DemoBase implements OnSeekBarChangeListener {
|
||||
|
||||
private CandleStickChart 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_candlechart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (CandleStickChart) findViewById(R.id.chart1);
|
||||
mChart.setBackgroundColor(Color.WHITE);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// 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.setDrawGridBackground(false);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setPosition(XAxisPosition.BOTTOM);
|
||||
xAxis.setDrawGridLines(false);
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
// leftAxis.setEnabled(false);
|
||||
leftAxis.setLabelCount(7, false);
|
||||
leftAxis.setDrawGridLines(false);
|
||||
leftAxis.setDrawAxisLine(false);
|
||||
|
||||
YAxis rightAxis = mChart.getAxisRight();
|
||||
rightAxis.setEnabled(false);
|
||||
// rightAxis.setStartAtZero(false);
|
||||
|
||||
// setting data
|
||||
mSeekBarX.setProgress(40);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
mChart.getLegend().setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.candle, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
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.actionToggleMakeShadowSameColorAsCandle: {
|
||||
for (ICandleDataSet set : mChart.getData().getDataSets()) {
|
||||
//TODO: set.setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
int prog = (mSeekBarX.getProgress() + 1);
|
||||
|
||||
tvX.setText("" + prog);
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
mChart.resetTracking();
|
||||
|
||||
ArrayList<CandleEntry> yVals1 = new ArrayList<CandleEntry>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set");
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
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.FillFormatter;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FilledLineActivity extends DemoBase {
|
||||
|
||||
private LineChart mChart;
|
||||
private int mFillColor = Color.argb(150, 51, 181, 229);
|
||||
|
||||
@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 = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setBackgroundColor(Color.WHITE);
|
||||
mChart.setGridBackgroundColor(mFillColor);
|
||||
mChart.setDrawGridBackground(true);
|
||||
|
||||
mChart.setDrawBorders(true);
|
||||
|
||||
// no description text
|
||||
mChart.setDescription("");
|
||||
|
||||
// if disabled, scaling can be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setEnabled(false);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setEnabled(false);
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.setAxisMaxValue(900f);
|
||||
leftAxis.setAxisMinValue(-250f);
|
||||
leftAxis.setDrawAxisLine(false);
|
||||
leftAxis.setDrawZeroLine(false);
|
||||
leftAxis.setDrawGridLines(false);
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
|
||||
// add data
|
||||
setData(100, 60);
|
||||
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
private void setData(int count, float range) {
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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();
|
||||
} else {
|
||||
// create a dataset and give it a type
|
||||
set1 = new LineDataSet(yVals1, "DataSet 1");
|
||||
|
||||
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||
set1.setColor(Color.rgb(255, 241, 46));
|
||||
set1.setDrawCircles(false);
|
||||
set1.setLineWidth(2f);
|
||||
set1.setCircleRadius(3f);
|
||||
set1.setFillAlpha(255);
|
||||
set1.setDrawFilled(true);
|
||||
set1.setFillColor(Color.WHITE);
|
||||
set1.setHighLightColor(Color.rgb(244, 117, 117));
|
||||
set1.setDrawCircleHole(false);
|
||||
set1.setFillFormatter(new FillFormatter() {
|
||||
@Override
|
||||
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
|
||||
return mChart.getAxisLeft().getAxisMinimum();
|
||||
}
|
||||
});
|
||||
|
||||
// create a dataset and give it a type
|
||||
set2 = new LineDataSet(yVals2, "DataSet 2");
|
||||
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||
set2.setColor(Color.rgb(255, 241, 46));
|
||||
set2.setDrawCircles(false);
|
||||
set2.setLineWidth(2f);
|
||||
set2.setCircleRadius(3f);
|
||||
set2.setFillAlpha(255);
|
||||
set2.setDrawFilled(true);
|
||||
set2.setFillColor(Color.WHITE);
|
||||
set2.setDrawCircleHole(false);
|
||||
set2.setHighLightColor(Color.rgb(244, 117, 117));
|
||||
set2.setFillFormatter(new FillFormatter() {
|
||||
@Override
|
||||
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
|
||||
return mChart.getAxisLeft().getAxisMaximum();
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
dataSets.add(set1); // add the datasets
|
||||
dataSets.add(set2);
|
||||
|
||||
// create a data object with the datasets
|
||||
LineData data = new LineData(dataSets);
|
||||
data.setDrawValues(false);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,266 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
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 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;
|
||||
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.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
protected HorizontalBarChart 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_horizontalbarchart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
|
||||
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
// mChart.setHighlightEnabled(false);
|
||||
|
||||
mChart.setDrawBarShadow(false);
|
||||
|
||||
mChart.setDrawValueAboveBar(true);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// 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);
|
||||
|
||||
// draw shadows for each bar that show the maximum value
|
||||
// mChart.setDrawBarShadow(true);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
XAxis xl = mChart.getXAxis();
|
||||
xl.setPosition(XAxisPosition.BOTTOM);
|
||||
xl.setTypeface(mTfLight);
|
||||
xl.setDrawAxisLine(true);
|
||||
xl.setDrawGridLines(false);
|
||||
xl.setGranularity(10f);
|
||||
|
||||
YAxis yl = mChart.getAxisLeft();
|
||||
yl.setTypeface(mTfLight);
|
||||
yl.setDrawAxisLine(true);
|
||||
yl.setDrawGridLines(true);
|
||||
yl.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
// yl.setInverted(true);
|
||||
|
||||
YAxis yr = mChart.getAxisRight();
|
||||
yr.setTypeface(mTfLight);
|
||||
yr.setDrawAxisLine(true);
|
||||
yr.setDrawGridLines(false);
|
||||
yr.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
// yr.setInverted(true);
|
||||
|
||||
setData(12, 50);
|
||||
mChart.setFitBars(true);
|
||||
mChart.animateY(2500);
|
||||
|
||||
// setting data
|
||||
mSeekBarY.setProgress(50);
|
||||
mSeekBarX.setProgress(12);
|
||||
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setFormSize(8f);
|
||||
l.setXEntrySpace(4f);
|
||||
}
|
||||
|
||||
@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: {
|
||||
List<IBarDataSet> sets = mChart.getData()
|
||||
.getDataSets();
|
||||
|
||||
for (IBarDataSet iSet : sets) {
|
||||
|
||||
IBarDataSet set = (BarDataSet) iSet;
|
||||
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()));
|
||||
|
||||
setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
private void setData(int count, float range) {
|
||||
|
||||
float barWidth = 9f;
|
||||
float spaceForBar = 10f;
|
||||
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
float val = (float) (Math.random() * range);
|
||||
yVals1.add(new BarEntry(i * spaceForBar, 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, "DataSet 1");
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set1);
|
||||
|
||||
BarData data = new BarData(dataSets);
|
||||
data.setValueTextSize(10f);
|
||||
data.setValueTypeface(mTfLight);
|
||||
data.setBarWidth(barWidth);
|
||||
mChart.setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onValueSelected(Entry e, Highlight h) {
|
||||
|
||||
if (e == null)
|
||||
return;
|
||||
|
||||
RectF bounds = mChart.getBarBounds((BarEntry) e);
|
||||
PointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
|
||||
.getAxisDependency());
|
||||
|
||||
Log.i("bounds", bounds.toString());
|
||||
Log.i("position", position.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
};
|
||||
}
|
|
@ -1,448 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
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 = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartGestureListener(this);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
// no description text
|
||||
mChart.setDescription("");
|
||||
mChart.setNoDataTextDescription("You need to provide data for the chart.");
|
||||
|
||||
// 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);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
|
||||
// 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(130f, "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.setAxisMaxValue(220f);
|
||||
leftAxis.setAxisMinValue(-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.setPosition(LegendPosition.LEFT_OF_CHART);
|
||||
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<ILineDataSet> sets = mChart.getData()
|
||||
.getDataSets();
|
||||
|
||||
for (ILineDataSet iSet : sets) {
|
||||
|
||||
LineDataSet set = (LineDataSet) iSet;
|
||||
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.actionToggleFilled: {
|
||||
|
||||
List<ILineDataSet> 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<ILineDataSet> 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<ILineDataSet> 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<ILineDataSet> 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<ILineDataSet> 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.EasingOption.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<Entry> values = new ArrayList<Entry>();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
float val = (float) (Math.random() * range) + 3;
|
||||
values.add(new Entry(i, val));
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// 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);
|
||||
|
||||
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<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
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.");
|
||||
}
|
||||
}
|
|
@ -1,242 +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 = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
mChart.setDescription("");
|
||||
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.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
}
|
||||
|
||||
@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<ILineDataSet> 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<ILineDataSet> 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<ILineDataSet> 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<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
|
||||
for (int z = 0; z < 3; z++) {
|
||||
|
||||
ArrayList<Entry> values = new ArrayList<Entry>();
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
|
@ -1,125 +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 = (TextView) findViewById(R.id.tvValueCount);
|
||||
mSeekBarValues = (SeekBar) findViewById(R.id.seekbarValues);
|
||||
mTvCount.setText("500");
|
||||
|
||||
mSeekBarValues.setProgress(500);
|
||||
|
||||
mSeekBarValues.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
// no description text
|
||||
mChart.setDescription("");
|
||||
mChart.setNoDataTextDescription("You need to provide data for the chart.");
|
||||
|
||||
// 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<Entry> yVals = new ArrayList<Entry>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,279 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
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.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.PieChart;
|
||||
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.PieData;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.data.PieEntry;
|
||||
import com.github.mikephil.charting.formatter.PercentFormatter;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PieChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
private PieChart 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_piechart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
|
||||
mSeekBarY.setProgress(10);
|
||||
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (PieChart) findViewById(R.id.chart1);
|
||||
mChart.setUsePercentValues(true);
|
||||
mChart.setDescription("");
|
||||
mChart.setExtraOffsets(5, 10, 5, 5);
|
||||
|
||||
mChart.setDragDecelerationFrictionCoef(0.95f);
|
||||
|
||||
mChart.setCenterTextTypeface(mTfLight);
|
||||
mChart.setCenterText(generateCenterSpannableText());
|
||||
|
||||
mChart.setDrawHoleEnabled(true);
|
||||
mChart.setHoleColor(Color.WHITE);
|
||||
|
||||
mChart.setTransparentCircleColor(Color.WHITE);
|
||||
mChart.setTransparentCircleAlpha(110);
|
||||
|
||||
mChart.setHoleRadius(58f);
|
||||
mChart.setTransparentCircleRadius(61f);
|
||||
|
||||
mChart.setDrawCenterText(true);
|
||||
|
||||
mChart.setRotationAngle(0);
|
||||
// enable rotation of the chart by touch
|
||||
mChart.setRotationEnabled(true);
|
||||
mChart.setHighlightPerTapEnabled(true);
|
||||
|
||||
// mChart.setUnit(" €");
|
||||
// mChart.setDrawUnitsInChart(true);
|
||||
|
||||
// add a selection listener
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
setData(4, 100);
|
||||
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
|
||||
// mChart.spin(2000, 0, 360);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setXEntrySpace(7f);
|
||||
l.setYEntrySpace(0f);
|
||||
l.setYOffset(0f);
|
||||
|
||||
// entry label styling
|
||||
mChart.setEntryLabelColor(Color.WHITE);
|
||||
mChart.setEntryLabelTypeface(mTfRegular);
|
||||
mChart.setEntryLabelTextSize(12f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.pie, 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.actionToggleHole: {
|
||||
if (mChart.isDrawHoleEnabled())
|
||||
mChart.setDrawHoleEnabled(false);
|
||||
else
|
||||
mChart.setDrawHoleEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionDrawCenter: {
|
||||
if (mChart.isDrawCenterTextEnabled())
|
||||
mChart.setDrawCenterText(false);
|
||||
else
|
||||
mChart.setDrawCenterText(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleXVals: {
|
||||
|
||||
mChart.setDrawEntryLabels(!mChart.isDrawEntryLabelsEnabled());
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
case R.id.actionTogglePercent:
|
||||
mChart.setUsePercentValues(!mChart.isUsePercentValuesEnabled());
|
||||
mChart.invalidate();
|
||||
break;
|
||||
case R.id.animateX: {
|
||||
mChart.animateX(1400);
|
||||
break;
|
||||
}
|
||||
case R.id.animateY: {
|
||||
mChart.animateY(1400);
|
||||
break;
|
||||
}
|
||||
case R.id.animateXY: {
|
||||
mChart.animateXY(1400, 1400);
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleSpin: {
|
||||
mChart.spin(1000, mChart.getRotationAngle(), mChart.getRotationAngle() + 360, Easing.EasingOption
|
||||
.EaseInCubic);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress()));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
setData(mSeekBarX.getProgress(), mSeekBarY.getProgress());
|
||||
}
|
||||
|
||||
private void setData(int count, float range) {
|
||||
|
||||
float mult = range;
|
||||
|
||||
ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
|
||||
|
||||
// NOTE: The order of the entries when being added to the entries array determines their position around the center of
|
||||
// the chart.
|
||||
for (int i = 0; i < count ; i++) {
|
||||
entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5), mParties[i % mParties.length]));
|
||||
}
|
||||
|
||||
PieDataSet dataSet = new PieDataSet(entries, "Election Results");
|
||||
dataSet.setSliceSpace(3f);
|
||||
dataSet.setSelectionShift(5f);
|
||||
|
||||
// add a lot of colors
|
||||
|
||||
ArrayList<Integer> colors = new ArrayList<Integer>();
|
||||
|
||||
for (int c : ColorTemplate.VORDIPLOM_COLORS)
|
||||
colors.add(c);
|
||||
|
||||
for (int c : ColorTemplate.JOYFUL_COLORS)
|
||||
colors.add(c);
|
||||
|
||||
for (int c : ColorTemplate.COLORFUL_COLORS)
|
||||
colors.add(c);
|
||||
|
||||
for (int c : ColorTemplate.LIBERTY_COLORS)
|
||||
colors.add(c);
|
||||
|
||||
for (int c : ColorTemplate.PASTEL_COLORS)
|
||||
colors.add(c);
|
||||
|
||||
colors.add(ColorTemplate.getHoloBlue());
|
||||
|
||||
dataSet.setColors(colors);
|
||||
//dataSet.setSelectionShift(0f);
|
||||
|
||||
PieData data = new PieData(dataSet);
|
||||
data.setValueFormatter(new PercentFormatter());
|
||||
data.setValueTextSize(11f);
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
data.setValueTypeface(mTfLight);
|
||||
mChart.setData(data);
|
||||
|
||||
// undo all highlights
|
||||
mChart.highlightValues(null);
|
||||
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
private SpannableString generateCenterSpannableText() {
|
||||
|
||||
SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
|
||||
s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
|
||||
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
|
||||
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
|
||||
s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
|
||||
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
|
||||
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueSelected(Entry e, Highlight h) {
|
||||
|
||||
if (e == null)
|
||||
return;
|
||||
Log.i("VAL SELECTED",
|
||||
"Value: " + e.getY() + ", index: " + h.getX()
|
||||
+ ", DataSet index: " + h.getDataSetIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
Log.i("PieChart", "nothing selected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
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.ScatterChart;
|
||||
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.Entry;
|
||||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.data.ScatterDataSet;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
private ScatterChart 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_scatterchart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (ScatterChart) findViewById(R.id.chart1);
|
||||
mChart.setDescription("");
|
||||
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setMaxHighlightDistance(50f);
|
||||
|
||||
// enable scaling and dragging
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setScaleEnabled(true);
|
||||
|
||||
mChart.setMaxVisibleValueCount(200);
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setTypeface(mTfLight);
|
||||
|
||||
YAxis yl = mChart.getAxisLeft();
|
||||
yl.setTypeface(mTfLight);
|
||||
yl.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
|
||||
XAxis xl = mChart.getXAxis();
|
||||
xl.setTypeface(mTfLight);
|
||||
xl.setDrawGridLines(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.scatter, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.actionToggleValues: {
|
||||
List<IScatterDataSet> sets = mChart.getData()
|
||||
.getDataSets();
|
||||
|
||||
for (IScatterDataSet iSet : sets) {
|
||||
|
||||
ScatterDataSet set = (ScatterDataSet) iSet;
|
||||
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.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals1.add(new Entry(i, val));
|
||||
}
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals2.add(new Entry(i+0.33f, val));
|
||||
}
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals3.add(new Entry(i+0.66f, val));
|
||||
}
|
||||
|
||||
// create a dataset and give it a type
|
||||
ScatterDataSet set1 = new ScatterDataSet(yVals1, "DS 1");
|
||||
set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
|
||||
set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
|
||||
ScatterDataSet set2 = new ScatterDataSet(yVals2, "DS 2");
|
||||
set2.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
|
||||
set2.setScatterShapeHoleColor(ColorTemplate.COLORFUL_COLORS[3]);
|
||||
set2.setScatterShapeHoleRadius(3f);
|
||||
set2.setColor(ColorTemplate.COLORFUL_COLORS[1]);
|
||||
ScatterDataSet set3 = new ScatterDataSet(yVals3, "DS 3");
|
||||
set3.setShapeRenderer(new CustomScatterShapeRenderer());
|
||||
set3.setColor(ColorTemplate.COLORFUL_COLORS[2]);
|
||||
|
||||
set1.setScatterShapeSize(8f);
|
||||
set2.setScatterShapeSize(8f);
|
||||
set3.setScatterShapeSize(8f);
|
||||
|
||||
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
|
||||
dataSets.add(set1); // add the datasets
|
||||
dataSets.add(set2);
|
||||
dataSets.add(set3);
|
||||
|
||||
// create a data object with the datasets
|
||||
ScatterData data = new ScatterData(dataSets);
|
||||
data.setValueTypeface(mTfLight);
|
||||
|
||||
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) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
|
@ -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 = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// 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<BarEntry> yVals = new ArrayList<BarEntry>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,260 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
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 com.github.mikephil.charting.charts.BarChart;
|
||||
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;
|
||||
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.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListener, OnChartValueSelectedListener {
|
||||
|
||||
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 = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
// if more than 60 entries are displayed in the chart, no values will be
|
||||
// drawn
|
||||
mChart.setMaxVisibleValueCount(40);
|
||||
|
||||
// scaling can now only be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
mChart.setDrawBarShadow(false);
|
||||
|
||||
mChart.setDrawValueAboveBar(false);
|
||||
mChart.setHighlightFullBarEnabled(false);
|
||||
|
||||
// change the position of the y-labels
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.setValueFormatter(new MyAxisValueFormatter());
|
||||
leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
|
||||
XAxis xLabels = mChart.getXAxis();
|
||||
xLabels.setPosition(XAxisPosition.TOP);
|
||||
|
||||
// mChart.setDrawXLabels(false);
|
||||
// mChart.setDrawYLabels(false);
|
||||
|
||||
// setting data
|
||||
mSeekBarX.setProgress(12);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
|
||||
l.setFormSize(8f);
|
||||
l.setFormToTextSpace(4f);
|
||||
l.setXEntrySpace(6f);
|
||||
|
||||
// mChart.setDrawLegend(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: {
|
||||
List<IBarDataSet> sets = mChart.getData()
|
||||
.getDataSets();
|
||||
|
||||
for (IBarDataSet iSet : sets) {
|
||||
|
||||
BarDataSet set = (BarDataSet) iSet;
|
||||
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<BarEntry> yVals1 = new ArrayList<BarEntry>();
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val1 = (float) (Math.random() * mult) + mult / 3;
|
||||
float val2 = (float) (Math.random() * mult) + mult / 3;
|
||||
float val3 = (float) (Math.random() * mult) + mult / 3;
|
||||
|
||||
yVals1.add(new BarEntry(i, new float[]{val1, val2, val3}));
|
||||
}
|
||||
|
||||
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, "Statistics Vienna 2014");
|
||||
set1.setColors(getColors());
|
||||
set1.setStackLabels(new String[]{"Births", "Divorces", "Marriages"});
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set1);
|
||||
|
||||
BarData data = new BarData(dataSets);
|
||||
data.setValueFormatter(new MyValueFormatter());
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueSelected(Entry e, Highlight h) {
|
||||
|
||||
BarEntry entry = (BarEntry) e;
|
||||
|
||||
if (entry.getYVals() != null)
|
||||
Log.i("VAL SELECTED", "Value: " + entry.getYVals()[h.getStackIndex()]);
|
||||
else
|
||||
Log.i("VAL SELECTED", "Value: " + entry.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private int[] getColors() {
|
||||
|
||||
int stacksize = 3;
|
||||
|
||||
// have as many colors as stack-values per entry
|
||||
int[] colors = new int[stacksize];
|
||||
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = ColorTemplate.MATERIAL_COLORS[i];
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
}
|
|
@ -1,248 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
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;
|
||||
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.formatter.ValueFormatter;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
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.ViewPortHandler;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StackedBarActivityNegative extends DemoBase implements
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
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_age_distribution);
|
||||
|
||||
setTitle("Age Distribution Austria");
|
||||
|
||||
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setDrawGridBackground(false);
|
||||
mChart.setDescription("");
|
||||
|
||||
// scaling can now only be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
mChart.setDrawBarShadow(false);
|
||||
mChart.setDrawValueAboveBar(true);
|
||||
mChart.setHighlightFullBarEnabled(false);
|
||||
|
||||
mChart.getAxisLeft().setEnabled(false);
|
||||
mChart.getAxisRight().setAxisMaxValue(25f);
|
||||
mChart.getAxisRight().setAxisMinValue(-25f);
|
||||
mChart.getAxisRight().setDrawGridLines(false);
|
||||
mChart.getAxisRight().setDrawZeroLine(true);
|
||||
mChart.getAxisRight().setLabelCount(7, false);
|
||||
mChart.getAxisRight().setValueFormatter(new CustomFormatter());
|
||||
mChart.getAxisRight().setTextSize(9f);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
|
||||
xAxis.setDrawGridLines(false);
|
||||
xAxis.setDrawAxisLine(false);
|
||||
xAxis.setTextSize(9f);
|
||||
xAxis.setAxisMinValue(0f);
|
||||
xAxis.setAxisMaxValue(110f);
|
||||
xAxis.setCenterAxisLabels(true);
|
||||
xAxis.setLabelCount(12);
|
||||
xAxis.setGranularity(10f);
|
||||
xAxis.setValueFormatter(new AxisValueFormatter() {
|
||||
|
||||
private DecimalFormat format = new DecimalFormat("###");
|
||||
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return format.format(value) + "-" + format.format(value + 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
|
||||
l.setFormSize(8f);
|
||||
l.setFormToTextSpace(4f);
|
||||
l.setXEntrySpace(6f);
|
||||
|
||||
// IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
|
||||
ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
|
||||
yValues.add(new BarEntry(5, new float[]{ -10, 10 }));
|
||||
yValues.add(new BarEntry(15, new float[]{ -12, 13 }));
|
||||
yValues.add(new BarEntry(25, new float[]{ -15, 15 }));
|
||||
yValues.add(new BarEntry(35, new float[]{ -17, 17 }));
|
||||
yValues.add(new BarEntry(45, new float[]{ -19, 20 }));
|
||||
yValues.add(new BarEntry(55, new float[]{ -19, 19 }));
|
||||
yValues.add(new BarEntry(65, new float[]{ -16, 16 }));
|
||||
yValues.add(new BarEntry(75, new float[]{ -13, 14 }));
|
||||
yValues.add(new BarEntry(85, new float[]{ -10, 11 }));
|
||||
yValues.add(new BarEntry(95, new float[]{ -5, 6 }));
|
||||
yValues.add(new BarEntry(105, new float[]{ -1, 2 }));
|
||||
|
||||
BarDataSet set = new BarDataSet(yValues, "Age Distribution");
|
||||
set.setValueFormatter(new CustomFormatter());
|
||||
set.setValueTextSize(7f);
|
||||
set.setAxisDependency(YAxis.AxisDependency.RIGHT);
|
||||
set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)});
|
||||
set.setStackLabels(new String[]{
|
||||
"Men", "Women"
|
||||
});
|
||||
|
||||
String []xLabels = new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+"};
|
||||
|
||||
BarData data = new BarData(set);
|
||||
data.setBarWidth(8.5f);
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
@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: {
|
||||
List<IBarDataSet> sets = mChart.getData()
|
||||
.getDataSets();
|
||||
|
||||
for (IBarDataSet iSet : sets) {
|
||||
|
||||
BarDataSet set = (BarDataSet) iSet;
|
||||
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 onValueSelected(Entry e, Highlight h) {
|
||||
|
||||
BarEntry entry = (BarEntry) e;
|
||||
Log.i("VAL SELECTED",
|
||||
"Value: " + Math.abs(entry.getYVals()[h.getStackIndex()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
// TODO Auto-generated method stub
|
||||
Log.i("NOTING SELECTED", "");
|
||||
}
|
||||
|
||||
private class CustomFormatter implements ValueFormatter, AxisValueFormatter {
|
||||
|
||||
private DecimalFormat mFormat;
|
||||
|
||||
public CustomFormatter() {
|
||||
mFormat = new DecimalFormat("###");
|
||||
}
|
||||
|
||||
// data
|
||||
@Override
|
||||
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
|
||||
return mFormat.format(Math.abs(value)) + "m";
|
||||
}
|
||||
|
||||
// YAxis
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return mFormat.format(Math.abs(value)) + "m";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Custom shape renderer that draws a single line.
|
||||
* Created by philipp on 26/06/16.
|
||||
*/
|
||||
public class CustomScatterShapeRenderer implements ShapeRenderer {
|
||||
|
||||
@Override
|
||||
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, ScatterBuffer buffer, Paint
|
||||
renderPaint, float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!viewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!viewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !viewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
renderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
renderPaint);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class MyAxisValueFormatter implements AxisValueFormatter {
|
||||
|
||||
private DecimalFormat mFormat;
|
||||
|
||||
public MyAxisValueFormatter() {
|
||||
mFormat = new DecimalFormat("###,###,###,##0.0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return mFormat.format(value) + " $";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 1;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import com.github.mikephil.charting.animation.EasingFunction;
|
||||
|
||||
/**
|
||||
* Example of a custom made animation EasingFunction.
|
||||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class MyEasingFunction implements EasingFunction {
|
||||
|
||||
@Override
|
||||
public float getInterpolation(float input) {
|
||||
// do awesome stuff here, this is just linear easing
|
||||
return input;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.formatter.ValueFormatter;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class MyValueFormatter implements ValueFormatter {
|
||||
|
||||
private DecimalFormat mFormat;
|
||||
|
||||
public MyValueFormatter() {
|
||||
mFormat = new DecimalFormat("###,###,###,##0.0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
|
||||
return mFormat.format(value) + " $";
|
||||
}
|
||||
}
|
|
@ -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<RealmFloat> 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<RealmFloat>();
|
||||
|
||||
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<RealmFloat> getStackValues() {
|
||||
return stackValues;
|
||||
}
|
||||
|
||||
public void setStackValues(RealmList<RealmFloat> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.fragments;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
|
||||
public class SineCosineFragment extends SimpleFragment {
|
||||
|
||||
public static Fragment newInstance() {
|
||||
return new SineCosineFragment();
|
||||
}
|
||||
|
||||
private LineChart mChart;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.frag_simple_line, container, false);
|
||||
|
||||
mChart = (LineChart) v.findViewById(R.id.lineChart1);
|
||||
|
||||
mChart.setDescription("");
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
mChart.setData(generateLineData());
|
||||
mChart.animateX(3000);
|
||||
|
||||
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setTypeface(tf);
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.setTypeface(tf);
|
||||
leftAxis.setAxisMaxValue(1.2f);
|
||||
leftAxis.setAxisMinValue(-1.2f);
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setEnabled(false);
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<ContentItem> {
|
||||
|
||||
private Typeface mTypeFaceLight;
|
||||
private Typeface mTypeFaceRegular;
|
||||
|
||||
public MyAdapter(Context context, List<ContentItem> 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 = (TextView) convertView.findViewById(R.id.tvName);
|
||||
holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
|
||||
holder.tvNew = (TextView) 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;
|
||||
}
|
||||
}
|
|
@ -1,203 +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.setDescription("");
|
||||
chart.setNoDataTextDescription("You need to provide data for the chart.");
|
||||
|
||||
// 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(getApplicationContext()).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();
|
||||
}
|
||||
}
|
|
@ -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 = (BarChart) 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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "xValue", "yValue"); // stacked entries
|
||||
set.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
|
||||
set.setLabel("Realm BarDataSet");
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
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.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -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 = (BubbleChart) 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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmBubbleDataSet<RealmDemoData> set = new RealmBubbleDataSet<RealmDemoData>(result, "xValue", "yValue", "bubbleSize");
|
||||
set.setLabel("Realm BubbleDataSet");
|
||||
set.setColors(ColorTemplate.COLORFUL_COLORS, 110);
|
||||
|
||||
ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
|
||||
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.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -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 = (CandleStickChart) 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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(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<ICandleDataSet> dataSets = new ArrayList<ICandleDataSet>();
|
||||
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.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -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 = (HorizontalBarChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setAxisMinValue(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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(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<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
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.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,77 +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.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 = (LineChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setAxisMaxValue(150f);
|
||||
mChart.getAxisLeft().setAxisMinValue(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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setDrawCubic(false);
|
||||
set.setLabel("Realm LineDataSet");
|
||||
set.setDrawCircleHole(false);
|
||||
set.setColor(ColorTemplate.rgb("#FF5722"));
|
||||
set.setCircleColor(ColorTemplate.rgb("#FF5722"));
|
||||
set.setLineWidth(1.8f);
|
||||
set.setCircleSize(3.6f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
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.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,83 +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 = (PieChart) 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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label"); // stacked entries
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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 = (RadarChart) 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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(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<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>();
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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 = (ScatterChart) 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<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setLabel("Realm ScatterDataSet");
|
||||
set.setScatterShapeSize(9f);
|
||||
set.setColor(ColorTemplate.rgb("#CDDC39"));
|
||||
set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
|
||||
|
||||
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
|
||||
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.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,131 +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<ContentItem> objects = new ArrayList<ContentItem>();
|
||||
|
||||
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 = (ListView) findViewById(R.id.listView1);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
lv.setOnItemClickListener(this);
|
||||
|
||||
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
|
||||
RealmConfiguration realmConfig = new RealmConfiguration.Builder(getApplicationContext()).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);
|
||||
}
|
||||
}
|
|
@ -1,137 +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.realm.implementation.RealmBarDataSet;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
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 = (LineChart) findViewById(R.id.lineChart);
|
||||
barChart = (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<Score> results = mRealm.where(Score.class).findAll();
|
||||
|
||||
|
||||
AxisValueFormatter formatter = new AxisValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return results.get((int) value).getPlayerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
lineChart.getXAxis().setValueFormatter(formatter);
|
||||
barChart.getXAxis().setValueFormatter(formatter);
|
||||
|
||||
RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
|
||||
lineDataSet.setDrawCubic(false);
|
||||
lineDataSet.setLabel("Result Scores");
|
||||
lineDataSet.setDrawCircleHole(false);
|
||||
lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
|
||||
lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
|
||||
lineDataSet.setLineWidth(1.8f);
|
||||
lineDataSet.setCircleSize(3.6f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
dataSets.add(lineDataSet);
|
||||
|
||||
LineData lineData = new LineData(dataSets);
|
||||
styleData(lineData);
|
||||
|
||||
// set data
|
||||
lineChart.setData(lineData);
|
||||
lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
|
||||
|
||||
// BAR-CHART
|
||||
RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
|
||||
barDataSet.setColors(new int[]{ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
|
||||
barDataSet.setLabel("Realm BarDataSet");
|
||||
|
||||
ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
|
||||
barDataSets.add(barDataSet);
|
||||
|
||||
BarData barData = new BarData(barDataSets);
|
||||
styleData(barData);
|
||||
|
||||
barChart.setData(barData);
|
||||
barChart.setFitBars(true);
|
||||
barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
57
MPChartExample/src/main/AndroidManifest.xml
Normal file
57
MPChartExample/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.xxmassdeveloper.mpchartexample">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.xxmassdeveloper.mpchartexample.notimportant.MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="LineChartActivity1" />
|
||||
<activity android:name="LineChartActivity2" />
|
||||
<activity android:name="LineChartTime" />
|
||||
<activity android:name="BarChartActivity" />
|
||||
<activity android:name="HorizontalBarChartActivity" />
|
||||
<activity android:name="HorizontalBarNegativeChartActivity" />
|
||||
<activity android:name="PieChartActivity" />
|
||||
<activity android:name="PiePolylineChartActivity" />
|
||||
<activity android:name="MultiLineChartActivity" />
|
||||
<activity android:name="BarChartActivityMultiDataset" />
|
||||
<activity android:name="DrawChartActivity" />
|
||||
<activity android:name="ScatterChartActivity" />
|
||||
<activity android:name="BubbleChartActivity" />
|
||||
<activity android:name=".fragments.SimpleChartDemo" />
|
||||
<activity android:name="ListViewBarChartActivity" />
|
||||
<activity android:name="ListViewMultiChartActivity" />
|
||||
<activity android:name="StackedBarActivity" />
|
||||
<activity android:name="AnotherBarActivity" />
|
||||
<activity android:name="InvertedLineChartActivity" />
|
||||
<activity android:name="CandleStickChartActivity" />
|
||||
<activity android:name="CubicLineChartActivity" />
|
||||
<activity android:name="RadarChartActivity" />
|
||||
<activity android:name="LineChartActivityColored" />
|
||||
<activity android:name="DynamicalAddingActivity" />
|
||||
<activity android:name="RealtimeLineChartActivity" />
|
||||
<activity android:name="CombinedChartActivity" />
|
||||
<activity android:name="PerformanceLineChart" />
|
||||
<activity android:name="BarChartActivitySinus" />
|
||||
<activity android:name="ScrollViewActivity" />
|
||||
<activity android:name="StackedBarActivityNegative" />
|
||||
<activity android:name="BarChartPositiveNegative" />
|
||||
<activity android:name="FilledLineActivity" />
|
||||
<activity android:name="HalfPieChartActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 4 KiB |
|
@ -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<BarEntry> 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<IBarDataSet> 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) {}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue