Compare commits

...

166 commits

Author SHA1 Message Date
yoksnod
a6c3808fd5
Merge pull request #2 from yoksnod/marker-interface-improvements
Added jitpack integration
2020-02-12 14:54:18 +03:00
Dmitry Donskoy
941579e10f Added jitpack integration 2020-02-12 14:53:16 +03:00
yoksnod
21c811ff9a
Merge pull request #1 from yoksnod/marker-interface-improvements
Modified and expanded, made more flexible  marker interaction interface
2020-02-12 14:49:13 +03:00
Dmitry Donskoy
f3a2ec21c9 Modified and expanded, made more flexible marker interaction interface 2020-02-12 14:47:18 +03:00
Daniel Cohen Gindi
9347dd1af7
Merge pull request #4802 from oatrice/fix_crash_solid_color_barchart
fix NPE when use solid color with barchart
2020-02-09 07:34:02 +02:00
Anirut Teerabut
90e523042c
Update BarChartRenderer.java 2020-02-07 22:09:57 +07:00
Anirut Teerabut
33240f9225
Update HorizontalBarChartRenderer.java 2020-02-07 22:09:07 +07:00
Anirut Teerabut
4b67673da9
Update BarChartRenderer.java 2020-02-07 22:03:20 +07:00
Anirut Teerabut
cef967fd71 fix NPE when use solid color with barchart 2020-02-07 17:53:40 +07:00
Daniel Cohen Gindi
eae977306e Merge branch 'fill'
* fill:
  Implement a more generic Fill class instead of GradientColor
2020-01-24 12:53:07 +02:00
Daniel Cohen Gindi
c0e7f56b5d Implement a more generic Fill class instead of GradientColor
Support HorizontalBarChart too.
2020-01-24 12:52:27 +02:00
Daniel Cohen Gindi
351e341ee7 Fixed merge residue 2020-01-24 11:42:03 +02:00
Daniel Cohen Gindi
f05337768d Finalized vertical line collision check 2020-01-23 15:45:57 +02:00
Daniel Cohen Gindi
f8d068d377
Merge pull request #4787 from danielgindi/feature/catching_up_to_ios
Feature/catching up to ios
2020-01-23 15:38:53 +02:00
Daniel Cohen Gindi
5e4a32eb41 Corrected check for line in vertical bounds
https://github.com/danielgindi/Charts/pull/4100
2020-01-23 12:09:06 +02:00
Daniel Cohen Gindi
1de836ac65 Remove unexpected dash line during linear animation
https://github.com/danielgindi/Charts/pull/4094
2020-01-23 11:19:07 +02:00
Daniel Cohen Gindi
0668d30a6b Fixed a bug where a pie slice without highlight enabled is hidden
https://github.com/danielgindi/Charts/pull/3969
2020-01-23 10:54:28 +02:00
Daniel Cohen Gindi
34fefd28e1 maxHeight didn't account for the last label
https://github.com/danielgindi/Charts/pull/3900
2020-01-23 10:18:28 +02:00
Daniel Cohen Gindi
45240c3723 Improved negative offset for horz bar chart
https://github.com/danielgindi/Charts/pull/3854
2020-01-22 16:01:42 +02:00
Daniel Cohen Gindi
14456f475f Renamed values -> entries for consistency
https://github.com/danielgindi/Charts/pull/3847
2020-01-22 14:24:37 +02:00
Daniel Cohen Gindi
e02e9be2fa Multiple colors for valueline
https://github.com/danielgindi/Charts/pull/3709
2020-01-22 14:13:31 +02:00
Daniel Cohen Gindi
fcc5af71ce Call onChartScale listener after double-tap-zoom
https://github.com/danielgindi/Charts/pull/3770
2020-01-22 13:49:10 +02:00
Daniel Cohen Gindi
13aee592b1 Improve min/max calculation
https://github.com/danielgindi/Charts/pull/3650
2020-01-22 13:43:42 +02:00
Daniel Cohen Gindi
c97c8d247f Fixed index out of bounds issue when using stacked bar chart
b03cf16ec4
2020-01-22 13:23:12 +02:00
Daniel Cohen Gindi
ae59e7a19e This is for the inline bubble selection
https://github.com/danielgindi/Charts/pull/3548
2020-01-22 13:12:04 +02:00
Daniel Cohen Gindi
7752efef7e Support for labelXOffset for YAxis label 2020-01-22 13:04:11 +02:00
Daniel Cohen Gindi
58545bbbfa Add option to disable clipping data to contentRect
https://github.com/danielgindi/Charts/pull/3360
2020-01-22 12:46:37 +02:00
Daniel Cohen Gindi
4ce14e6cc9 Add a warning message if pie chart has more than one data set
https://github.com/danielgindi/Charts/pull/3286
2020-01-22 12:42:32 +02:00
Daniel Cohen Gindi
8df9eda7af Call notifyDataChanged for an opportunity for subclasses 2020-01-22 12:39:03 +02:00
Daniel Cohen Gindi
34c3ceaa05 Reset min/max when clearing ChartDataSet
https://github.com/danielgindi/Charts/pull/3265
2020-01-22 12:29:47 +02:00
Daniel Cohen Gindi
ea816e8d6d Added dataIndex param for highlightValue (combined charts)
https://github.com/danielgindi/Charts/pull/2852
2020-01-22 12:25:34 +02:00
Daniel Cohen Gindi
bafb0fbbe4 Use correct color index for bubble chart
https://github.com/danielgindi/Charts/pull/3202
2020-01-22 12:16:48 +02:00
Daniel Cohen Gindi
4549ae17b7 Select correct axis for legend distance calculation in horz bar chart
https://github.com/danielgindi/Charts/pull/2214
2020-01-22 12:15:02 +02:00
Daniel Cohen Gindi
912427e543 Custom text alignment for no-data
https://github.com/danielgindi/Charts/pull/3199
2020-01-22 12:07:37 +02:00
Daniel Cohen Gindi
3f5475077e Avoid race condition for interval/intervalMagnitude
https://github.com/danielgindi/Charts/pull/2377
2020-01-22 11:59:43 +02:00
Daniel Cohen Gindi
2e725e49d3 Make min/max axis labels configurable
https://github.com/danielgindi/Charts/pull/2894
2020-01-22 11:54:08 +02:00
Daniel Cohen Gindi
a4ca1f3fba Fixed axis label disappearing when zooming in
https://github.com/danielgindi/Charts/pull/3132
2020-01-22 11:47:45 +02:00
Daniel Cohen Gindi
634a690d6a Added an implementation of Douglas Peucker with resultCount input
https://github.com/danielgindi/Charts/pull/2848
2020-01-22 11:44:27 +02:00
Daniel Cohen Gindi
1987d7eb64 Consider axis dependency in Combined chart
https://github.com/danielgindi/Charts/pull/2874
2020-01-22 11:04:57 +02:00
Daniel Cohen Gindi
6ebf3fa57a Added highlightColor parameter for pie charts
https://github.com/danielgindi/Charts/pull/2961
2020-01-22 10:27:55 +02:00
Daniel Cohen Gindi
95027fa6a7 Safe guards
These will be even more important when moving to Kotlin ranges
2020-01-22 09:55:00 +02:00
Philipp Jahoda
d86f39cc91
Update README.md 2020-01-20 11:15:12 +01:00
Philipp Jahoda
cb26ed4ef4
Update FUNDING.yml 2019-10-08 14:15:52 +02:00
Philipp Jahoda
dc59171524
Create FUNDING.yml 2019-10-08 14:15:21 +02:00
Philipp Jahoda
726616d079 Merge branch 'master' of github.com:PhilJay/MPAndroidChart 2019-04-27 17:38:41 +02:00
Philipp Jahoda
fffe9a297e Update gradle 2019-04-27 17:38:37 +02:00
Philipp Jahoda
2340e12800
Merge pull request #4512 from duchampdev/percent_formatter_sign_spacing
PercentFormatter: make space between number and percent sign optional
2019-04-27 17:37:13 +02:00
duchampdev
c5667d4f14 fix little typo 2019-04-27 16:06:37 +02:00
duchampdev
0563fb48b0 PercentFormatter: make space between number and percent sign optional 2019-04-27 16:06:10 +02:00
Philipp Jahoda
ed8876cef2
Update README.md 2019-04-07 16:37:14 +02:00
Philipp Jahoda
12b4351d0c
Update README.md 2019-04-07 16:27:59 +02:00
Philipp Jahoda
adb56e75bd
Update README.md 2019-04-07 16:20:14 +02:00
Philipp Jahoda
e95c1eb26a
Update README.md 2019-03-20 17:56:58 +01:00
Philipp Jahoda
0c2ac2d9cc New example app release 2019-03-16 11:53:42 +01:00
Philipp Jahoda
2058f7bf5d Minor changes to project and example 2019-03-16 11:42:04 +01:00
Philipp Jahoda
971640b29d
Update Support_help.md 2019-02-21 09:05:06 +01:00
Philipp Jahoda
7df8a4cedc
Update Feature_request.md 2019-02-21 09:04:40 +01:00
Philipp Jahoda
59028d3bf3
Update Bug_report.md 2019-02-21 09:04:28 +01:00
Philipp Jahoda
c886bb342a
Update README.md 2019-02-20 22:51:10 +01:00
almic
aea2ff3417
Add option to set minimum angles
Allows to force minimum slice angles when drawing charts, which means that any
slices with angles lower than the minimum will be drawn with the minimum angle.

When changing this setting on the fly, you have to call
`notifyDataSetChanged()` and `invalidate()` for the minimum angle to take
effect.

This only functions if all slices can be drawn with the minimum angle. For
example if a chart has 5 slices, the largest functioning minimum angle is
`72f` degrees on a 360 degree chart, or 20% of the chart's `maxAngle`.
2018-11-15 09:51:46 -07:00
almic
42cdba535f
Add Curved Slices to Pie Chart
Finally added support for rounded slices, and somewhat improved the code
for the PieChartRenderer class.
2018-11-12 10:59:48 -07:00
almic
29f4cc5c2c
Remove unnecessary API checks
Also added run configuration for the MPChartExample.
Removed deprecated Legend stuff.
2018-11-11 09:40:37 -07:00
almic
fc0e234298
Remove Deprecated Things
Long deprecated Legend constructor and positioning has been removed, it was
replaced with a new way to position the Legend.

The old Easing options have been removed now, accessing them is as easy as
removing the `EasingOption` part, such that the names look like
`Easing.Linear` or `Easing.EaseInOutQuad` now.
2018-11-07 14:52:25 -07:00
almic
e5b66192e7
New ValueFormatter
I created a simplified value formatter class, which is an abstract class rather
than an interface.

The switch was chosen because the new format has all the methods predefined
(something an interface wouldn't allow) meaning you can extend it and only
change what you want. This also means that you only need one value formatting
class for labels rather than two different classes, it just makes more sense.

Please check the method signatures to learn how to use them, I'm sure you'll
find this new format is much more customizable and faster to use.

I've made the class abstract even though there are no abstract methods or
fields, this is because it would certainly be a mistake to create a
ValueFormatter and not override any methods.

To convert existing code, just use 'extends' instead of 'implements' and change
the names to 'ValueFormatter'. You'll need to change the methods you overwrite
as well, just check the class and use the one you need.
2018-11-07 12:41:53 -07:00
Mick A
608d9e29f5
Fix link error 2018-10-30 08:59:58 -06:00
almic
9148f37f9e
Bump version to 3.1.0-alpha 2018-10-29 13:23:18 -06:00
Mick A
6ce99326ae
Merge pull request #2273 from vpop/update/unused-local
Remove unused local variable
2018-10-27 21:56:40 -06:00
Mick A
129ad15fd0
Merge pull request #2187 from vpop/update/redundant-nullcheck
Remove nullcheck for known non-null variable
2018-10-27 21:42:36 -06:00
almic
5030b36c86
More Cleanup
I've removed the realm examples, mainly because the library was buggy.
In the previous commit, I already removed the examples from the list
since they didn't add anything to the overall demonstration. I thought
that if anyone wants to use realm.io with the charts, they can see the
actual library.

The file structure has been updated to match how Android Studio does
things. Some files added way back when have been deleted as they don't
do anything but cause the linter to freak out about 'unused properties'

All 'build.gradle' files have been refreshed as well.

Small addition to the README file to add a quick way to reach sections
of the page.
2018-10-27 18:00:06 -06:00
almic
db7dda2b7e
More Linting
Lots of things in the example app are now marked with the 'final' modifier, and saveToGallery() is protected in classes that implement it. As well, new suppressions are in a few places.

NEW text is now removed completely. Looks like this has been unused for a long time and it's just stuck around anyway.
2018-10-27 14:02:04 -06:00
almic
d67ea481af
Huge Project Refresh
Before anyone freaks out, all these changes are under-the-hood, meaning that you probably won't even notice them at all.

The biggest difference is raising the minSdkVersion from 9 to 14. Recently android bumped this number interally as there are basically no devices running lower than 14 anymore. Sorry but you are just wasting your time if you are trying to support anything lower than 14 now.

The next biggest change is updating the project to the new AndroidX libraries, which changes some imports and nothing else really.

The third biggest change is fixing a few bugs in the code that cause values to be drawn even if there are none, which results in your app crashing. Surprisingly, these checks already existed in a few of the newer chart types, but most lacked this simple check.

Other than those three changes, nothing else is functionally different. Well, saving to gallery works on all charts in the example app now, and you can quickly see the code for each example in the menus.

The only real potential "breaking" change is that charts are now saved as PNGs by default instead of JPGs if you go the route of not specifying as a JPG. You may want to double check your file sizes as PNGs can be larger than low quality JPGs.

I still have more plans for simplifying the API and fixing other issues with the project, for the small few that closely pay attention to individual commits: there's going to be more soon.
2018-10-26 10:30:22 -06:00
Philipp Jahoda
20bca4a8ca
Update README.md 2018-08-26 20:31:44 +02:00
Philipp Jahoda
e2a9110d38
Update README.md 2018-08-26 20:31:00 +02:00
Philipp Jahoda
2316f8500f
Update README.md 2018-08-26 20:21:49 +02:00
Philipp Jahoda
6f0b7432ac
Update README.md 2018-08-26 20:21:19 +02:00
Philipp Jahoda
073ad3c877
Update README.md 2018-08-26 20:14:32 +02:00
Philipp Jahoda
c1f6fcebf0
Update README.md 2018-06-06 09:14:41 +02:00
Philipp Jahoda
b65ba08324
Update README.md 2018-05-15 15:57:09 +02:00
Mick A
fe7a0f8bc3
Merge pull request #4018 from RobertZagorski/feature/remove-redundant-findViewById-casts
[Enhancement] Remove redundant findViewById casts in example application
2018-05-12 21:28:06 -06:00
almic
536a35a6fd
docs(README): Update & simplify README
- Re-ordered some of the sections
- Simplified some sections
- Reformatted here and there
- Added a few emojis, how cute!

The goal of this change was to hopefully further reduce the amount of
issue support/ question spam. By moving the sections around to show the
more important parts higher up, like usage and documentation links, I
hope this will make it easier for people to find the documentation.
2018-05-10 11:03:03 -06:00
RobertZagorski
75dd04cc42 Remove redundant findViewById casts, that became obsolete after migration to API 26. 2018-05-10 08:01:03 +02:00
Mick A
1485cdc687
Merge pull request #3451 from davidgoli/add-grid-lines-on-top-of-data
Add option to draw limit lines on top of data
2018-05-09 09:12:49 -06:00
Mick A
53de181607
Merge pull request #3478 from MaximPestryakov/patch-1
Refactored LargeValueFormatter
2018-05-09 09:07:06 -06:00
Mick A
9ee3a74633
Merge pull request #4013 from RobertZagorski/bugfix/#2369-legend-offset-is-not-calculated-twice-for-line-chart
Remove mLabelRotatedHeight counted twice, when calculating legend offset
2018-05-09 08:36:07 -06:00
Mick A
73054bedc3
Merge pull request #3642 from pagrzybe/autoscale_restrictions
Option to set restrictions for Y axis autoscaling.
2018-05-09 08:29:22 -06:00
Maxim Pestryakov
5869c9de23
Fixed Javadoc 2018-05-09 16:03:48 +03:00
RobertZagorski
89436221db Remove mLabelRotatedHeight counted twice, when calculating legend offsets. (Fix for #2369).
Removed statements where completely not needed as calculating offsets is alredy done in BarLineCharBase#calculateOffsets(...)
2018-05-09 08:44:22 +02:00
Pawel Grzybek
92c14db5b4 Fixed code review comments. 2018-05-09 08:09:03 +02:00
Mick A
0b6632f2cb
Merge pull request #4008 from RobertZagorski/bugfix/#1604-update-and-reorganise--copy-data-sets-methods
Update and reorganise copy data sets methods (Fix for #1604).
2018-05-08 09:42:03 -06:00
RobertZagorski
7abc9cd669 Update and reorganise copy data sets methods (Fix for #1604).
Copying class properties is always done in protected copy method.
2018-05-08 16:19:09 +02:00
almic
9583a18b84
chore(template): Move templates to .github folder 2018-05-06 00:29:31 -06:00
almic
03c538fc34
docs(templates): Update Issue & PR templates
I've updated the issue and pull request templates, again. This time I
looked to the node.js request library for inspiration.

It's no secret that this project has been attracting a LOT of very
low-quality issues. Almost all are asking questions that can be easily
answered if the person looked at the example project or the wiki.

Specifically, the new Support_help.md file.

This file will hopefully bait these low-quality support questions and
reduce the number of opened issues regarding debugging or support
significantly.

I've updated the default ISSUE_TEMPLATE.md to be a copy of Bug_report.md
to force people to read that notice text if they decide to not choose
any of the templates.
2018-05-06 00:27:57 -06:00
Mick A
c08ec81fc0
Merge pull request #4001 from oatrice/feature/muti_gradient
[Feature] Multiple gradient color for barchart
2018-05-05 09:18:14 -06:00
Anirut Teerabut
e4ba3cdc20 - multiple gradient color 2018-05-04 04:21:26 +07:00
almic
689d484615
Delete lingering MyEasingFunction.java
I made the decision to remove this file instead of updating it, as I'm
sure most will instead prefer to look at the actual Easing class. If you
miss this example class... ¯\_(ツ)_/¯
2018-05-03 08:37:00 -06:00
Philipp Jahoda
9b9d2a68cb
Update README.md 2018-05-03 16:22:32 +02:00
Mick A
0378e763ae
Merge pull request #2856 from stephenmcbride/master
Fix for missing setters in getInstance method
2018-05-02 10:42:40 -06:00
Mick A
1ff676ecaf
Update CONTRIBUTING.md
Condensed CONTRIBUTING and added helpful reference links.

And cake!
2018-05-02 00:44:47 -06:00
Mick A
00e284c043
Update Bug_report.md
quick fix
2018-05-01 23:02:01 -06:00
Mick A
a7eb395b81
Downgrade ISSUE_TEMPLATE.md to generic issue 2018-05-01 22:59:06 -06:00
Mick A
11bf7aa812 Update issue templates 2018-05-01 22:57:40 -06:00
Mick A
89e50c8c9b
Merge pull request #3982 from almic/yaxis-calc
Remove YAxis Custom Min/Max Check for Padding
2018-05-01 21:29:15 -06:00
Mick A
640208c8ff
Merge pull request #3820 from longup/master
Fix last entry clipping bug #3819
2018-05-01 21:19:05 -06:00
Mick A
5519c5170d
fix(docs): Broken Contributing link 2018-04-30 17:42:35 -06:00
almic
35c9fc937e
refactor(EasingFunction): Simplified EasingFunction
EasingFunction has been simplified greatly, and I've added a MUCH needed
annotation to relevant methods.

Easing.EasingOptions has been deprecated, as well as any methods using
them. Converting is as simple as deleting the "EasingOptions" part.

A new signature is available for animateXY()!

You are now able to pass one EasingFunction to animateXY() if you want
both axes to be animated the same way.

Quietly included are some gradle build updates, incrementing the
appcompat version to 27.1.1, and using the new `javacompiler` to avoid
deprecation of `javacompile`
2018-04-30 12:24:18 -06:00
Mick A
89d18a7f67
Merge pull request #3207 from scottkennedy/weakref-fixes
Fix some potential NPEs with WeakReference usage
2018-04-30 08:15:48 -06:00
Mick A
6fbd492761
Create PULL_REQUEST_TEMPLATE.md 2018-04-29 09:58:33 -06:00
Mick A
7286f8703f
Create ISSUE_TEMPLATE.md 2018-04-29 09:48:01 -06:00
Mick A
9997a33524
Merge pull request #3975 from hannesa2/AndroidStudio3.1.2
update to Android Studio 3.1.2
2018-04-28 19:12:26 -06:00
Hannes Achleitner
d8ea67aa21 update to Android Studio 3.1.2 2018-04-28 19:54:22 +02:00
Mick A
40adb57f68
Merge pull request #3898 from sembozdemir/pie_chart_value_line_colors
PieChart: Add option for using slice color as value line color
2018-04-28 10:53:08 -06:00
Mick A
215e0dfc05
Merge pull request #3949 from WilderPereira/master
Rename RadarChartActivitry to RadarChartActivity
2018-04-28 10:37:07 -06:00
almic
e1411f169e
Remove Custom Check
calculate() no longer checks if min and max is custom, it just adds the padding.
2018-04-27 00:08:27 -06:00
Wilder Pereira
993a8554c0 Remove unused imports 2018-04-15 21:51:35 -03:00
Wilder Pereira
508cc565a9 Rename RadarChartActivitry to RadarChartActivity 2018-04-15 21:51:15 -03:00
sembozdemir
1e6e58d2c0 Add option for using slice color as value line color
Fixes: #3897
2018-03-28 20:23:51 +03:00
zhanglong
aee6058dbb Avoid that the last label entry in the x-labels clip off the edge of the screen #3819 2018-02-27 15:04:47 +08:00
Philipp Jahoda
3e1eb1445a
Delete googlee1205ea43aa2c32a.html 2018-02-24 12:51:49 +01:00
Philipp Jahoda
82668ebc34
Add files via upload 2018-02-24 12:50:04 +01:00
Philipp Jahoda
a5250888b9
Update README.md 2018-01-12 15:27:40 +01:00
Philipp Jahoda
297ce9f2cc
Update README.md 2018-01-12 14:07:02 +01:00
Philipp Jahoda
b3e2358334
Update README.md 2018-01-12 14:06:19 +01:00
Philipp Jahoda
8fd1a86b0a
Update README.md 2017-12-27 16:25:56 +01:00
Philipp Jahoda
6ccaf940d8
Update README.md 2017-12-27 16:24:45 +01:00
Philipp Jahoda
c50f03cf39
Update README.md 2017-12-25 20:09:46 +01:00
Philipp Jahoda
c867d7cb37
Update README.md 2017-12-25 20:06:18 +01:00
Philipp Jahoda
2c08b560d6
Update README.md 2017-12-25 20:05:18 +01:00
Philipp Jahoda
779e0f5665
Update README.md 2017-12-25 19:58:23 +01:00
Philipp Jahoda
8954409575
Update README.md 2017-12-20 14:03:05 +01:00
Philipp Jahoda
44125a87dd
Update README.md 2017-12-20 10:59:50 +01:00
Philipp Jahoda
4b7eb1fd04
Update README.md 2017-12-19 14:38:34 +01:00
Philipp Jahoda
21ad19661b
Update README.md 2017-12-19 14:19:30 +01:00
Philipp Jahoda
b06439f36d
Update README.md 2017-12-19 14:14:54 +01:00
Philipp Jahoda
62910171f1 Merge branch 'master' of github.com:PhilJay/MPAndroidChart 2017-12-14 19:37:16 +01:00
Philipp Jahoda
16a9be8ea0 Update gitignore, add assets 2017-12-14 19:37:09 +01:00
Pawel Grzybek
e416736ad5 Added option to set restrictions for Y axis autoscaling. 2017-12-10 20:19:06 +01:00
Philipp Jahoda
d9000987c7
Update README.md 2017-11-30 13:40:49 +01:00
Philipp Jahoda
1ac72ea811
Update README.md 2017-11-30 09:27:59 +01:00
Philipp Jahoda
41aff3f13d Merge 2017-11-29 16:07:13 +01:00
Philipp Jahoda
5e97f561f7 Update version 2017-11-29 16:06:58 +01:00
Philipp Jahoda
47485f8364
Update README.md 2017-11-29 16:03:11 +01:00
Philipp Jahoda
0868d9bf89 Add new google repo 2017-11-29 15:57:30 +01:00
Philipp Jahoda
23aef1a0ab Add new google repo 2017-11-29 15:55:18 +01:00
Philipp Jahoda
dfaffa39cc Add maven plugin to example 2017-11-29 15:48:42 +01:00
Philipp Jahoda
ed9340ea51 Update maven android plugin 2017-11-29 15:47:10 +01:00
Philipp Jahoda
796dfb21f8 Out comment gradle wrapper 2017-11-29 15:28:03 +01:00
Philipp Jahoda
f2dedb30de Update gradle and dependencies 2017-11-29 15:23:57 +01:00
Philipp Jahoda
a5a482fbdc
Update README.md 2017-11-28 10:50:37 +01:00
Maxim Pestryakov
d3c339da10 Refactored LargeValueFormatter 2017-10-06 17:12:46 +03:00
davidgoli
c97b8d531d add option to draw limit lines on top of data 2017-09-22 18:57:07 -07:00
Daniel Cohen Gindi
72031d33ca Allow locking drag on either axes 2017-09-08 11:00:45 +03:00
Daniel Cohen Gindi
ea93823f63 Fix CombinedChartView not drawing markers 2017-09-08 10:13:12 +03:00
Daniel Cohen Gindi
ed770762fb Add default x spacing (half width) for scatter chart as well 2017-08-25 12:15:42 +03:00
Daniel Cohen Gindi
98f97f0df1 Run view port jobs after applying changes 2017-08-25 12:13:45 +03:00
Philipp Jahoda
4f77a154bf Update README.md 2017-08-11 16:31:29 +02:00
Philipp Jahoda
ad3c82f634 Update README.md 2017-08-04 17:05:42 +02:00
Scott Kennedy
43ae497ecf Fix some potential NPEs with WeakReference usage
Even if the WeakReference field is not null, the contained value may be null.  Additionally, you always need a strong reference to the value to ensure it isn't garbage collected while you're using it.
2017-06-26 10:51:58 -07:00
Philipp Jahoda
695f481077 Merge pull request #3204 from PhilJay/add-license-1
Create LICENSE
2017-06-26 09:16:47 +02:00
Philipp Jahoda
fcb506c219 Create LICENSE 2017-06-26 09:16:23 +02:00
Daniel Cohen Gindi
acf985ff0c Clear lastHighlighted when clear is called 2017-04-26 20:45:12 +03:00
Philipp Jahoda
0af86819ea Update README.md 2017-04-04 10:29:38 +02:00
Philipp Jahoda
f6a398b6b2 Update README.md 2017-03-24 11:36:12 +01:00
Philipp Jahoda
208bf181ad Update README.md 2017-03-23 16:23:45 +01:00
Stephen McBride
6c54f0b0a9 Fix for missing setters in getInstance method
The zoomAndCenterAnimated method in BarLineChartBase crashes with a NullPointer exception because the yAxis variable is null when onAnimationUpdate is called. The yAxis is null because of missing setters in the getInstance method of AnimatedZoomJob.
2017-02-28 15:58:42 +13:00
Voicu
89f10e928e Remove unused local variable 2016-09-18 09:32:34 -07:00
Voicu
e5d03ba640 Remove nullcheck for known non-null value 2016-08-22 23:30:43 -07:00
288 changed files with 9667 additions and 9065 deletions

12
.github/FUNDING.yml vendored Normal file
View 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
View 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
View 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.

View 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
View 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
View 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? -->

7
.gitignore vendored
View file

@ -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

View 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>

View file

@ -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=

View file

@ -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
View 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.

View file

@ -1 +1,2 @@
/build
/release

View file

@ -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=..

View file

@ -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="55"
android:versionName="3.0.2" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="25" />
<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>

View file

@ -1,65 +1,26 @@
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
compileSdkVersion 28
defaultConfig {
applicationId "com.xxmassdeveloper.mpchartexample"
minSdkVersion 16
targetSdkVersion 25
versionCode 55
versionName '3.0.2'
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.3.0'
//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:v2.0.2@aar'
compile project(':MPChartLib')
compile 'com.android.support:appcompat-v7:24.2.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')
}

View file

@ -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
View 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

View file

@ -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

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -1,49 +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/actionToggleIcons"
android:title="Toggle Icons">
</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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawBarShadow(false);
mChart.setDrawGridBackground(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
mChart.getAxisLeft().setDrawGridLines(false);
// setting data
mSeekBarX.setProgress(10);
mSeekBarY.setProgress(100);
// add a nice and smooth animation
mChart.animateY(2500);
mChart.getLegend().setEnabled(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
else
mChart.setPinchZoom(true);
mChart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
mChart.invalidate();
break;
}
case R.id.animateX: {
mChart.animateX(3000);
break;
}
case R.id.animateY: {
mChart.animateY(3000);
break;
}
case R.id.animateXY: {
mChart.animateXY(3000, 3000);
break;
}
case R.id.actionSave: {
if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
Toast.LENGTH_SHORT).show();
} else
Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
.show();
break;
}
}
return true;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvX.setText("" + (mSeekBarX.getProgress() + 1));
tvY.setText("" + (mSeekBarY.getProgress()));
ArrayList<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
}
}

View file

@ -1,306 +0,0 @@
package com.xxmassdeveloper.mpchartexample;
import android.annotation.SuppressLint;
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.IAxisValueFormatter;
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.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.XYMarkerView;
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.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
// mChart.setDrawYLabels(false);
IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart);
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(xAxisFormatter);
IAxisValueFormatter 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.setAxisMinimum(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.setAxisMinimum(0f); // this replaces setStartAtZero(true)
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
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" });
XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv); // Set the marker to the chart
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.actionToggleIcons: {
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if (mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
break;
}
case R.id.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 = 1f;
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);
if (Math.random() * 100 < 25) {
yVals1.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
} else {
yVals1.add(new BarEntry(i, val));
}
}
BarDataSet set1;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
set1.setValues(yVals1);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "The year 2017");
set1.setDrawIcons(false);
set1.setColors(ColorTemplate.MATERIAL_COLORS);
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);
}
}
protected RectF mOnValueSelectedRectF = new RectF();
@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
if (e == null)
return;
RectF bounds = mOnValueSelectedRectF;
mChart.getBarBounds((BarEntry) e, bounds);
MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
Log.i("x-index",
"low: " + mChart.getLowestVisibleX() + ", high: "
+ mChart.getHighestVisibleX());
MPPointF.recycleInstance(position);
}
@Override
public void onNothingSelected() { }
}

View file

@ -1,464 +0,0 @@
package com.xxmassdeveloper.mpchartexample;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.LimitLine.LimitLabelPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.Utils;
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListener,
OnChartGestureListener, OnChartValueSelectedListener {
private LineChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private TextView tvX, tvY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
tvX = (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.getDescription().setEnabled(false);
// enable touch gestures
mChart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// mChart.setScaleXEnabled(true);
// mChart.setScaleYEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
// set an alternative background color
// mChart.setBackgroundColor(Color.GRAY);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv); // Set the marker to the chart
// x-axis limit line
LimitLine llXAxis = new LimitLine(10f, "Index 10");
llXAxis.setLineWidth(4f);
llXAxis.enableDashedLine(10f, 10f, 0f);
llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
llXAxis.setTextSize(10f);
XAxis xAxis = mChart.getXAxis();
xAxis.enableGridDashedLine(10f, 10f, 0f);
//xAxis.setValueFormatter(new MyCustomXAxisValueFormatter());
//xAxis.addLimitLine(llXAxis); // add x-axis limit line
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
LimitLine ll1 = new LimitLine(150f, "Upper Limit");
ll1.setLineWidth(4f);
ll1.enableDashedLine(10f, 10f, 0f);
ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
ll1.setTextSize(10f);
ll1.setTypeface(tf);
LimitLine ll2 = new LimitLine(-30f, "Lower Limit");
ll2.setLineWidth(4f);
ll2.enableDashedLine(10f, 10f, 0f);
ll2.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
ll2.setTextSize(10f);
ll2.setTypeface(tf);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.addLimitLine(ll1);
leftAxis.addLimitLine(ll2);
leftAxis.setAxisMaximum(200f);
leftAxis.setAxisMinimum(-50f);
//leftAxis.setYOffset(20f);
leftAxis.enableGridDashedLine(10f, 10f, 0f);
leftAxis.setDrawZeroLine(false);
// limit lines are drawn behind data (and not on top)
leftAxis.setDrawLimitLinesBehindData(true);
mChart.getAxisRight().setEnabled(false);
//mChart.getViewPortHandler().setMaximumScaleY(2f);
//mChart.getViewPortHandler().setMaximumScaleX(2f);
// add data
setData(45, 100);
// mChart.setVisibleXRange(20);
// mChart.setVisibleYRange(20f, AxisDependency.LEFT);
// mChart.centerViewTo(20, 50, AxisDependency.LEFT);
mChart.animateX(2500);
//mChart.invalidate();
// get the legend (only possible after setting data)
Legend l = mChart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
// // dont forget to refresh the drawing
// mChart.invalidate();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionToggleValues: {
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
}
case R.id.actionToggleIcons: {
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawIcons(!set.isDrawIconsEnabled());
}
mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
List<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, getResources().getDrawable(R.drawable.star)));
}
LineDataSet set1;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
set1.setValues(values);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
set1 = new LineDataSet(values, "DataSet 1");
set1.setDrawIcons(false);
// set the line to be drawn like this "- - - - - -"
set1.enableDashedLine(10f, 5f, 0f);
set1.enableDashedHighlightLine(10f, 5f, 0f);
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(1f);
set1.setCircleRadius(3f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(9f);
set1.setDrawFilled(true);
set1.setFormLineWidth(1f);
set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
set1.setFormSize(15.f);
if (Utils.getSDKInt() >= 18) {
// fill drawable only supported on api level 18 and above
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
set1.setFillDrawable(drawable);
}
else {
set1.setFillColor(Color.BLACK);
}
ArrayList<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.");
}
}

View file

@ -1,245 +0,0 @@
package com.xxmassdeveloper.mpchartexample;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
private LineChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private TextView tvX, tvY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
tvX = (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.getDescription().setEnabled(false);
mChart.setDrawBorders(false);
mChart.getAxisLeft().setEnabled(false);
mChart.getAxisRight().setDrawAxisLine(false);
mChart.getAxisRight().setDrawGridLines(false);
mChart.getXAxis().setDrawAxisLine(false);
mChart.getXAxis().setDrawGridLines(false);
// enable touch gestures
mChart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
mSeekBarX.setProgress(20);
mSeekBarY.setProgress(100);
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionToggleValues: {
List<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) {
}
}

View file

@ -1,124 +0,0 @@
package com.xxmassdeveloper.mpchartexample;
import android.graphics.Color;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
public class PerformanceLineChart extends DemoBase implements OnSeekBarChangeListener {
private LineChart mChart;
private SeekBar mSeekBarValues;
private TextView mTvCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_performance_linechart);
mTvCount = (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.getDescription().setEnabled(false);
// enable touch gestures
mChart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getAxisRight().setEnabled(false);
mChart.getXAxis().setDrawGridLines(true);
mChart.getXAxis().setDrawAxisLine(false);
// dont forget to refresh the drawing
mChart.invalidate();
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int count = mSeekBarValues.getProgress() + 1000;
mTvCount.setText("" + count);
mChart.resetTracking();
setData(count, 500f);
// redraw
mChart.invalidate();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
private void setData(int count, float range) {
ArrayList<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);
}
}

View file

@ -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.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawBarShadow(false);
mChart.setDrawGridBackground(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getLegend().setEnabled(false);
setData(10);
mChart.setFitBars(true);
}
private void setData(int count) {
ArrayList<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);
}
}

View file

@ -1,21 +0,0 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import java.text.DecimalFormat;
public class MyAxisValueFormatter implements IAxisValueFormatter
{
private DecimalFormat mFormat;
public MyAxisValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0");
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(value) + " $";
}
}

View file

@ -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;
}
}

View file

@ -1,22 +0,0 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
public class MyValueFormatter implements IValueFormatter
{
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) + " $";
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -1,202 +0,0 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import io.realm.Realm;
import io.realm.RealmConfiguration;
/**
* Created by Philipp Jahoda on 05/11/15.
*/
public abstract class RealmBaseActivity extends DemoBase {
protected Realm mRealm;
protected Typeface mTf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Realm.io Examples");
}
protected void setup(Chart<?> chart) {
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
// no description text
chart.getDescription().setEnabled(false);
// enable touch gestures
chart.setTouchEnabled(true);
if (chart instanceof BarLineChartBase) {
BarLineChartBase mChart = (BarLineChartBase) chart;
mChart.setDrawGridBackground(false);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.setTypeface(mTf);
leftAxis.setTextSize(8f);
leftAxis.setTextColor(Color.DKGRAY);
leftAxis.setValueFormatter(new PercentFormatter());
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(mTf);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(8f);
xAxis.setTextColor(Color.DKGRAY);
mChart.getAxisRight().setEnabled(false);
}
}
protected void styleData(ChartData data) {
data.setValueTypeface(mTf);
data.setValueTextSize(8f);
data.setValueTextColor(Color.DKGRAY);
data.setValueFormatter(new PercentFormatter());
}
@Override
protected void onResume() {
super.onResume();
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(realmConfig);
mRealm = Realm.getDefaultInstance();
}
@Override
protected void onPause() {
super.onPause();
mRealm.close();
}
protected void writeToDB(int objectCount) {
mRealm.beginTransaction();
mRealm.delete(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float value = 40f + (float) (Math.random() * 60f);
RealmDemoData d = new RealmDemoData(i, value);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBStack(int objectCount) {
mRealm.beginTransaction();
mRealm.delete(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float val1 = 34f + (float) (Math.random() * 12.0f);
float val2 = 34f + (float) (Math.random() * 12.0f);
float[] stack = new float[]{val1, val2, 100 - val1 - val2};
RealmDemoData d = new RealmDemoData(i, stack);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBCandle(int objectCount) {
mRealm.beginTransaction();
mRealm.delete(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float mult = 50;
float val = (float) (Math.random() * 40) + mult;
float high = (float) (Math.random() * 9) + 8f;
float low = (float) (Math.random() * 9) + 8f;
float open = (float) (Math.random() * 6) + 1f;
float close = (float) (Math.random() * 6) + 1f;
boolean even = i % 2 == 0;
RealmDemoData d = new RealmDemoData(i, val + high, val - low, even ? val + open : val - open,
even ? val - close : val + close);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBBubble(int objectCount) {
mRealm.beginTransaction();
mRealm.delete(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float value = 30f + (float) (Math.random() * 100.0);
float size = 15f + (float) (Math.random() * 20.0);
RealmDemoData d = new RealmDemoData(i, value, size);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBPie() {
mRealm.beginTransaction();
mRealm.delete(RealmDemoData.class);
float value1 = 15f + (float) (Math.random() * 8f);
float value2 = 15f + (float) (Math.random() * 8f);
float value3 = 15f + (float) (Math.random() * 8f);
float value4 = 15f + (float) (Math.random() * 8f);
float value5 = 100f - value1 - value2 - value3 - value4;
float[] values = new float[]{value1, value2, value3, value4, value5};
String[] labels = new String[]{"iOS", "Android", "WP 10", "BlackBerry", "Other"};
for (int i = 0; i < values.length; i++) {
RealmDemoData d = new RealmDemoData(values[i], labels[i]);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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().setAxisMinimum(0f);
mChart.setDrawValueAboveBar(false);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDBStack(50);
// add data to the chart
setData();
}
private void setData() {
RealmResults<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);
}
}

View file

@ -1,78 +0,0 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityLine extends RealmBaseActivity {
private LineChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
mChart = (LineChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getAxisLeft().setAxisMaximum(150f);
mChart.getAxisLeft().setAxisMinimum(0f);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDB(40);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
set.setLabel("Realm LineDataSet");
set.setDrawCircleHole(false);
set.setColor(ColorTemplate.rgb("#FF5722"));
set.setCircleColor(ColorTemplate.rgb("#FF5722"));
set.setLineWidth(1.8f);
set.setCircleRadius(3.6f);
ArrayList<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);
}
}

View file

@ -1,82 +0,0 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityPie extends RealmBaseActivity {
private PieChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart_noseekbar);
mChart = (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();
RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label");
set.setColors(ColorTemplate.VORDIPLOM_COLORS);
set.setLabel("Example market share");
set.setSliceSpace(2);
// create a data object with the dataset list
PieData data = new PieData(set);
styleData(data);
data.setValueTextColor(Color.WHITE);
data.setValueTextSize(12f);
// set data
mChart.setData(data);
mChart.animateY(1400);
}
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("Realm.io\nmobile database");
s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
return s;
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -1,133 +0,0 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.notimportant.ContentItem;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import com.xxmassdeveloper.mpchartexample.notimportant.MyAdapter;
import java.util.ArrayList;
import io.realm.Realm;
import io.realm.RealmConfiguration;
/**
* Created by Philipp Jahoda on 07/12/15.
*/
public class RealmMainActivity extends DemoBase implements AdapterView.OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
setTitle("Realm.io Examples");
ArrayList<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);
Realm.init(this);
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(realmConfig);
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
realm.deleteAll();
realm.commitTransaction();
}
@Override
public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
Intent i;
switch (pos) {
case 0:
i = new Intent(this, RealmDatabaseActivityLine.class);
startActivity(i);
break;
case 1:
i = new Intent(this, RealmDatabaseActivityBar.class);
startActivity(i);
break;
case 2:
i = new Intent(this, RealmDatabaseActivityHorizontalBar.class);
startActivity(i);
break;
case 3:
i = new Intent(this, RealmDatabaseActivityScatter.class);
startActivity(i);
break;
case 4:
i = new Intent(this, RealmDatabaseActivityCandle.class);
startActivity(i);
break;
case 5:
i = new Intent(this, RealmDatabaseActivityBubble.class);
startActivity(i);
break;
case 6:
i = new Intent(this, RealmDatabaseActivityPie.class);
startActivity(i);
break;
case 7:
i = new Intent(this, RealmDatabaseActivityRadar.class);
startActivity(i);
break;
case 8:
i = new Intent(this, RealmWikiExample.class);
startActivity(i);
break;
}
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.realm, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://realm.io"));
startActivity(i);
return super.onOptionsItemSelected(item);
}
}

View file

@ -1,133 +0,0 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 18/12/15.
*/
public class RealmWikiExample extends RealmBaseActivity {
private LineChart lineChart;
private BarChart barChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_realm_wiki);
lineChart = (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();
IAxisValueFormatter formatter = new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return results.get((int) value).getPlayerName();
}
};
lineChart.getXAxis().setValueFormatter(formatter);
barChart.getXAxis().setValueFormatter(formatter);
RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
lineDataSet.setLabel("Result Scores");
lineDataSet.setDrawCircleHole(false);
lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
lineDataSet.setLineWidth(1.8f);
lineDataSet.setCircleRadius(3.6f);
ArrayList<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);
}
}

View file

@ -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;
}
}

View 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>

View file

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -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) {}
}

View file

@ -0,0 +1,326 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
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.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
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.ValueFormatter;
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.Fill;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.XYMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class BarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
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("BarChartActivity");
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
seekBarX.setOnSeekBarChangeListener(this);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
chart.setPinchZoom(false);
chart.setDrawGridBackground(false);
// chart.setDrawYLabels(false);
ValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(tfLight);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f); // only intervals of 1 day
xAxis.setLabelCount(7);
xAxis.setValueFormatter(xAxisFormatter);
ValueFormatter custom = new MyValueFormatter("$");
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(8, false);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(8, false);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setForm(LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
mv.setChartView(chart); // For bounds control
chart.setMarker(mv); // Set the marker to the chart
// setting data
seekBarY.setProgress(50);
seekBarX.setProgress(12);
// chart.setDrawLegend(false);
}
private void setData(int count, float range) {
float start = 1f;
ArrayList<BarEntry> values = new ArrayList<>();
for (int i = (int) start; i < start + count; i++) {
float val = (float) (Math.random() * (range + 1));
if (Math.random() * 100 < 25) {
values.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
} else {
values.add(new BarEntry(i, val));
}
}
BarDataSet set1;
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
set1.setValues(values);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(values, "The year 2017");
set1.setDrawIcons(false);
int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
int startColor4 = ContextCompat.getColor(this, android.R.color.holo_green_light);
int startColor5 = ContextCompat.getColor(this, android.R.color.holo_red_light);
int endColor1 = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
int endColor2 = ContextCompat.getColor(this, android.R.color.holo_purple);
int endColor3 = ContextCompat.getColor(this, android.R.color.holo_green_dark);
int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
List<Fill> gradientFills = new ArrayList<>();
gradientFills.add(new Fill(startColor1, endColor1));
gradientFills.add(new Fill(startColor2, endColor2));
gradientFills.add(new Fill(startColor3, endColor3));
gradientFills.add(new Fill(startColor4, endColor4));
gradientFills.add(new Fill(startColor5, endColor5));
set1.setFills(gradientFills);
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(tfLight);
data.setBarWidth(0.9f);
chart.setData(data);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.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: {
for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if (chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
chart.setPinchZoom(true);
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
chart.invalidate();
break;
}
case R.id.animateX: {
chart.animateX(2000);
break;
}
case R.id.animateY: {
chart.animateY(2000);
break;
}
case R.id.animateXY: {
chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
}
return true;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvX.setText(String.valueOf(seekBarX.getProgress()));
tvY.setText(String.valueOf(seekBarY.getProgress()));
setData(seekBarX.getProgress(), seekBarY.getProgress());
chart.invalidate();
}
@Override
protected void saveToGallery() {
saveToGallery(chart, "BarChartActivity");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
private final RectF onValueSelectedRectF = new RectF();
@Override
public void onValueSelected(Entry e, Highlight h) {
if (e == null)
return;
RectF bounds = onValueSelectedRectF;
chart.getBarBounds((BarEntry) e, bounds);
MPPointF position = chart.getPosition(e, AxisDependency.LEFT);
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
Log.i("x-index",
"low: " + chart.getLowestVisibleX() + ", high: "
+ chart.getHighestVisibleX());
MPPointF.recycleInstance(position);
}
@Override
public void onNothingSelected() { }
}

View file

@ -1,8 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -12,7 +16,6 @@ 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.XAxis;
import com.github.mikephil.charting.components.YAxis;
@ -20,8 +23,8 @@ 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.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.LargeValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
@ -29,12 +32,13 @@ import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.Locale;
public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
private BarChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private BarChart chart;
private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@ -44,68 +48,145 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
tvX = (TextView) findViewById(R.id.tvXMax);
setTitle("BarChartActivityMultiDataset");
tvX = findViewById(R.id.tvXMax);
tvX.setTextSize(10);
tvY = (TextView) findViewById(R.id.tvYMax);
tvY = findViewById(R.id.tvYMax);
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarX.setOnSeekBarChangeListener(this);
seekBarX = findViewById(R.id.seekBar1);
seekBarX.setMax(50);
seekBarX.setOnSeekBarChangeListener(this);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
mSeekBarY.setOnSeekBarChangeListener(this);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.getDescription().setEnabled(false);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
chart.getDescription().setEnabled(false);
// mChart.setDrawBorders(true);
// chart.setDrawBorders(true);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
mChart.setDrawBarShadow(false);
chart.setDrawBarShadow(false);
mChart.setDrawGridBackground(false);
chart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv); // Set the marker to the chart
mv.setChartView(chart); // For bounds control
chart.setMarker(mv); // Set the marker to the chart
mSeekBarX.setProgress(10);
mSeekBarY.setProgress(100);
seekBarX.setProgress(10);
seekBarY.setProgress(100);
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(true);
l.setTypeface(mTfLight);
l.setTypeface(tfLight);
l.setYOffset(0f);
l.setXOffset(10f);
l.setYEntrySpace(0f);
l.setTextSize(8f);
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(mTfLight);
XAxis xAxis = chart.getXAxis();
xAxis.setTypeface(tfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return String.valueOf((int) value);
}
});
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTfLight);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tfLight);
leftAxis.setValueFormatter(new LargeValueFormatter());
leftAxis.setDrawGridLines(false);
leftAxis.setSpaceTop(35f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
mChart.getAxisRight().setEnabled(false);
chart.getAxisRight().setEnabled(false);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float groupSpace = 0.08f;
float barSpace = 0.03f; // x4 DataSet
float barWidth = 0.2f; // x4 DataSet
// (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
int groupCount = seekBarX.getProgress() + 1;
int startYear = 1980;
int endYear = startYear + groupCount;
tvX.setText(String.format(Locale.ENGLISH, "%d-%d", startYear, endYear));
tvY.setText(String.valueOf(seekBarY.getProgress()));
ArrayList<BarEntry> values1 = new ArrayList<>();
ArrayList<BarEntry> values2 = new ArrayList<>();
ArrayList<BarEntry> values3 = new ArrayList<>();
ArrayList<BarEntry> values4 = new ArrayList<>();
float randomMultiplier = seekBarY.getProgress() * 100000f;
for (int i = startYear; i < endYear; i++) {
values1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
values2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
values3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
values4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
}
BarDataSet set1, set2, set3, set4;
if (chart.getData() != null && chart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
set2 = (BarDataSet) chart.getData().getDataSetByIndex(1);
set3 = (BarDataSet) chart.getData().getDataSetByIndex(2);
set4 = (BarDataSet) chart.getData().getDataSetByIndex(3);
set1.setValues(values1);
set2.setValues(values2);
set3.setValues(values3);
set4.setValues(values4);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
// create 4 DataSets
set1 = new BarDataSet(values1, "Company A");
set1.setColor(Color.rgb(104, 241, 175));
set2 = new BarDataSet(values2, "Company B");
set2.setColor(Color.rgb(164, 228, 251));
set3 = new BarDataSet(values3, "Company C");
set3.setColor(Color.rgb(242, 247, 158));
set4 = new BarDataSet(values4, "Company D");
set4.setColor(Color.rgb(255, 102, 0));
BarData data = new BarData(set1, set2, set3, set4);
data.setValueFormatter(new LargeValueFormatter());
data.setValueTypeface(tfLight);
chart.setData(data);
}
// specify the width each bar should have
chart.getBarData().setBarWidth(barWidth);
// restrict the x-axis range
chart.getXAxis().setAxisMinimum(startYear);
// barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
chart.getXAxis().setAxisMaximum(startYear + chart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
chart.groupBars(startYear, groupSpace, barSpace);
chart.invalidate();
}
@Override
@ -118,56 +199,65 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java"));
startActivity(i);
break;
}
case R.id.actionToggleValues: {
for (IBarDataSet set : mChart.getData().getDataSets())
for (IBarDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
mChart.setPinchZoom(true);
chart.setPinchZoom(true);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if (mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
if (chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionSave: {
// mChart.saveToGallery("title"+System.currentTimeMillis());
mChart.saveToPath("title" + System.currentTimeMillis(), "");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
case R.id.animateX: {
mChart.animateX(3000);
chart.animateX(2000);
break;
}
case R.id.animateY: {
mChart.animateY(3000);
chart.animateY(2000);
break;
}
case R.id.animateXY: {
mChart.animateXY(3000, 3000);
chart.animateXY(2000, 2000);
break;
}
}
@ -175,88 +265,15 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float groupSpace = 0.08f;
float barSpace = 0.03f; // x4 DataSet
float barWidth = 0.2f; // x4 DataSet
// (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
int groupCount = mSeekBarX.getProgress() + 1;
int startYear = 1980;
int endYear = startYear + groupCount;
tvX.setText(startYear + "-" + endYear);
tvY.setText("" + (mSeekBarY.getProgress()));
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals4 = new ArrayList<BarEntry>();
float randomMultiplier = mSeekBarY.getProgress() * 100000f;
for (int i = startYear; i < endYear; i++) {
yVals1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
yVals2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
yVals3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
yVals4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
}
BarDataSet set1, set2, set3, set4;
if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
set2 = (BarDataSet) mChart.getData().getDataSetByIndex(1);
set3 = (BarDataSet) mChart.getData().getDataSetByIndex(2);
set4 = (BarDataSet) mChart.getData().getDataSetByIndex(3);
set1.setValues(yVals1);
set2.setValues(yVals2);
set3.setValues(yVals3);
set4.setValues(yVals4);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
// create 4 DataSets
set1 = new BarDataSet(yVals1, "Company A");
set1.setColor(Color.rgb(104, 241, 175));
set2 = new BarDataSet(yVals2, "Company B");
set2.setColor(Color.rgb(164, 228, 251));
set3 = new BarDataSet(yVals3, "Company C");
set3.setColor(Color.rgb(242, 247, 158));
set4 = new BarDataSet(yVals4, "Company D");
set4.setColor(Color.rgb(255, 102, 0));
BarData data = new BarData(set1, set2, set3, set4);
data.setValueFormatter(new LargeValueFormatter());
data.setValueTypeface(mTfLight);
mChart.setData(data);
}
// specify the width each bar should have
mChart.getBarData().setBarWidth(barWidth);
// restrict the x-axis range
mChart.getXAxis().setAxisMinimum(startYear);
// barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
mChart.getXAxis().setAxisMaximum(startYear + mChart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
mChart.groupBars(startYear, groupSpace, barSpace);
mChart.invalidate();
protected void saveToGallery() {
saveToGallery(chart, "BarChartActivityMultiDataset");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onValueSelected(Entry e, Highlight h) {

View file

@ -1,20 +1,23 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
@ -29,11 +32,11 @@ import java.util.List;
public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeListener {
protected BarChart mChart;
private SeekBar mSeekBarX;
private BarChart chart;
private SeekBar seekBarX;
private TextView tvX;
private List<BarEntry> mSinusData;
private List<BarEntry> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -42,57 +45,59 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_sinus);
mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
setTitle("BarChartActivitySinus");
tvX = (TextView) findViewById(R.id.tvValueCount);
data = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
mSeekBarX = (SeekBar) findViewById(R.id.seekbarValues);
tvX = findViewById(R.id.tvValueCount);
mChart = (BarChart) findViewById(R.id.chart1);
seekBarX = findViewById(R.id.seekbarValues);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
chart = findViewById(R.id.chart1);
mChart.getDescription().setEnabled(false);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
// chart.setDrawBarShadow(true);
// mChart.setDrawXLabels(false);
// chart.setDrawXLabels(false);
mChart.setDrawGridBackground(false);
// mChart.setDrawYLabels(false);
chart.setDrawGridBackground(false);
// chart.setDrawYLabels(false);
XAxis xAxis = mChart.getXAxis();
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTfLight);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(6, false);
leftAxis.setAxisMinimum(-2.5f);
leftAxis.setAxisMaximum(2.5f);
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(0.1f);
YAxis rightAxis = mChart.getAxisRight();
YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(mTfLight);
rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(6, false);
rightAxis.setAxisMinimum(-2.5f);
rightAxis.setAxisMaximum(2.5f);
rightAxis.setGranularity(0.1f);
mSeekBarX.setOnSeekBarChangeListener(this);
mSeekBarX.setProgress(150); // set data
seekBarX.setOnSeekBarChangeListener(this);
seekBarX.setProgress(150); // set data
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@ -102,7 +107,37 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
l.setTextSize(11f);
l.setXEntrySpace(4f);
mChart.animateXY(2000, 2000);
chart.animateXY(1500, 1500);
}
private void setData(int count) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int i = 0; i < count; i++) {
entries.add(data.get(i));
}
BarDataSet set;
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set = (BarDataSet) chart.getData().getDataSetByIndex(0);
set.setValues(entries);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
set = new BarDataSet(entries, "Sinus Function");
set.setColor(Color.rgb(240, 120, 124));
}
BarData data = new BarData(set);
data.setValueTextSize(10f);
data.setValueTypeface(tfLight);
data.setDrawValues(false);
data.setBarWidth(0.8f);
chart.setData(data);
}
@Override
@ -115,61 +150,66 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java"));
startActivity(i);
break;
}
case R.id.actionToggleValues: {
for (IBarDataSet set : mChart.getData().getDataSets())
for (IBarDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if (mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
if (chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
mChart.setPinchZoom(true);
chart.setPinchZoom(true);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.animateX: {
mChart.animateX(1500);
chart.animateX(2000);
break;
}
case R.id.animateY: {
mChart.animateY(1500);
chart.animateY(2000);
break;
}
case R.id.animateXY: {
mChart.animateXY(2000, 2000);
chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
Toast.LENGTH_SHORT).show();
} else
Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
.show();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
}
@ -179,51 +219,21 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvX.setText("" + (mSeekBarX.getProgress()));
tvX.setText(String.valueOf(seekBarX.getProgress()));
setData(mSeekBarX.getProgress());
mChart.invalidate();
setData(seekBarX.getProgress());
chart.invalidate();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
protected void saveToGallery() {
saveToGallery(chart, "BarChartActivitySinus");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
public void onStartTrackingTouch(SeekBar seekBar) {}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
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);
}
}

View file

@ -1,23 +1,21 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.AxisBase;
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.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.text.DecimalFormat;
@ -26,8 +24,7 @@ import java.util.List;
public class BarChartPositiveNegative extends DemoBase {
protected BarChart mChart;
private Typeface mTf;
private BarChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -36,27 +33,28 @@ public class BarChartPositiveNegative extends DemoBase {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_noseekbar);
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setBackgroundColor(Color.WHITE);
mChart.setExtraTopOffset(-30f);
mChart.setExtraBottomOffset(10f);
mChart.setExtraLeftOffset(70f);
mChart.setExtraRightOffset(70f);
setTitle("BarChartPositiveNegative");
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.WHITE);
chart.setExtraTopOffset(-30f);
chart.setExtraBottomOffset(10f);
chart.setExtraLeftOffset(70f);
chart.setExtraRightOffset(70f);
mChart.getDescription().setEnabled(false);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
chart.setDrawGridBackground(false);
XAxis xAxis = mChart.getXAxis();
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(mTf);
xAxis.setTypeface(tfRegular);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextColor(Color.LTGRAY);
@ -65,7 +63,7 @@ public class BarChartPositiveNegative extends DemoBase {
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f);
YAxis left = mChart.getAxisLeft();
YAxis left = chart.getAxisLeft();
left.setDrawLabels(false);
left.setSpaceTop(25f);
left.setSpaceBottom(25f);
@ -74,8 +72,8 @@ public class BarChartPositiveNegative extends DemoBase {
left.setDrawZeroLine(true); // draw a zero line
left.setZeroLineColor(Color.GRAY);
left.setZeroLineWidth(0.7f);
mChart.getAxisRight().setEnabled(false);
mChart.getLegend().setEnabled(false);
chart.getAxisRight().setEnabled(false);
chart.getLegend().setEnabled(false);
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
final List<Data> data = new ArrayList<>();
@ -85,9 +83,9 @@ public class BarChartPositiveNegative extends DemoBase {
data.add(new Data(3f, -442.3f, "01-01"));
data.add(new Data(4f, -2280.1f, "01-02"));
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
}
});
@ -97,8 +95,8 @@ public class BarChartPositiveNegative extends DemoBase {
private void setData(List<Data> dataList) {
ArrayList<BarEntry> values = new ArrayList<BarEntry>();
List<Integer> colors = new ArrayList<Integer>();
ArrayList<BarEntry> values = new ArrayList<>();
List<Integer> colors = new ArrayList<>();
int green = Color.rgb(110, 190, 102);
int red = Color.rgb(211, 74, 88);
@ -118,12 +116,12 @@ public class BarChartPositiveNegative extends DemoBase {
BarDataSet set;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set = (BarDataSet)mChart.getData().getDataSetByIndex(0);
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set = (BarDataSet) chart.getData().getDataSetByIndex(0);
set.setValues(values);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
set = new BarDataSet(values, "Values");
set.setColors(colors);
@ -131,12 +129,12 @@ public class BarChartPositiveNegative extends DemoBase {
BarData data = new BarData(set);
data.setValueTextSize(13f);
data.setValueTypeface(mTf);
data.setValueFormatter(new ValueFormatter());
data.setValueTypeface(tfRegular);
data.setValueFormatter(new Formatter());
data.setBarWidth(0.8f);
mChart.setData(data);
mChart.invalidate();
chart.setData(data);
chart.invalidate();
}
}
@ -145,29 +143,53 @@ public class BarChartPositiveNegative extends DemoBase {
*/
private class Data {
public String xAxisValue;
public float yValue;
public float xValue;
final String xAxisValue;
final float yValue;
final float xValue;
public Data(float xValue, float yValue, String xAxisValue) {
Data(float xValue, float yValue, String xAxisValue) {
this.xAxisValue = xAxisValue;
this.yValue = yValue;
this.xValue = xValue;
}
}
private class ValueFormatter implements IValueFormatter
private class Formatter extends ValueFormatter
{
private DecimalFormat mFormat;
private final DecimalFormat mFormat;
public ValueFormatter() {
Formatter() {
mFormat = new DecimalFormat("######.0");
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
public String getFormattedValue(float value) {
return mFormat.format(value);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.only_github, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java"));
startActivity(i);
break;
}
}
return true;
}
@Override
public void saveToGallery() { /* Intentionally left empty */ }
}

View file

@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -13,7 +18,6 @@ import 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;
@ -33,10 +37,10 @@ import java.util.ArrayList;
public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
private BubbleChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private BubbleChart chart;
private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -44,52 +48,106 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_bubblechart);
tvX = (TextView) findViewById(R.id.tvXMax);
tvY = (TextView) findViewById(R.id.tvYMax);
setTitle("BubbleChartActivity");
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarX.setOnSeekBarChangeListener(this);
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
mSeekBarY.setOnSeekBarChangeListener(this);
seekBarX = findViewById(R.id.seekBar1);
seekBarX.setOnSeekBarChangeListener(this);
mChart = (BubbleChart) findViewById(R.id.chart1);
mChart.getDescription().setEnabled(false);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
mChart.setOnChartValueSelectedListener(this);
chart = findViewById(R.id.chart1);
chart.getDescription().setEnabled(false);
mChart.setDrawGridBackground(false);
chart.setOnChartValueSelectedListener(this);
mChart.setTouchEnabled(true);
chart.setDrawGridBackground(false);
chart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
mChart.setMaxVisibleValueCount(200);
mChart.setPinchZoom(true);
chart.setMaxVisibleValueCount(200);
chart.setPinchZoom(true);
mSeekBarX.setProgress(10);
mSeekBarY.setProgress(50);
seekBarX.setProgress(10);
seekBarY.setProgress(50);
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
l.setTypeface(mTfLight);
l.setTypeface(tfLight);
YAxis yl = mChart.getAxisLeft();
yl.setTypeface(mTfLight);
YAxis yl = chart.getAxisLeft();
yl.setTypeface(tfLight);
yl.setSpaceTop(30f);
yl.setSpaceBottom(30f);
yl.setDrawZeroLine(false);
mChart.getAxisRight().setEnabled(false);
XAxis xl = mChart.getXAxis();
chart.getAxisRight().setEnabled(false);
XAxis xl = chart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
xl.setTypeface(mTfLight);
xl.setTypeface(tfLight);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int count = seekBarX.getProgress();
int range = seekBarY.getProgress();
tvX.setText(String.valueOf(count));
tvY.setText(String.valueOf(range));
ArrayList<BubbleEntry> values1 = new ArrayList<>();
ArrayList<BubbleEntry> values2 = new ArrayList<>();
ArrayList<BubbleEntry> values3 = new ArrayList<>();
for (int i = 0; i < count; i++) {
values1.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
values2.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
values3.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range)));
}
// create a dataset and give it a type
BubbleDataSet set1 = new BubbleDataSet(values1, "DS 1");
set1.setDrawIcons(false);
set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
set1.setDrawValues(true);
BubbleDataSet set2 = new BubbleDataSet(values2, "DS 2");
set2.setDrawIcons(false);
set2.setIconsOffset(new MPPointF(0, 15));
set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
set2.setDrawValues(true);
BubbleDataSet set3 = new BubbleDataSet(values3, "DS 3");
set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
set3.setDrawValues(true);
ArrayList<IBubbleDataSet> dataSets = new ArrayList<>();
dataSets.add(set1); // add the data sets
dataSets.add(set2);
dataSets.add(set3);
// create a data object with the data sets
BubbleData data = new BubbleData(dataSets);
data.setDrawValues(false);
data.setValueTypeface(tfLight);
data.setValueTextSize(8f);
data.setValueTextColor(Color.WHITE);
data.setHighlightCircleWidth(1.5f);
chart.setData(data);
chart.invalidate();
}
@Override
@ -102,56 +160,65 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java"));
startActivity(i);
break;
}
case R.id.actionToggleValues: {
for (IDataSet set : mChart.getData().getDataSets())
for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
for (IDataSet set : mChart.getData().getDataSets())
for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
if(chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
mChart.setPinchZoom(true);
chart.setPinchZoom(true);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
mChart.saveToPath("title" + System.currentTimeMillis(), "");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
case R.id.animateX: {
mChart.animateX(3000);
chart.animateX(2000);
break;
}
case R.id.animateY: {
mChart.animateY(3000);
chart.animateY(2000);
break;
}
case R.id.animateXY: {
mChart.animateXY(3000, 3000);
chart.animateXY(2000, 2000);
break;
}
}
@ -159,70 +226,8 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
}
@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, getResources().getDrawable(R.drawable.star)));
}
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range);
float size = (float) (Math.random() * range);
yVals2.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
}
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range);
float size = (float) (Math.random() * range);
yVals3.add(new BubbleEntry(i, val, size));
}
// create a dataset and give it a type
BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
set1.setDrawIcons(false);
set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
set1.setDrawValues(true);
BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
set2.setDrawIcons(false);
set2.setIconsOffset(new MPPointF(0, 15));
set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
set2.setDrawValues(true);
BubbleDataSet set3 = new BubbleDataSet(yVals3, "DS 3");
set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
set3.setDrawValues(true);
ArrayList<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();
protected void saveToGallery() {
saveToGallery(chart, "BubbleChartActivity");
}
@Override
@ -233,20 +238,11 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
}
@Override
public void onNothingSelected() {
// TODO Auto-generated method stub
}
public void onNothingSelected() {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {}
}

View file

@ -1,16 +1,20 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.components.XAxis;
@ -28,8 +32,8 @@ import java.util.ArrayList;
public class CandleStickChartActivity extends DemoBase implements OnSeekBarChangeListener {
private CandleStickChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private CandleStickChart chart;
private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@ -39,154 +43,77 @@ public class CandleStickChartActivity extends DemoBase implements OnSeekBarChang
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_candlechart);
tvX = (TextView) findViewById(R.id.tvXMax);
tvY = (TextView) findViewById(R.id.tvYMax);
setTitle("CandleStickChartActivity");
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarX.setOnSeekBarChangeListener(this);
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
mSeekBarY.setOnSeekBarChangeListener(this);
seekBarX = findViewById(R.id.seekBar1);
seekBarX.setOnSeekBarChangeListener(this);
mChart = (CandleStickChart) findViewById(R.id.chart1);
mChart.setBackgroundColor(Color.WHITE);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
mChart.getDescription().setEnabled(false);
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.WHITE);
chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
chart.setDrawGridBackground(false);
XAxis xAxis = mChart.getXAxis();
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
YAxis leftAxis = mChart.getAxisLeft();
YAxis leftAxis = chart.getAxisLeft();
// leftAxis.setEnabled(false);
leftAxis.setLabelCount(7, false);
leftAxis.setDrawGridLines(false);
leftAxis.setDrawAxisLine(false);
YAxis rightAxis = mChart.getAxisRight();
YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// rightAxis.setStartAtZero(false);
// setting data
mSeekBarX.setProgress(40);
mSeekBarY.setProgress(100);
mChart.getLegend().setEnabled(false);
}
seekBarX.setProgress(40);
seekBarY.setProgress(100);
@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.actionToggleValues: {
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
break;
}
case R.id.actionToggleIcons: {
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
break;
}
case R.id.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;
chart.getLegend().setEnabled(false);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int prog = (mSeekBarX.getProgress() + 1);
tvX.setText("" + prog);
tvY.setText("" + (mSeekBarY.getProgress()));
mChart.resetTracking();
progress = (seekBarX.getProgress());
ArrayList<CandleEntry> yVals1 = new ArrayList<CandleEntry>();
tvX.setText(String.valueOf(progress));
tvY.setText(String.valueOf(seekBarY.getProgress()));
chart.resetTracking();
ArrayList<CandleEntry> values = new ArrayList<>();
for (int i = 0; i < progress; i++) {
float multi = (seekBarY.getProgress() + 1);
float val = (float) (Math.random() * 40) + multi;
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(
values.add(new CandleEntry(
i, val + high,
val - low,
even ? val + open : val - open,
@ -195,7 +122,7 @@ public class CandleStickChartActivity extends DemoBase implements OnSeekBarChang
));
}
CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set");
CandleDataSet set1 = new CandleDataSet(values, "Data Set");
set1.setDrawIcons(false);
set1.setAxisDependency(AxisDependency.LEFT);
@ -210,20 +137,102 @@ public class CandleStickChartActivity extends DemoBase implements OnSeekBarChang
//set1.setHighlightLineWidth(1f);
CandleData data = new CandleData(set1);
mChart.setData(data);
mChart.invalidate();
chart.setData(data);
chart.invalidate();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.candle, menu);
return true;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java"));
startActivity(i);
break;
}
case R.id.actionToggleValues: {
for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.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.actionToggleMakeShadowSameColorAsCandle: {
for (ICandleDataSet set : chart.getData().getDataSets()) {
((CandleDataSet) set).setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
}
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, "CandleStickChartActivity");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
}

View file

@ -1,7 +1,8 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@ -9,7 +10,6 @@ import android.view.WindowManager;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.CombinedChart.DrawOrder;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
@ -29,7 +29,7 @@ import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.data.ScatterDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -38,8 +38,8 @@ import java.util.ArrayList;
public class CombinedChartActivity extends DemoBase {
private CombinedChart mChart;
private final int itemcount = 12;
private CombinedChart chart;
private final int count = 12;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -48,41 +48,43 @@ public class CombinedChartActivity extends DemoBase {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_combined);
mChart = (CombinedChart) findViewById(R.id.chart1);
mChart.getDescription().setEnabled(false);
mChart.setBackgroundColor(Color.WHITE);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
mChart.setHighlightFullBarEnabled(false);
setTitle("CombinedChartActivity");
chart = findViewById(R.id.chart1);
chart.getDescription().setEnabled(false);
chart.setBackgroundColor(Color.WHITE);
chart.setDrawGridBackground(false);
chart.setDrawBarShadow(false);
chart.setHighlightFullBarEnabled(false);
// draw bars behind lines
mChart.setDrawOrder(new DrawOrder[]{
chart.setDrawOrder(new DrawOrder[]{
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
});
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = mChart.getAxisRight();
YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis leftAxis = mChart.getAxisLeft();
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
XAxis xAxis = mChart.getXAxis();
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mMonths[(int) value % mMonths.length];
public String getFormattedValue(float value) {
return months[(int) value % months.length];
}
});
@ -93,21 +95,21 @@ public class CombinedChartActivity extends DemoBase {
data.setData(generateBubbleData());
data.setData(generateScatterData());
data.setData(generateCandleData());
data.setValueTypeface(mTfLight);
data.setValueTypeface(tfLight);
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
mChart.setData(data);
mChart.invalidate();
chart.setData(data);
chart.invalidate();
}
private LineData generateLineData() {
LineData d = new LineData();
ArrayList<Entry> entries = new ArrayList<Entry>();
ArrayList<Entry> entries = new ArrayList<>();
for (int index = 0; index < itemcount; index++)
for (int index = 0; index < count; index++)
entries.add(new Entry(index + 0.5f, getRandom(15, 5)));
LineDataSet set = new LineDataSet(entries, "Line DataSet");
@ -129,10 +131,10 @@ public class CombinedChartActivity extends DemoBase {
private BarData generateBarData() {
ArrayList<BarEntry> entries1 = new ArrayList<BarEntry>();
ArrayList<BarEntry> entries2 = new ArrayList<BarEntry>();
ArrayList<BarEntry> entries1 = new ArrayList<>();
ArrayList<BarEntry> entries2 = new ArrayList<>();
for (int index = 0; index < itemcount; index++) {
for (int index = 0; index < count; index++) {
entries1.add(new BarEntry(0, getRandom(25, 25)));
// stacked
@ -147,7 +149,7 @@ public class CombinedChartActivity extends DemoBase {
BarDataSet set2 = new BarDataSet(entries2, "");
set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255));
set2.setValueTextColor(Color.rgb(61, 165, 255));
set2.setValueTextSize(10f);
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
@ -166,13 +168,13 @@ public class CombinedChartActivity extends DemoBase {
return d;
}
protected ScatterData generateScatterData() {
private ScatterData generateScatterData() {
ScatterData d = new ScatterData();
ArrayList<Entry> entries = new ArrayList<Entry>();
ArrayList<Entry> entries = new ArrayList<>();
for (float index = 0; index < itemcount; index += 0.5f)
for (float index = 0; index < count; index += 0.5f)
entries.add(new Entry(index + 0.25f, getRandom(10, 55)));
ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet");
@ -185,13 +187,13 @@ public class CombinedChartActivity extends DemoBase {
return d;
}
protected CandleData generateCandleData() {
private CandleData generateCandleData() {
CandleData d = new CandleData();
ArrayList<CandleEntry> entries = new ArrayList<CandleEntry>();
ArrayList<CandleEntry> entries = new ArrayList<>();
for (int index = 0; index < itemcount; index += 2)
for (int index = 0; index < count; index += 2)
entries.add(new CandleEntry(index + 1f, 90, 70, 85, 75f));
CandleDataSet set = new CandleDataSet(entries, "Candle DataSet");
@ -205,13 +207,13 @@ public class CombinedChartActivity extends DemoBase {
return d;
}
protected BubbleData generateBubbleData() {
private BubbleData generateBubbleData() {
BubbleData bd = new BubbleData();
ArrayList<BubbleEntry> entries = new ArrayList<BubbleEntry>();
ArrayList<BubbleEntry> entries = new ArrayList<>();
for (int index = 0; index < itemcount; index++) {
for (int index = 0; index < count; index++) {
float y = getRandom(10, 105);
float size = getRandom(100, 105);
entries.add(new BubbleEntry(index + 0.5f, y, size));
@ -237,34 +239,42 @@ public class CombinedChartActivity extends DemoBase {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java"));
startActivity(i);
break;
}
case R.id.actionToggleLineValues: {
for (IDataSet set : mChart.getData().getDataSets()) {
for (IDataSet set : chart.getData().getDataSets()) {
if (set instanceof LineDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleBarValues: {
for (IDataSet set : mChart.getData().getDataSets()) {
for (IDataSet set : chart.getData().getDataSets()) {
if (set instanceof BarDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionRemoveDataSet: {
int rnd = (int) getRandom(mChart.getData().getDataSetCount(), 0);
mChart.getData().removeDataSet(mChart.getData().getDataSetByIndex(rnd));
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
mChart.invalidate();
int rnd = (int) getRandom(chart.getData().getDataSetCount(), 0);
chart.getData().removeDataSet(chart.getData().getDataSetByIndex(rnd));
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
chart.invalidate();
break;
}
}
return true;
}
@Override
public void saveToGallery() { /* Intentionally left empty */ }
}

View file

@ -1,15 +1,19 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
@ -28,8 +32,8 @@ import java.util.List;
public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeListener {
private LineChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private LineChart chart;
private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@ -39,252 +43,89 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
tvX = (TextView) findViewById(R.id.tvXMax);
tvY = (TextView) findViewById(R.id.tvYMax);
setTitle("CubicLineChartActivity");
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
mSeekBarX.setProgress(45);
mSeekBarY.setProgress(100);
seekBarX = findViewById(R.id.seekBar1);
seekBarY = findViewById(R.id.seekBar2);
mSeekBarY.setOnSeekBarChangeListener(this);
mSeekBarX.setOnSeekBarChangeListener(this);
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setViewPortOffsets(0, 0, 0, 0);
mChart.setBackgroundColor(Color.rgb(104, 241, 175));
chart = findViewById(R.id.chart1);
chart.setViewPortOffsets(0, 0, 0, 0);
chart.setBackgroundColor(Color.rgb(104, 241, 175));
// no description text
mChart.getDescription().setEnabled(false);
chart.getDescription().setEnabled(false);
// enable touch gestures
mChart.setTouchEnabled(true);
chart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
mChart.setMaxHighlightDistance(300);
XAxis x = mChart.getXAxis();
chart.setDrawGridBackground(false);
chart.setMaxHighlightDistance(300);
XAxis x = chart.getXAxis();
x.setEnabled(false);
YAxis y = mChart.getAxisLeft();
y.setTypeface(mTfLight);
YAxis y = chart.getAxisLeft();
y.setTypeface(tfLight);
y.setLabelCount(6, false);
y.setTextColor(Color.WHITE);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
mChart.getAxisRight().setEnabled(false);
chart.getAxisRight().setEnabled(false);
// add data
setData(45, 100);
mChart.getLegend().setEnabled(false);
mChart.animateXY(2000, 2000);
seekBarY.setOnSeekBarChangeListener(this);
seekBarX.setOnSeekBarChangeListener(this);
// dont forget to refresh the drawing
mChart.invalidate();
}
// lower max, as cubic runs significantly slower than linear
seekBarX.setMax(700);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
return true;
}
seekBarX.setProgress(45);
seekBarY.setProgress(100);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
chart.getLegend().setEnabled(false);
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.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);
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
chart.animateXY(2000, 2000);
// don't forget to refresh the drawing
chart.invalidate();
}
private void setData(int count, float range) {
ArrayList<Entry> yVals = new ArrayList<Entry>();
ArrayList<Entry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float mult = (range + 1);
float val = (float) (Math.random() * mult) + 20;// + (float)
// ((mult *
// 0.1) / 10);
yVals.add(new Entry(i, val));
float val = (float) (Math.random() * (range + 1)) + 20;
values.add(new Entry(i, val));
}
LineDataSet set1;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
set1.setValues(yVals);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
set1.setValues(values);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
set1 = new LineDataSet(yVals, "DataSet 1");
set1 = new LineDataSet(values, "DataSet 1");
set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
set1.setCubicIntensity(0.2f);
//set1.setDrawFilled(true);
set1.setDrawFilled(true);
set1.setDrawCircles(false);
set1.setLineWidth(1.8f);
set1.setCircleRadius(4f);
@ -297,18 +138,183 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
set1.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return -10;
return chart.getAxisLeft().getAxisMinimum();
}
});
// create a data object with the datasets
// create a data object with the data sets
LineData data = new LineData(set1);
data.setValueTypeface(mTfLight);
data.setValueTypeface(tfLight);
data.setValueTextSize(9f);
data.setDrawValues(false);
// set data
mChart.setData(data);
chart.setData(data);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java"));
startActivity(i);
break;
}
case R.id.actionToggleValues: {
for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
List<ILineDataSet> sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
set.setDrawFilled(true);
}
chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
List<ILineDataSet> sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCirclesEnabled())
set.setDrawCircles(false);
else
set.setDrawCircles(true);
}
chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
List<ILineDataSet> sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
}
chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
List<ILineDataSet> sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setMode(set.getMode() == LineDataSet.Mode.STEPPED
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
}
chart.invalidate();
break;
}
case R.id.actionToggleHorizontalCubic: {
List<ILineDataSet> sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
chart.setPinchZoom(true);
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
chart.animateX(2000);
break;
}
case R.id.animateY: {
chart.animateY(2000);
break;
}
case R.id.animateXY: {
chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
}
return true;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvX.setText(String.valueOf(seekBarX.getProgress()));
tvY.setText(String.valueOf(seekBarY.getProgress()));
setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
chart.invalidate();
}
@Override
protected void saveToGallery() {
saveToGallery(chart, "CubicLineChartActivity");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
}

View file

@ -1,8 +1,10 @@
// TODO: Finish and add to main activity list
package com.xxmassdeveloper.mpchartexample;
import android.graphics.Typeface;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -28,13 +30,13 @@ import java.util.List;
/**
* This Activity demonstrates drawing into the Chart with the finger. Both line,
* bar and scatter charts can be used for drawing.
*
*
* @author Philipp Jahoda
*/
public class DrawChartActivity extends DemoBase implements OnChartValueSelectedListener,
OnDrawListener {
private LineChart mChart;
private LineChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -43,49 +45,49 @@ public class DrawChartActivity extends DemoBase implements OnChartValueSelectedL
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_draw_chart);
mChart = (LineChart) findViewById(R.id.chart1);
setTitle("DrawChartActivity");
chart = findViewById(R.id.chart1);
// listener for selecting and drawing
mChart.setOnChartValueSelectedListener(this);
mChart.setOnDrawListener(this);
chart.setOnChartValueSelectedListener(this);
chart.setOnDrawListener(this);
// if disabled, drawn datasets with the finger will not be automatically
// if disabled, drawn data sets with the finger will not be automatically
// finished
// mChart.setAutoFinish(true);
mChart.setDrawGridBackground(false);
// chart.setAutoFinish(true);
chart.setDrawGridBackground(false);
// add dummy-data to the chart
initWithDummyData();
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
XAxis xl = mChart.getXAxis();
xl.setTypeface(tf);
XAxis xl = chart.getXAxis();
xl.setTypeface(tfRegular);
xl.setAvoidFirstLastClipping(true);
YAxis yl = mChart.getAxisLeft();
yl.setTypeface(tf);
YAxis yl = chart.getAxisLeft();
yl.setTypeface(tfRegular);
mChart.getLegend().setEnabled(false);
chart.getLegend().setEnabled(false);
// mChart.setYRange(-40f, 40f, true);
// chart.setYRange(-40f, 40f, true);
// call this to reset the changed y-range
// mChart.resetYRange(true);
// chart.resetYRange(true);
}
private void initWithDummyData() {
ArrayList<Entry> yVals = new ArrayList<Entry>();
ArrayList<Entry> values = new ArrayList<>();
// create a dataset and give it a type (0)
LineDataSet set1 = new LineDataSet(yVals, "DataSet");
LineDataSet set1 = new LineDataSet(values, "DataSet");
set1.setLineWidth(3f);
set1.setCircleRadius(5f);
// create a data object with the datasets
// create a data object with the data sets
LineData data = new LineData(set1);
mChart.setData(data);
chart.setData(data);
}
@Override
@ -99,7 +101,7 @@ public class DrawChartActivity extends DemoBase implements OnChartValueSelectedL
switch (item.getItemId()) {
case R.id.actionToggleValues: {
List<ILineDataSet> sets = mChart.getData()
List<ILineDataSet> sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@ -108,39 +110,47 @@ public class DrawChartActivity extends DemoBase implements OnChartValueSelectedL
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
if(chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
mChart.setPinchZoom(true);
chart.setPinchZoom(true);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
// mChart.saveToGallery("title"+System.currentTimeMillis());
mChart.saveToPath("title" + System.currentTimeMillis(), "");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
}
return true;
}
@Override
protected void saveToGallery() {
saveToGallery(chart, "DrawChartActivity");
}
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.i("VAL SELECTED",
@ -164,7 +174,7 @@ public class DrawChartActivity extends DemoBase implements OnChartValueSelectedL
Log.i(Chart.LOG_TAG, "DataSet drawn. " + dataSet.toSimpleString());
// prepare the legend again
mChart.getLegendRenderer().computeLegend(mChart.getData());
chart.getLegendRenderer().computeLegend(chart.getData());
}
@Override

View file

@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
@ -23,7 +28,7 @@ import java.util.ArrayList;
public class DynamicalAddingActivity extends DemoBase implements OnChartValueSelectedListener {
private LineChart mChart;
private LineChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -32,24 +37,30 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawGridBackground(false);
mChart.getDescription().setEnabled(false);
setTitle("DynamicalAddingActivity");
// add an empty data object
mChart.setData(new LineData());
// mChart.getXAxis().setDrawLabels(false);
// mChart.getXAxis().setDrawGridLines(false);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
chart.setDrawGridBackground(false);
chart.getDescription().setEnabled(false);
chart.setNoDataText("No chart data available. Use the menu to add entries and data sets!");
mChart.invalidate();
// chart.getXAxis().setDrawLabels(false);
// chart.getXAxis().setDrawGridLines(false);
chart.invalidate();
}
int[] mColors = ColorTemplate.VORDIPLOM_COLORS;
private final int[] colors = ColorTemplate.VORDIPLOM_COLORS;
private void addEntry() {
LineData data = mChart.getData();
LineData data = chart.getData();
if (data == null) {
data = new LineData();
chart.setData(data);
}
ILineDataSet set = data.getDataSetByIndex(0);
// set.addEntry(...); // can be called as well
@ -61,25 +72,26 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
// choose a random dataSet
int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
float yValue = (float) (Math.random() * 10) + 50f;
ILineDataSet randomSet = data.getDataSetByIndex(randomDataSetIndex);
float value = (float) (Math.random() * 50) + 50f * (randomDataSetIndex + 1);
data.addEntry(new Entry(data.getDataSetByIndex(randomDataSetIndex).getEntryCount(), yValue), randomDataSetIndex);
data.addEntry(new Entry(randomSet.getEntryCount(), value), randomDataSetIndex);
data.notifyDataChanged();
// let the chart know it's data has changed
mChart.notifyDataSetChanged();
chart.notifyDataSetChanged();
mChart.setVisibleXRangeMaximum(6);
//mChart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
//
chart.setVisibleXRangeMaximum(6);
//chart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
//
// // this automatically refreshes the chart (calls invalidate())
mChart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
chart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
}
private void removeLastEntry() {
LineData data = mChart.getData();
LineData data = chart.getData();
if (data != null) {
@ -93,31 +105,33 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
// or remove by index
// mData.removeEntryByXValue(xIndex, dataSetIndex);
data.notifyDataChanged();
mChart.notifyDataSetChanged();
mChart.invalidate();
chart.notifyDataSetChanged();
chart.invalidate();
}
}
}
private void addDataSet() {
LineData data = mChart.getData();
if (data != null) {
LineData data = chart.getData();
if (data == null) {
chart.setData(new LineData());
} else {
int count = (data.getDataSetCount() + 1);
int amount = data.getDataSetByIndex(0).getEntryCount();
ArrayList<Entry> yVals = new ArrayList<Entry>();
ArrayList<Entry> values = new ArrayList<>();
for (int i = 0; i < data.getEntryCount(); i++) {
yVals.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
for (int i = 0; i < amount; i++) {
values.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
}
LineDataSet set = new LineDataSet(yVals, "DataSet " + count);
LineDataSet set = new LineDataSet(values, "DataSet " + count);
set.setLineWidth(2.5f);
set.setCircleRadius(4.5f);
int color = mColors[count % mColors.length];
int color = colors[count % colors.length];
set.setColor(color);
set.setCircleColor(color);
@ -127,74 +141,24 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
data.addDataSet(set);
data.notifyDataChanged();
mChart.notifyDataSetChanged();
mChart.invalidate();
chart.notifyDataSetChanged();
chart.invalidate();
}
}
private void removeDataSet() {
LineData data = mChart.getData();
LineData data = chart.getData();
if (data != null) {
data.removeDataSet(data.getDataSetByIndex(data.getDataSetCount() - 1));
mChart.notifyDataSetChanged();
mChart.invalidate();
chart.notifyDataSetChanged();
chart.invalidate();
}
}
@Override
public void onValueSelected(Entry e, Highlight h) {
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected() {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dynamical, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionAddEntry:
addEntry();
Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show();
break;
case R.id.actionRemoveEntry:
removeLastEntry();
Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show();
break;
case R.id.actionAddDataSet:
addDataSet();
Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show();
break;
case R.id.actionRemoveDataSet:
removeDataSet();
Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show();
break;
case R.id.actionAddEmptyLineData:
mChart.setData(new LineData());
mChart.invalidate();
Toast.makeText(this, "Empty data added!", Toast.LENGTH_SHORT).show();
break;
case R.id.actionClear:
mChart.clear();
Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
private LineDataSet createSet() {
LineDataSet set = new LineDataSet(null, "DataSet 1");
@ -208,4 +172,71 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
return set;
}
@Override
public void onValueSelected(Entry e, Highlight h) {
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected() {}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dynamical, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java"));
startActivity(i);
break;
}
case R.id.actionAddEntry: {
addEntry();
Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show();
break;
}
case R.id.actionRemoveEntry: {
removeLastEntry();
Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show();
break;
}
case R.id.actionAddDataSet: {
addDataSet();
Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show();
break;
}
case R.id.actionRemoveDataSet: {
removeDataSet();
Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show();
break;
}
case R.id.actionClear: {
chart.clear();
Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show();
break;
}
case R.id.actionSave: {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
}
return true;
}
@Override
protected void saveToGallery() {
saveToGallery(chart, "DynamicalAddingActivity");
}
}

View file

@ -1,8 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.LineChart;
@ -19,10 +23,19 @@ import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
/**
* This works by inverting the background and desired "fill" color. First, we draw the fill color
* that we want between the lines as the actual background of the chart. Then, we fill the area
* above the highest line and the area under the lowest line with the desired background color.
*
* This method makes it look like we filled the area between the lines, but really we are filling
* the area OUTSIDE the lines!
*/
@SuppressWarnings("SameParameterValue")
public class FilledLineActivity extends DemoBase {
private LineChart mChart;
private int mFillColor = Color.argb(150, 51, 181, 229);
private LineChart chart;
private final int fillColor = Color.argb(150, 51, 181, 229);
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -31,73 +44,71 @@ public class FilledLineActivity extends DemoBase {
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);
setTitle("FilledLineActivity");
mChart.setDrawBorders(true);
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.WHITE);
chart.setGridBackgroundColor(fillColor);
chart.setDrawGridBackground(true);
chart.setDrawBorders(true);
// no description text
mChart.getDescription().setEnabled(false);
chart.getDescription().setEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setEnabled(false);
XAxis xAxis = mChart.getXAxis();
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setAxisMaximum(900f);
leftAxis.setAxisMinimum(-250f);
leftAxis.setDrawAxisLine(false);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(false);
mChart.getAxisRight().setEnabled(false);
chart.getAxisRight().setEnabled(false);
// add data
setData(100, 60);
mChart.invalidate();
chart.invalidate();
}
private void setData(int count, float range) {
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
ArrayList<Entry> values1 = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) + 50;// + (float)
// ((mult *
// 0.1) / 10);
yVals1.add(new Entry(i, val));
float val = (float) (Math.random() * range) + 50;
values1.add(new Entry(i, val));
}
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
ArrayList<Entry> values2 = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) + 450;// + (float)
// ((mult *
// 0.1) / 10);
yVals2.add(new Entry(i, val));
float val = (float) (Math.random() * range) + 450;
values2.add(new Entry(i, val));
}
LineDataSet set1, set2;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
set2 = (LineDataSet)mChart.getData().getDataSetByIndex(1);
set1.setValues(yVals1);
set2.setValues(yVals2);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
set2 = (LineDataSet) chart.getData().getDataSetByIndex(1);
set1.setValues(values1);
set2.setValues(values2);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
set1 = new LineDataSet(yVals1, "DataSet 1");
set1 = new LineDataSet(values1, "DataSet 1");
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setColor(Color.rgb(255, 241, 46));
@ -112,12 +123,14 @@ public class FilledLineActivity extends DemoBase {
set1.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return mChart.getAxisLeft().getAxisMinimum();
// change the return value here to better understand the effect
// return 0;
return chart.getAxisLeft().getAxisMinimum();
}
});
// create a dataset and give it a type
set2 = new LineDataSet(yVals2, "DataSet 2");
set2 = new LineDataSet(values2, "DataSet 2");
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
set2.setColor(Color.rgb(255, 241, 46));
set2.setDrawCircles(false);
@ -131,20 +144,46 @@ public class FilledLineActivity extends DemoBase {
set2.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return mChart.getAxisLeft().getAxisMaximum();
// change the return value here to better understand the effect
// return 600;
return chart.getAxisLeft().getAxisMaximum();
}
});
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
ArrayList<ILineDataSet> dataSets = new ArrayList<>();
dataSets.add(set1); // add the data sets
dataSets.add(set2);
// create a data object with the datasets
// create a data object with the data sets
LineData data = new LineData(dataSets);
data.setDrawValues(false);
// set data
mChart.setData(data);
chart.setData(data);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.only_github, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java"));
startActivity(i);
break;
}
}
return true;
}
@Override
public void saveToGallery() { /* Intentionally left empty */ }
}

View file

@ -1,22 +1,24 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.Display;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
@ -26,9 +28,10 @@ import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
@SuppressWarnings("SameParameterValue")
public class HalfPieChartActivity extends DemoBase {
private PieChart mChart;
private PieChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -37,40 +40,42 @@ public class HalfPieChartActivity extends DemoBase {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart_half);
mChart = (PieChart) findViewById(R.id.chart1);
mChart.setBackgroundColor(Color.WHITE);
setTitle("HalfPieChartActivity");
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.WHITE);
moveOffScreen();
mChart.setUsePercentValues(true);
mChart.getDescription().setEnabled(false);
chart.setUsePercentValues(true);
chart.getDescription().setEnabled(false);
mChart.setCenterTextTypeface(mTfLight);
mChart.setCenterText(generateCenterSpannableText());
chart.setCenterTextTypeface(tfLight);
chart.setCenterText(generateCenterSpannableText());
mChart.setDrawHoleEnabled(true);
mChart.setHoleColor(Color.WHITE);
chart.setDrawHoleEnabled(true);
chart.setHoleColor(Color.WHITE);
mChart.setTransparentCircleColor(Color.WHITE);
mChart.setTransparentCircleAlpha(110);
chart.setTransparentCircleColor(Color.WHITE);
chart.setTransparentCircleAlpha(110);
mChart.setHoleRadius(58f);
mChart.setTransparentCircleRadius(61f);
chart.setHoleRadius(58f);
chart.setTransparentCircleRadius(61f);
mChart.setDrawCenterText(true);
chart.setDrawCenterText(true);
mChart.setRotationEnabled(false);
mChart.setHighlightPerTapEnabled(true);
chart.setRotationEnabled(false);
chart.setHighlightPerTapEnabled(true);
mChart.setMaxAngle(180f); // HALF CHART
mChart.setRotationAngle(180f);
mChart.setCenterTextOffset(0, -20);
chart.setMaxAngle(180f); // HALF CHART
chart.setRotationAngle(180f);
chart.setCenterTextOffset(0, -20);
setData(4, 100);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
chart.animateY(1400, Easing.EaseInOutQuad);
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@ -80,17 +85,17 @@ public class HalfPieChartActivity extends DemoBase {
l.setYOffset(0f);
// entry label styling
mChart.setEntryLabelColor(Color.WHITE);
mChart.setEntryLabelTypeface(mTfRegular);
mChart.setEntryLabelTextSize(12f);
chart.setEntryLabelColor(Color.WHITE);
chart.setEntryLabelTypeface(tfRegular);
chart.setEntryLabelTextSize(12f);
}
private void setData(int count, float range) {
ArrayList<PieEntry> values = new ArrayList<PieEntry>();
ArrayList<PieEntry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.length]));
values.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.length]));
}
PieDataSet dataSet = new PieDataSet(values, "Election Results");
@ -104,10 +109,10 @@ public class HalfPieChartActivity extends DemoBase {
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.WHITE);
data.setValueTypeface(mTfLight);
mChart.setData(data);
data.setValueTypeface(tfLight);
chart.setData(data);
mChart.invalidate();
chart.invalidate();
}
private SpannableString generateCenterSpannableText() {
@ -124,14 +129,40 @@ public class HalfPieChartActivity extends DemoBase {
private void moveOffScreen() {
Display display = getWindowManager().getDefaultDisplay();
int height = display.getHeight(); // deprecated
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int offset = (int)(height * 0.65); /* percent to move */
RelativeLayout.LayoutParams rlParams =
(RelativeLayout.LayoutParams)mChart.getLayoutParams();
(RelativeLayout.LayoutParams) chart.getLayoutParams();
rlParams.setMargins(0, 0, 0, -offset);
mChart.setLayoutParams(rlParams);
chart.setLayoutParams(rlParams);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.only_github, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java"));
startActivity(i);
break;
}
}
return true;
}
@Override
public void saveToGallery() { /* Intentionally left empty */ }
}

View file

@ -1,9 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
import android.annotation.SuppressLint;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -11,11 +15,9 @@ import android.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;
@ -35,8 +37,8 @@ import java.util.List;
public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
protected HorizontalBarChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private HorizontalBarChart chart;
private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@ -46,67 +48,68 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_horizontalbarchart);
tvX = (TextView) findViewById(R.id.tvXMax);
tvY = (TextView) findViewById(R.id.tvYMax);
setTitle("HorizontalBarChartActivity");
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
// mChart.setHighlightEnabled(false);
seekBarX = findViewById(R.id.seekBar1);
seekBarY = findViewById(R.id.seekBar2);
mChart.setDrawBarShadow(false);
seekBarY.setOnSeekBarChangeListener(this);
seekBarX.setOnSeekBarChangeListener(this);
mChart.setDrawValueAboveBar(true);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
// chart.setHighlightEnabled(false);
mChart.getDescription().setEnabled(false);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
// chart.setDrawBarShadow(true);
mChart.setDrawGridBackground(false);
chart.setDrawGridBackground(false);
XAxis xl = mChart.getXAxis();
XAxis xl = chart.getXAxis();
xl.setPosition(XAxisPosition.BOTTOM);
xl.setTypeface(mTfLight);
xl.setTypeface(tfLight);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
xl.setGranularity(10f);
YAxis yl = mChart.getAxisLeft();
yl.setTypeface(mTfLight);
YAxis yl = chart.getAxisLeft();
yl.setTypeface(tfLight);
yl.setDrawAxisLine(true);
yl.setDrawGridLines(true);
yl.setAxisMinimum(0f); // this replaces setStartAtZero(true)
// yl.setInverted(true);
YAxis yr = mChart.getAxisRight();
yr.setTypeface(mTfLight);
YAxis yr = chart.getAxisRight();
yr.setTypeface(tfLight);
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
yr.setAxisMinimum(0f); // this replaces setStartAtZero(true)
// yr.setInverted(true);
setData(12, 50);
mChart.setFitBars(true);
mChart.animateY(2500);
chart.setFitBars(true);
chart.animateY(2500);
// setting data
mSeekBarY.setProgress(50);
mSeekBarX.setProgress(12);
seekBarY.setProgress(50);
seekBarX.setProgress(12);
mSeekBarY.setOnSeekBarChangeListener(this);
mSeekBarX.setOnSeekBarChangeListener(this);
Legend l = mChart.getLegend();
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@ -115,6 +118,42 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
l.setXEntrySpace(4f);
}
private void setData(int count, float range) {
float barWidth = 9f;
float spaceForBar = 10f;
ArrayList<BarEntry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range);
values.add(new BarEntry(i * spaceForBar, val,
getResources().getDrawable(R.drawable.star)));
}
BarDataSet set1;
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
set1.setValues(values);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(values, "DataSet 1");
set1.setDrawIcons(false);
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(tfLight);
data.setBarWidth(barWidth);
chart.setData(data);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
@ -125,80 +164,80 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.viewGithub: {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java"));
startActivity(i);
break;
}
case R.id.actionToggleValues: {
List<IBarDataSet> sets = mChart.getData()
List<IBarDataSet> sets = chart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
IBarDataSet set = (BarDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
iSet.setDrawValues(!iSet.isDrawValuesEnabled());
}
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
List<IBarDataSet> sets = mChart.getData()
List<IBarDataSet> sets = chart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
IBarDataSet set = (BarDataSet) iSet;
set.setDrawIcons(!set.isDrawIconsEnabled());
iSet.setDrawIcons(!iSet.isDrawIconsEnabled());
}
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
if(chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
if (chart.isPinchZoomEnabled())
chart.setPinchZoom(false);
else
mChart.setPinchZoom(true);
chart.setPinchZoom(true);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
mChart.invalidate();
chart.invalidate();
break;
}
case R.id.animateX: {
mChart.animateX(3000);
chart.animateX(2000);
break;
}
case R.id.animateY: {
mChart.animateY(3000);
chart.animateY(2000);
break;
}
case R.id.animateXY: {
mChart.animateXY(3000, 3000);
chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
Toast.LENGTH_SHORT).show();
} else
Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
.show();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
saveToGallery();
} else {
requestStoragePermission(chart);
}
break;
}
}
@ -208,64 +247,27 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvX.setText("" + (mSeekBarX.getProgress() + 1));
tvY.setText("" + (mSeekBarY.getProgress()));
tvX.setText(String.valueOf(seekBarX.getProgress()));
tvY.setText(String.valueOf(seekBarY.getProgress()));
setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
mChart.setFitBars(true);
mChart.invalidate();
setData(seekBarX.getProgress(), seekBarY.getProgress());
chart.setFitBars(true);
chart.invalidate();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
protected void saveToGallery() {
saveToGallery(chart, "HorizontalBarChartActivity");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
public void onStartTrackingTouch(SeekBar seekBar) {}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
private void setData(int count, float range) {
private final RectF mOnValueSelectedRectF = new RectF();
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,
getResources().getDrawable(R.drawable.star)));
}
BarDataSet set1;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setValues(yVals1);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "DataSet 1");
set1.setDrawIcons(false);
ArrayList<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);
}
}
protected RectF mOnValueSelectedRectF = new RectF();
@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
@ -273,9 +275,9 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
return;
RectF bounds = mOnValueSelectedRectF;
mChart.getBarBounds((BarEntry) e, bounds);
chart.getBarBounds((BarEntry) e, bounds);
MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
MPPointF position = chart.getPosition(e, chart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency());
Log.i("bounds", bounds.toString());
@ -285,6 +287,5 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
}
@Override
public void onNothingSelected() {
};
public void onNothingSelected() {}
}

Some files were not shown because too many files have changed in this diff Show more