diff --git a/MPChartExample/AndroidManifest.xml b/MPChartExample/AndroidManifest.xml
index 3fa15cd69c..292e0933a2 100644
--- a/MPChartExample/AndroidManifest.xml
+++ b/MPChartExample/AndroidManifest.xml
@@ -1,71 +1,66 @@
+ package="com.xxmassdeveloper.mpchartexample">
-
+ android:theme="@style/AppTheme">
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MPChartExample/build.gradle b/MPChartExample/build.gradle
index 8e6fe137b8..2856bc0109 100644
--- a/MPChartExample/build.gradle
+++ b/MPChartExample/build.gradle
@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
- compileSdkVersion 27
- buildToolsVersion '27.0.3'
+ compileSdkVersion 28
defaultConfig {
+ applicationId "com.xxmassdeveloper.mpchartexample"
minSdkVersion 16
- targetSdkVersion 27
+ targetSdkVersion 28
versionCode 56
versionName '3.0.3'
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
sourceSets {
main {
@@ -33,17 +33,14 @@ android {
}
}
-buildscript {
- repositories {
- jcenter()
- google()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.1.2'
- //classpath 'io.realm:realm-gradle-plugin:0.88.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
+dependencies {
+ implementation "androidx.appcompat:appcompat:1.0.0"
+ implementation 'com.google.android.material:material:1.0.0'
+ //implementation "androidx.legacy:legacy-support-v4:1.0.0"
+ //implementation "androidx.legacy:legacy-support-v13:1.0.0"
+ //compile project(':MPChartLib-Realm') // clone "https://github.com/PhilJay/MPAndroidChart-Realm" to get this or uncomment the gradle dependency below:
+ implementation 'com.github.PhilJay:MPAndroidChart-Realm:v2.0.2@aar'
+ implementation project(':MPChartLib')
}
repositories {
@@ -52,14 +49,3 @@ repositories {
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
-
-dependencies {
- //compile fileTree(dir: 'libs', include: ['*.jar'])
- //compile project(':MPChartLib-Realm') // clone "https://github.com/PhilJay/MPAndroidChart-Realm" to get this or uncomment the gradle dependency below:
- implementation 'com.github.PhilJay:MPAndroidChart-Realm:v2.0.2@aar'
-
- implementation project(':MPChartLib')
- implementation 'com.android.support:appcompat-v7:27.1.1'
- //compile 'io.realm:realm-android:0.87.5' // dependency for realm-database API (http://realm.io)
- //compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
-}
diff --git a/MPChartExample/res/drawable-nodpi/marker.png b/MPChartExample/res/drawable-nodpi/marker.png
deleted file mode 100644
index 616cdd7b31..0000000000
Binary files a/MPChartExample/res/drawable-nodpi/marker.png and /dev/null differ
diff --git a/MPChartExample/res/layout/activity_age_distribution.xml b/MPChartExample/res/layout/activity_age_distribution.xml
index b023d3ab2d..574510fa0b 100644
--- a/MPChartExample/res/layout/activity_age_distribution.xml
+++ b/MPChartExample/res/layout/activity_age_distribution.xml
@@ -1,7 +1,7 @@
+ android:layout_height="match_parent">
-
-
+
+
+ android:layout_height="match_parent">
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_barchart_sinus.xml b/MPChartExample/res/layout/activity_barchart_sinus.xml
index 78b849081f..f39f2c7739 100644
--- a/MPChartExample/res/layout/activity_barchart_sinus.xml
+++ b/MPChartExample/res/layout/activity_barchart_sinus.xml
@@ -28,7 +28,7 @@
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/seekbarValues"
android:layout_alignParentRight="true"
- android:text="0"
+ android:text="@string/dash"
android:layout_marginBottom="15dp"
android:layout_marginRight="10dp"
android:gravity="right"
diff --git a/MPChartExample/res/layout/activity_bubblechart.xml b/MPChartExample/res/layout/activity_bubblechart.xml
index 1cc55dfb42..d3df042fd0 100644
--- a/MPChartExample/res/layout/activity_bubblechart.xml
+++ b/MPChartExample/res/layout/activity_bubblechart.xml
@@ -1,7 +1,7 @@
+ android:layout_height="match_parent">
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_candlechart.xml b/MPChartExample/res/layout/activity_candlechart.xml
index f9384c9158..39df4c8104 100644
--- a/MPChartExample/res/layout/activity_candlechart.xml
+++ b/MPChartExample/res/layout/activity_candlechart.xml
@@ -1,14 +1,14 @@
+ android:layout_height="match_parent">
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_colored_lines.xml b/MPChartExample/res/layout/activity_colored_lines.xml
index cac3442e54..f6b61cfc54 100644
--- a/MPChartExample/res/layout/activity_colored_lines.xml
+++ b/MPChartExample/res/layout/activity_colored_lines.xml
@@ -2,7 +2,7 @@
+ android:orientation="vertical">
-
+
diff --git a/MPChartExample/res/layout/activity_draw_chart.xml b/MPChartExample/res/layout/activity_draw_chart.xml
index 5b3792395b..5e2f1a21fc 100644
--- a/MPChartExample/res/layout/activity_draw_chart.xml
+++ b/MPChartExample/res/layout/activity_draw_chart.xml
@@ -1,7 +1,7 @@
+ android:layout_height="match_parent">
+ android:layout_height="match_parent">
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_linechart.xml b/MPChartExample/res/layout/activity_linechart.xml
index 7cadd8dd65..d7cd3a1e39 100644
--- a/MPChartExample/res/layout/activity_linechart.xml
+++ b/MPChartExample/res/layout/activity_linechart.xml
@@ -1,5 +1,6 @@
-
@@ -8,7 +9,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/seekBar1" />
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_linechart_time.xml b/MPChartExample/res/layout/activity_linechart_time.xml
index 27f70f8ba3..c63d3e6f41 100644
--- a/MPChartExample/res/layout/activity_linechart_time.xml
+++ b/MPChartExample/res/layout/activity_linechart_time.xml
@@ -25,7 +25,7 @@
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
- android:text="500"
+ android:text="@string/dash"
android:layout_marginBottom="15dp"
android:layout_marginRight="10dp"
android:gravity="right"
diff --git a/MPChartExample/res/layout/activity_listview_chart.xml b/MPChartExample/res/layout/activity_listview_chart.xml
index b11c3d1ef8..12aa2f8500 100644
--- a/MPChartExample/res/layout/activity_listview_chart.xml
+++ b/MPChartExample/res/layout/activity_listview_chart.xml
@@ -2,7 +2,7 @@
+ android:orientation="vertical">
+ android:layout_height="fill_parent"
+ android:scrollbarFadeDuration="0">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_performance_linechart.xml b/MPChartExample/res/layout/activity_performance_linechart.xml
index d7cd5747fe..515321e1de 100644
--- a/MPChartExample/res/layout/activity_performance_linechart.xml
+++ b/MPChartExample/res/layout/activity_performance_linechart.xml
@@ -1,8 +1,7 @@
+ android:layout_height="match_parent">
+ android:layout_height="match_parent">
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_piechart_noseekbar.xml b/MPChartExample/res/layout/activity_piechart_noseekbar.xml
index 52c62806b0..a92eec3c48 100644
--- a/MPChartExample/res/layout/activity_piechart_noseekbar.xml
+++ b/MPChartExample/res/layout/activity_piechart_noseekbar.xml
@@ -1,11 +1,11 @@
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_radarchart.xml b/MPChartExample/res/layout/activity_radarchart.xml
index a197875bb8..aff98010c8 100644
--- a/MPChartExample/res/layout/activity_radarchart.xml
+++ b/MPChartExample/res/layout/activity_radarchart.xml
@@ -1,7 +1,7 @@
+ android:layout_height="match_parent">
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MPChartExample/res/layout/activity_realm_wiki.xml b/MPChartExample/res/layout/activity_realm_wiki.xml
index d4e27933cf..a9ba53fa6f 100644
--- a/MPChartExample/res/layout/activity_realm_wiki.xml
+++ b/MPChartExample/res/layout/activity_realm_wiki.xml
@@ -2,7 +2,6 @@
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_realtime_linechart.xml b/MPChartExample/res/layout/activity_realtime_linechart.xml
index 0f09b88325..9ee392a8f2 100644
--- a/MPChartExample/res/layout/activity_realtime_linechart.xml
+++ b/MPChartExample/res/layout/activity_realtime_linechart.xml
@@ -7,5 +7,5 @@
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
-
+
diff --git a/MPChartExample/res/layout/activity_scatterchart.xml b/MPChartExample/res/layout/activity_scatterchart.xml
index 947f8ce56d..41df167e5a 100644
--- a/MPChartExample/res/layout/activity_scatterchart.xml
+++ b/MPChartExample/res/layout/activity_scatterchart.xml
@@ -1,14 +1,14 @@
+ android:layout_height="match_parent">
-
+
+ android:layout_height="match_parent">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/activity_scrollview.xml b/MPChartExample/res/layout/activity_scrollview.xml
index 95c78fedeb..f4865426fd 100644
--- a/MPChartExample/res/layout/activity_scrollview.xml
+++ b/MPChartExample/res/layout/activity_scrollview.xml
@@ -1,18 +1,18 @@
+ android:layout_height="wrap_content">
-
+
+ android:text="@string/scrollViewStart" />
@@ -30,13 +30,13 @@
-
+
-
+ android:text="@string/scrollViewEnd" />
+
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/layout/custom_marker_view.xml b/MPChartExample/res/layout/custom_marker_view.xml
index 12cb53c2e2..f8444bf8c4 100644
--- a/MPChartExample/res/layout/custom_marker_view.xml
+++ b/MPChartExample/res/layout/custom_marker_view.xml
@@ -1,8 +1,10 @@
+ android:background="@drawable/marker2"
+ tools:ignore="Overdraw">
-
-
+
diff --git a/MPChartExample/res/layout/list_item.xml b/MPChartExample/res/layout/list_item.xml
index c9c11e93ba..2b6069b4f4 100644
--- a/MPChartExample/res/layout/list_item.xml
+++ b/MPChartExample/res/layout/list_item.xml
@@ -12,7 +12,7 @@
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:text="Medium Text"
- android:textSize="16dp"/>
+ android:textSize="16sp"/>
@@ -32,11 +32,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:text="NEW"
+ android:text="@string/textNew"
android:background="@drawable/new_background"
android:textColor="@android:color/white"
android:id="@+id/tvNew"
- android:textSize="11dp"
+ android:textSize="12sp"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
diff --git a/MPChartExample/res/layout/list_item_section.xml b/MPChartExample/res/layout/list_item_section.xml
new file mode 100644
index 0000000000..f71901d1fb
--- /dev/null
+++ b/MPChartExample/res/layout/list_item_section.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/MPChartExample/res/layout/radar_markerview.xml b/MPChartExample/res/layout/radar_markerview.xml
index 9ab1b84121..d94768dd67 100644
--- a/MPChartExample/res/layout/radar_markerview.xml
+++ b/MPChartExample/res/layout/radar_markerview.xml
@@ -1,8 +1,10 @@
+ android:background="@drawable/radar_marker"
+ tools:ignore="Overdraw">
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ tools:ignore="SmallSp" />
diff --git a/MPChartExample/res/menu/bar.xml b/MPChartExample/res/menu/bar.xml
index 4bbfedd4db..e05fc59797 100644
--- a/MPChartExample/res/menu/bar.xml
+++ b/MPChartExample/res/menu/bar.xml
@@ -2,48 +2,48 @@
\ No newline at end of file
+
diff --git a/MPChartExample/res/menu/bubble.xml b/MPChartExample/res/menu/bubble.xml
index b7950291e9..7b9ab5cd11 100644
--- a/MPChartExample/res/menu/bubble.xml
+++ b/MPChartExample/res/menu/bubble.xml
@@ -1,45 +1,45 @@
\ No newline at end of file
+
diff --git a/MPChartExample/res/menu/candle.xml b/MPChartExample/res/menu/candle.xml
index cdf1c4e4dd..42a1a7e050 100644
--- a/MPChartExample/res/menu/candle.xml
+++ b/MPChartExample/res/menu/candle.xml
@@ -2,40 +2,48 @@
\ No newline at end of file
+
diff --git a/MPChartExample/res/menu/combined.xml b/MPChartExample/res/menu/combined.xml
index 7e37ba0d83..c7def2509c 100644
--- a/MPChartExample/res/menu/combined.xml
+++ b/MPChartExample/res/menu/combined.xml
@@ -1,16 +1,21 @@
\ No newline at end of file
+
+
diff --git a/MPChartExample/res/menu/draw.xml b/MPChartExample/res/menu/draw.xml
index 50f35239e7..36383db54f 100644
--- a/MPChartExample/res/menu/draw.xml
+++ b/MPChartExample/res/menu/draw.xml
@@ -3,34 +3,30 @@
-
+ android:title="@string/actionToggleValues">
-
+ android:title="@string/actionToggleFilled">
-
+ android:title="@string/actionToggleCircles">
-
-
- -
-
- -
+ android:title="@string/actionToggleHighlight">
-
+ android:title="@string/actionTogglePinch">
-
+ android:title="@string/actionToggleAutoScale">
+
+ -
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/menu/dynamical.xml b/MPChartExample/res/menu/dynamical.xml
index c43a3a0ae6..68d4fab0c9 100644
--- a/MPChartExample/res/menu/dynamical.xml
+++ b/MPChartExample/res/menu/dynamical.xml
@@ -1,33 +1,33 @@
\ No newline at end of file
+
+
diff --git a/MPChartExample/res/menu/line.xml b/MPChartExample/res/menu/line.xml
index f9f5be9615..a812b91b5a 100644
--- a/MPChartExample/res/menu/line.xml
+++ b/MPChartExample/res/menu/line.xml
@@ -1,64 +1,65 @@
\ No newline at end of file
+
+
diff --git a/MPChartExample/res/menu/main.xml b/MPChartExample/res/menu/main.xml
index b45d3bbb9f..9ac13dbbae 100644
--- a/MPChartExample/res/menu/main.xml
+++ b/MPChartExample/res/menu/main.xml
@@ -3,19 +3,15 @@
-
+ android:title="@string/viewGithub">
-
-
- -
+ android:title="@string/reportProblem">
-
+ android:title="@string/viewWebsite">
-
\ No newline at end of file
+
diff --git a/MPChartExample/res/menu/only_github.xml b/MPChartExample/res/menu/only_github.xml
new file mode 100644
index 0000000000..c0a9b66934
--- /dev/null
+++ b/MPChartExample/res/menu/only_github.xml
@@ -0,0 +1,7 @@
+
+
diff --git a/MPChartExample/res/menu/pie.xml b/MPChartExample/res/menu/pie.xml
index 0e5323a590..b2de043409 100644
--- a/MPChartExample/res/menu/pie.xml
+++ b/MPChartExample/res/menu/pie.xml
@@ -1,49 +1,53 @@
\ No newline at end of file
+
diff --git a/MPChartExample/res/menu/radar.xml b/MPChartExample/res/menu/radar.xml
index 14690f446c..2a5c19cf81 100644
--- a/MPChartExample/res/menu/radar.xml
+++ b/MPChartExample/res/menu/radar.xml
@@ -1,57 +1,62 @@
\ No newline at end of file
+
+
diff --git a/MPChartExample/res/menu/realm.xml b/MPChartExample/res/menu/realm.xml
index f954443b30..ce149bef91 100644
--- a/MPChartExample/res/menu/realm.xml
+++ b/MPChartExample/res/menu/realm.xml
@@ -1,8 +1,13 @@
\ No newline at end of file
+
+
diff --git a/MPChartExample/res/menu/realtime.xml b/MPChartExample/res/menu/realtime.xml
index a4b2d22a78..48cc7ccd0a 100644
--- a/MPChartExample/res/menu/realtime.xml
+++ b/MPChartExample/res/menu/realtime.xml
@@ -1,16 +1,25 @@
\ No newline at end of file
+ -
+
+
+
diff --git a/MPChartExample/res/menu/scatter.xml b/MPChartExample/res/menu/scatter.xml
index b7950291e9..eb8e0efa67 100644
--- a/MPChartExample/res/menu/scatter.xml
+++ b/MPChartExample/res/menu/scatter.xml
@@ -1,45 +1,45 @@
\ No newline at end of file
+
diff --git a/MPChartExample/res/values-sw600dp/dimens.xml b/MPChartExample/res/values-sw600dp/dimens.xml
deleted file mode 100644
index 44f01db75f..0000000000
--- a/MPChartExample/res/values-sw600dp/dimens.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
diff --git a/MPChartExample/res/values-sw720dp-land/dimens.xml b/MPChartExample/res/values-sw720dp-land/dimens.xml
deleted file mode 100644
index 61e3fa8fbc..0000000000
--- a/MPChartExample/res/values-sw720dp-land/dimens.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
- 128dp
-
-
diff --git a/MPChartExample/res/values-v11/styles.xml b/MPChartExample/res/values-v11/styles.xml
deleted file mode 100644
index 3c02242ad0..0000000000
--- a/MPChartExample/res/values-v11/styles.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
diff --git a/MPChartExample/res/values-v14/styles.xml b/MPChartExample/res/values-v14/styles.xml
deleted file mode 100644
index a91fd0372b..0000000000
--- a/MPChartExample/res/values-v14/styles.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
diff --git a/MPChartExample/res/values/dimens.xml b/MPChartExample/res/values/dimens.xml
deleted file mode 100644
index 55c1e5908c..0000000000
--- a/MPChartExample/res/values/dimens.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
- 16dp
- 16dp
-
-
diff --git a/MPChartExample/res/values/strings.xml b/MPChartExample/res/values/strings.xml
index 7f59af64bb..d81d9b1a0c 100644
--- a/MPChartExample/res/values/strings.xml
+++ b/MPChartExample/res/values/strings.xml
@@ -2,7 +2,54 @@
MPAndroidChart Example
- Settings
- Hello world!
+
+ View on GitHub
+ Problem Report
+ Developer Website
+ Save to Gallery
+ realm.io website
+
+ Animate X
+ Animate Y
+ Animate XY
+
+ Toggle Values
+ Toggle Y-Values
+ Toggle X-Values
+
+ Toggle Icons
+ Toggle Highlight
+ Toggle PinchZoom
+ Toggle Auto Scale
+
+ Toggle Line Values
+ Toggle Bar Values
+ Toggle Bar Borders
+ Toggle Filled
+ Toggle Circles
+ Toggle Shadow Color
+
+ Toggle Cubic
+ Toggle Stepped
+ Toggle Horizontal Cubic
+
+ Add Entry
+ Add Multiple
+ Remove Entry
+ Add Data Set
+ Remove Data Set
+ Clear chart
+
+ Toggle Percent
+ Toggle Hole
+ Draw Center Text
+ Toggle Highlight Circle
+ Toggle Rotation
+ Spin Animation
+
+ -
+ START OF SCROLLVIEW
+ END OF SCROLLVIEW
+ NEW
diff --git a/MPChartExample/res/values/styles.xml b/MPChartExample/res/values/styles.xml
index 6ce89c7ba4..9d5b53bd6c 100644
--- a/MPChartExample/res/values/styles.xml
+++ b/MPChartExample/res/values/styles.xml
@@ -1,19 +1,7 @@
-
-
-
-
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
index f6cffddcbe..5916619645 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java
@@ -1,14 +1,18 @@
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 android.widget.Toast;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
@@ -25,8 +29,8 @@
public class AnotherBarActivity extends DemoBase implements OnSeekBarChangeListener {
- private BarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -36,48 +40,89 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
+ setTitle("AnotherBarActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
+ chart = findViewById(R.id.chart1);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawBarShadow(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawBarShadow(false);
+ chart.setDrawGridBackground(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
-
- mChart.getAxisLeft().setDrawGridLines(false);
+
+ chart.getAxisLeft().setDrawGridLines(false);
// setting data
- mSeekBarX.setProgress(10);
- mSeekBarY.setProgress(100);
+ seekBarX.setProgress(10);
+ seekBarY.setProgress(100);
// add a nice and smooth animation
- mChart.animateY(2500);
-
- mChart.getLegend().setEnabled(false);
+ chart.animateY(1500);
+
+ chart.getLegend().setEnabled(false);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < seekBarX.getProgress(); i++) {
+ float multi = (seekBarY.getProgress() + 1);
+ float val = (float) (Math.random() * multi) + multi / 3;
+ values.add(new BarEntry(i, val));
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set1 = new BarDataSet(values, "Data Set");
+ set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
+ set1.setDrawValues(false);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
+
+ BarData data = new BarData(dataSets);
+ chart.setData(data);
+ chart.setFitBars(true);
+ }
+
+ chart.invalidate();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
+ menu.removeItem(R.id.actionToggleIcons);
return true;
}
@@ -85,63 +130,71 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.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: { 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;
}
}
@@ -149,52 +202,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
- float mult = (mSeekBarY.getProgress() + 1);
- float val = (float) (Math.random() * mult) + mult / 3;
- yVals1.add(new BarEntry(i, val));
- }
-
- BarDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals1);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set1 = new BarDataSet(yVals1, "Data Set");
- set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
- set1.setDrawValues(false);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1);
-
- BarData data = new BarData(dataSets);
- mChart.setData(data);
- mChart.setFitBars(true);
- }
-
- mChart.invalidate();
+ public void saveToGallery() {
+ saveToGallery(chart, "AnotherBarActivity");
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
index c0e3405625..fcdaae364d 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
@@ -1,10 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
-import android.annotation.SuppressLint;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.RectF;
+import android.net.Uri;
import android.os.Bundle;
-import android.support.v4.content.ContextCompat;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -12,7 +15,6 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.Legend;
@@ -32,7 +34,6 @@
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.model.GradientColor;
-import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
@@ -45,8 +46,8 @@
public class BarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- protected BarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -56,35 +57,40 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
+ setTitle("BarChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
- mChart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart.setDrawBarShadow(false);
+ chart.setDrawValueAboveBar(true);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
- // mChart.setDrawYLabels(false);
+ chart.setDrawGridBackground(false);
+ // chart.setDrawYLabels(false);
- IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart);
+ IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setTypeface(mTfLight);
+ xAxis.setTypeface(tfLight);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f); // only intervals of 1 day
xAxis.setLabelCount(7);
@@ -92,23 +98,23 @@ protected void onCreate(Bundle savedInstanceState) {
IAxisValueFormatter custom = new MyAxisValueFormatter();
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(8, false);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
- rightAxis.setTypeface(mTfLight);
+ rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(8, false);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -117,25 +123,85 @@ protected void onCreate(Bundle savedInstanceState) {
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
- // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
- // "def", "ghj", "ikl", "mno" });
- // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
- // "def", "ghj", "ikl", "mno" });
XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
+ mv.setChartView(chart); // For bounds control
+ chart.setMarker(mv); // Set the marker to the chart
+ // setting data
+ seekBarY.setProgress(50);
+ seekBarX.setProgress(12);
setData(12, 50);
- // setting data
- mSeekBarY.setProgress(50);
- mSeekBarX.setProgress(12);
+ // chart.setDrawLegend(false);
+ }
+
+ private void setData(int count, float range) {
+
+ float start = 1f;
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = (int) start; i < start + count; i++) {
+ float val = (float) (Math.random() * (range + 1));
+
+ if (Math.random() * 100 < 25) {
+ values.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
+ } else {
+ values.add(new BarEntry(i, val));
+ }
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+
+ } else {
+ set1 = new BarDataSet(values, "The year 2017");
+
+ set1.setDrawIcons(false);
+
+// set1.setColors(ColorTemplate.MATERIAL_COLORS);
+
+ /*int startColor = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
+ int endColor = ContextCompat.getColor(this, android.R.color.holo_blue_bright);
+ set1.setGradientColor(startColor, endColor);*/
+
+ int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
+ int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
+ int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
+ int startColor4 = ContextCompat.getColor(this, android.R.color.holo_green_light);
+ int startColor5 = ContextCompat.getColor(this, android.R.color.holo_red_light);
+ int endColor1 = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
+ int endColor2 = ContextCompat.getColor(this, android.R.color.holo_purple);
+ int endColor3 = ContextCompat.getColor(this, android.R.color.holo_green_dark);
+ int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
+ int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
+
+ List gradientColors = new ArrayList<>();
+ gradientColors.add(new GradientColor(startColor1, endColor1));
+ gradientColors.add(new GradientColor(startColor2, endColor2));
+ gradientColors.add(new GradientColor(startColor3, endColor3));
+ gradientColors.add(new GradientColor(startColor4, endColor4));
+ gradientColors.add(new GradientColor(startColor5, endColor5));
+
+ set1.setGradientColors(gradientColors);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
- // mChart.setDrawLegend(false);
+ BarData data = new BarData(dataSets);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setBarWidth(0.9f);
+
+ chart.setData(data);
+ }
}
@Override
@@ -148,68 +214,72 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -219,110 +289,42 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 2));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1 , mSeekBarY.getProgress());
- mChart.invalidate();
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
+ public void saveToGallery() {
+ saveToGallery(chart, "BarChartActivity");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
- }
-
- private void setData(int count, float range) {
-
- float start = 1f;
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = (int) start; i < start + count + 1; i++) {
- float mult = (range + 1);
- float val = (float) (Math.random() * mult);
-
- if (Math.random() * 100 < 25) {
- yVals1.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
- } else {
- yVals1.add(new BarEntry(i, val));
- }
- }
-
- BarDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals1);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set1 = new BarDataSet(yVals1, "The year 2017");
-
- set1.setDrawIcons(false);
-
-// set1.setColors(ColorTemplate.MATERIAL_COLORS);
-
- /*int startColor = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
- int endColor = ContextCompat.getColor(this, android.R.color.holo_blue_bright);
- set1.setGradientColor(startColor, endColor);*/
-
- int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
- int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
- int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
- int startColor4 = ContextCompat.getColor(this, android.R.color.holo_green_light);
- int startColor5 = ContextCompat.getColor(this, android.R.color.holo_red_light);
- int endColor1 = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
- int endColor2 = ContextCompat.getColor(this, android.R.color.holo_purple);
- int endColor3 = ContextCompat.getColor(this, android.R.color.holo_green_dark);
- int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
- int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
-
- List gradientColors = new ArrayList<>();
- gradientColors.add(new GradientColor(startColor1, endColor1));
- gradientColors.add(new GradientColor(startColor2, endColor2));
- gradientColors.add(new GradientColor(startColor3, endColor3));
- gradientColors.add(new GradientColor(startColor4, endColor4));
- gradientColors.add(new GradientColor(startColor5, endColor5));
-
- set1.setGradientColors(gradientColors);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1);
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- BarData data = new BarData(dataSets);
- data.setValueTextSize(10f);
- data.setValueTypeface(mTfLight);
- data.setBarWidth(0.9f);
-
- mChart.setData(data);
- }
- }
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
- protected RectF mOnValueSelectedRectF = new RectF();
+ private RectF onValueSelectedRectF = new RectF();
- @SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
if (e == null)
return;
- RectF bounds = mOnValueSelectedRectF;
- mChart.getBarBounds((BarEntry) e, bounds);
- MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);
+ RectF bounds = onValueSelectedRectF;
+ chart.getBarBounds((BarEntry) e, bounds);
+ MPPointF position = chart.getPosition(e, AxisDependency.LEFT);
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
Log.i("x-index",
- "low: " + mChart.getLowestVisibleX() + ", high: "
- + mChart.getHighestVisibleX());
+ "low: " + chart.getLowestVisibleX() + ", high: "
+ + chart.getHighestVisibleX());
MPPointF.recycleInstance(position);
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
index 204dc1fe64..d0c0bc453d 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -29,12 +34,13 @@
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
+import java.util.Locale;
public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private BarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -44,51 +50,53 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
+ setTitle("BarChartActivityMultiDataset");
+
tvX = findViewById(R.id.tvXMax);
tvX.setTextSize(10);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- mChart.getDescription().setEnabled(false);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ chart.getDescription().setEnabled(false);
-// mChart.setDrawBorders(true);
+// chart.setDrawBorders(true);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawBarShadow(false);
+ chart.setDrawBarShadow(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
+ mv.setChartView(chart); // For bounds control
+ chart.setMarker(mv); // Set the marker to the chart
- mSeekBarX.setProgress(10);
- mSeekBarY.setProgress(100);
+ seekBarX.setProgress(10);
+ seekBarY.setProgress(100);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(true);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
l.setYOffset(0f);
l.setXOffset(10f);
l.setYEntrySpace(0f);
l.setTextSize(8f);
- XAxis xAxis = mChart.getXAxis();
- xAxis.setTypeface(mTfLight);
+ XAxis xAxis = chart.getXAxis();
+ xAxis.setTypeface(tfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@@ -98,14 +106,88 @@ public String getFormattedValue(float value, AxisBase axis) {
}
});
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setValueFormatter(new LargeValueFormatter());
leftAxis.setDrawGridLines(false);
leftAxis.setSpaceTop(35f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- mChart.getAxisRight().setEnabled(false);
+ chart.getAxisRight().setEnabled(false);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ float groupSpace = 0.08f;
+ float barSpace = 0.03f; // x4 DataSet
+ float barWidth = 0.2f; // x4 DataSet
+ // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
+
+ int groupCount = seekBarX.getProgress() + 1;
+ int startYear = 1980;
+ int endYear = startYear + groupCount;
+
+ tvX.setText(String.format(Locale.ENGLISH, "%d-%d", startYear, endYear));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ ArrayList values1 = new ArrayList<>();
+ ArrayList values2 = new ArrayList<>();
+ ArrayList values3 = new ArrayList<>();
+ ArrayList values4 = new ArrayList<>();
+
+ float randomMultiplier = seekBarY.getProgress() * 100000f;
+
+ for (int i = startYear; i < endYear; i++) {
+ values1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ values2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ values3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ values4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
+ }
+
+ BarDataSet set1, set2, set3, set4;
+
+ if (chart.getData() != null && chart.getData().getDataSetCount() > 0) {
+
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set2 = (BarDataSet) chart.getData().getDataSetByIndex(1);
+ set3 = (BarDataSet) chart.getData().getDataSetByIndex(2);
+ set4 = (BarDataSet) chart.getData().getDataSetByIndex(3);
+ set1.setValues(values1);
+ set2.setValues(values2);
+ set3.setValues(values3);
+ set4.setValues(values4);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+
+ } else {
+ // create 4 DataSets
+ set1 = new BarDataSet(values1, "Company A");
+ set1.setColor(Color.rgb(104, 241, 175));
+ set2 = new BarDataSet(values2, "Company B");
+ set2.setColor(Color.rgb(164, 228, 251));
+ set3 = new BarDataSet(values3, "Company C");
+ set3.setColor(Color.rgb(242, 247, 158));
+ set4 = new BarDataSet(values4, "Company D");
+ set4.setColor(Color.rgb(255, 102, 0));
+
+ BarData data = new BarData(set1, set2, set3, set4);
+ data.setValueFormatter(new LargeValueFormatter());
+ data.setValueTypeface(tfLight);
+
+ chart.setData(data);
+ }
+
+ // specify the width each bar should have
+ chart.getBarData().setBarWidth(barWidth);
+
+ // restrict the x-axis range
+ chart.getXAxis().setAxisMinimum(startYear);
+
+ // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
+ chart.getXAxis().setAxisMaximum(startYear + chart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
+ chart.groupBars(startYear, groupSpace, barSpace);
+ chart.invalidate();
}
@Override
@@ -118,56 +200,65 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
}
@@ -175,88 +266,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- float groupSpace = 0.08f;
- float barSpace = 0.03f; // x4 DataSet
- float barWidth = 0.2f; // x4 DataSet
- // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
-
- int groupCount = mSeekBarX.getProgress() + 1;
- int startYear = 1980;
- int endYear = startYear + groupCount;
-
- tvX.setText(startYear + "-" + endYear);
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- ArrayList yVals1 = new ArrayList();
- ArrayList yVals2 = new ArrayList();
- ArrayList yVals3 = new ArrayList();
- ArrayList yVals4 = new ArrayList();
-
- float randomMultiplier = mSeekBarY.getProgress() * 100000f;
-
- for (int i = startYear; i < endYear; i++) {
- yVals1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- yVals2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- yVals3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- yVals4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
- }
-
- BarDataSet set1, set2, set3, set4;
-
- if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
-
- set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
- set2 = (BarDataSet) mChart.getData().getDataSetByIndex(1);
- set3 = (BarDataSet) mChart.getData().getDataSetByIndex(2);
- set4 = (BarDataSet) mChart.getData().getDataSetByIndex(3);
- set1.setValues(yVals1);
- set2.setValues(yVals2);
- set3.setValues(yVals3);
- set4.setValues(yVals4);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
-
- } else {
- // create 4 DataSets
- set1 = new BarDataSet(yVals1, "Company A");
- set1.setColor(Color.rgb(104, 241, 175));
- set2 = new BarDataSet(yVals2, "Company B");
- set2.setColor(Color.rgb(164, 228, 251));
- set3 = new BarDataSet(yVals3, "Company C");
- set3.setColor(Color.rgb(242, 247, 158));
- set4 = new BarDataSet(yVals4, "Company D");
- set4.setColor(Color.rgb(255, 102, 0));
-
- BarData data = new BarData(set1, set2, set3, set4);
- data.setValueFormatter(new LargeValueFormatter());
- data.setValueTypeface(mTfLight);
-
- mChart.setData(data);
- }
-
- // specify the width each bar should have
- mChart.getBarData().setBarWidth(barWidth);
-
- // restrict the x-axis range
- mChart.getXAxis().setAxisMinimum(startYear);
-
- // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
- mChart.getXAxis().setAxisMaximum(startYear + mChart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
- mChart.groupBars(startYear, groupSpace, barSpace);
- mChart.invalidate();
+ public void saveToGallery() {
+ saveToGallery(chart, "BarChartActivityMultiDataset");
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onValueSelected(Entry e, Highlight h) {
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
index 82b039909f..d7c16df440 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java
@@ -1,20 +1,23 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
@@ -29,11 +32,11 @@
public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeListener {
- protected BarChart mChart;
- private SeekBar mSeekBarX;
+ private BarChart chart;
+ private SeekBar seekBarX;
private TextView tvX;
- private List mSinusData;
+ private List data;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -42,57 +45,59 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_sinus);
- mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
+ setTitle("BarChartActivitySinus");
+
+ data = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
tvX = findViewById(R.id.tvValueCount);
- mSeekBarX = findViewById(R.id.seekbarValues);
+ seekBarX = findViewById(R.id.seekbarValues);
- mChart = findViewById(R.id.chart1);
+ chart = findViewById(R.id.chart1);
- mChart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart.setDrawBarShadow(false);
+ chart.setDrawValueAboveBar(true);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
- // mChart.setDrawBarShadow(true);
+ // chart.setDrawBarShadow(true);
- // mChart.setDrawXLabels(false);
+ // chart.setDrawXLabels(false);
- mChart.setDrawGridBackground(false);
- // mChart.setDrawYLabels(false);
+ chart.setDrawGridBackground(false);
+ // chart.setDrawYLabels(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(6, false);
leftAxis.setAxisMinimum(-2.5f);
leftAxis.setAxisMaximum(2.5f);
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(0.1f);
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
- rightAxis.setTypeface(mTfLight);
+ rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(6, false);
rightAxis.setAxisMinimum(-2.5f);
rightAxis.setAxisMaximum(2.5f);
rightAxis.setGranularity(0.1f);
- mSeekBarX.setOnSeekBarChangeListener(this);
- mSeekBarX.setProgress(150); // set data
+ seekBarX.setOnSeekBarChangeListener(this);
+ seekBarX.setProgress(150); // set data
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -102,7 +107,37 @@ protected void onCreate(Bundle savedInstanceState) {
l.setTextSize(11f);
l.setXEntrySpace(4f);
- mChart.animateXY(2000, 2000);
+ chart.animateXY(1500, 1500);
+ }
+
+ private void setData(int count) {
+
+ ArrayList entries = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ entries.add(data.get(i));
+ }
+
+ BarDataSet set;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set.setValues(entries);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set = new BarDataSet(entries, "Sinus Function");
+ set.setColor(Color.rgb(240, 120, 124));
+ }
+
+ BarData data = new BarData(set);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setDrawValues(false);
+ data.setBarWidth(0.8f);
+
+ chart.setData(data);
}
@Override
@@ -115,61 +150,66 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(1500);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(1500);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(2000, 2000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -179,51 +219,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
- setData(mSeekBarX.getProgress());
- mChart.invalidate();
+ setData(seekBarX.getProgress());
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ public void saveToGallery() {
+ saveToGallery(chart, "BarChartActivitySinus");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count) {
-
- ArrayList entries = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- entries.add(mSinusData.get(i));
- }
-
- BarDataSet set;
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set = (BarDataSet) mChart.getData().getDataSetByIndex(0);
- set.setValues(entries);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set = new BarDataSet(entries, "Sinus Function");
- set.setColor(Color.rgb(240, 120, 124));
- }
-
- BarData data = new BarData(set);
- data.setValueTextSize(10f);
- data.setValueTypeface(mTfLight);
- data.setDrawValues(false);
- data.setBarWidth(0.8f);
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
- mChart.setData(data);
- }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
index 7d6bd44896..ce73317860 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
@@ -1,9 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
-import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.BarChart;
@@ -26,8 +29,7 @@
public class BarChartPositiveNegative extends DemoBase {
- protected BarChart mChart;
- private Typeface mTf;
+ private BarChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -36,27 +38,28 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_noseekbar);
- mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setExtraTopOffset(-30f);
- mChart.setExtraBottomOffset(10f);
- mChart.setExtraLeftOffset(70f);
- mChart.setExtraRightOffset(70f);
+ setTitle("BarChartPositiveNegative");
- mChart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setExtraTopOffset(-30f);
+ chart.setExtraBottomOffset(10f);
+ chart.setExtraLeftOffset(70f);
+ chart.setExtraRightOffset(70f);
- mChart.getDescription().setEnabled(false);
+ chart.setDrawBarShadow(false);
+ chart.setDrawValueAboveBar(true);
+
+ chart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setTypeface(mTf);
+ xAxis.setTypeface(tfRegular);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextColor(Color.LTGRAY);
@@ -65,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f);
- YAxis left = mChart.getAxisLeft();
+ YAxis left = chart.getAxisLeft();
left.setDrawLabels(false);
left.setSpaceTop(25f);
left.setSpaceBottom(25f);
@@ -74,8 +77,8 @@ protected void onCreate(Bundle savedInstanceState) {
left.setDrawZeroLine(true); // draw a zero line
left.setZeroLineColor(Color.GRAY);
left.setZeroLineWidth(0.7f);
- mChart.getAxisRight().setEnabled(false);
- mChart.getLegend().setEnabled(false);
+ chart.getAxisRight().setEnabled(false);
+ chart.getLegend().setEnabled(false);
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
final List data = new ArrayList<>();
@@ -97,8 +100,8 @@ public String getFormattedValue(float value, AxisBase axis) {
private void setData(List dataList) {
- ArrayList values = new ArrayList();
- List colors = new ArrayList();
+ ArrayList values = new ArrayList<>();
+ List colors = new ArrayList<>();
int green = Color.rgb(110, 190, 102);
int red = Color.rgb(211, 74, 88);
@@ -118,12 +121,12 @@ private void setData(List dataList) {
BarDataSet set;
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set = (BarDataSet)mChart.getData().getDataSetByIndex(0);
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set = (BarDataSet) chart.getData().getDataSetByIndex(0);
set.setValues(values);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
} else {
set = new BarDataSet(values, "Values");
set.setColors(colors);
@@ -131,12 +134,12 @@ private void setData(List dataList) {
BarData data = new BarData(set);
data.setValueTextSize(13f);
- data.setValueTypeface(mTf);
+ data.setValueTypeface(tfRegular);
data.setValueFormatter(new ValueFormatter());
data.setBarWidth(0.8f);
- mChart.setData(data);
- mChart.invalidate();
+ chart.setData(data);
+ chart.invalidate();
}
}
@@ -145,11 +148,11 @@ private void setData(List dataList) {
*/
private class Data {
- public String xAxisValue;
- public float yValue;
- public float xValue;
+ String xAxisValue;
+ float yValue;
+ 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;
@@ -161,7 +164,7 @@ private class ValueFormatter implements IValueFormatter
private DecimalFormat mFormat;
- public ValueFormatter() {
+ ValueFormatter() {
mFormat = new DecimalFormat("######.0");
}
@@ -170,4 +173,28 @@ public String getFormattedValue(float value, Entry entry, int dataSetIndex, View
return mFormat.format(value);
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
index bc1750381e..098c8f242b 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -13,7 +18,6 @@
import com.github.mikephil.charting.charts.BubbleChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BubbleData;
@@ -33,10 +37,10 @@
public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private BubbleChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private BubbleChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -44,52 +48,106 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_bubblechart);
+ setTitle("BubbleChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.getDescription().setEnabled(false);
+ chart = findViewById(R.id.chart1);
+ chart.getDescription().setEnabled(false);
- mChart.setOnChartValueSelectedListener(this);
+ chart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
- mChart.setMaxVisibleValueCount(200);
- mChart.setPinchZoom(true);
+ chart.setMaxVisibleValueCount(200);
+ chart.setPinchZoom(true);
- mSeekBarX.setProgress(10);
- mSeekBarY.setProgress(50);
+ seekBarX.setProgress(10);
+ seekBarY.setProgress(50);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
- YAxis yl = mChart.getAxisLeft();
- yl.setTypeface(mTfLight);
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfLight);
yl.setSpaceTop(30f);
yl.setSpaceBottom(30f);
yl.setDrawZeroLine(false);
-
- mChart.getAxisRight().setEnabled(false);
- XAxis xl = mChart.getXAxis();
+ chart.getAxisRight().setEnabled(false);
+
+ XAxis xl = chart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
- xl.setTypeface(mTfLight);
+ xl.setTypeface(tfLight);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ int count = seekBarX.getProgress();
+ int range = seekBarY.getProgress();
+
+ tvX.setText(String.valueOf(count));
+ tvY.setText(String.valueOf(range));
+
+ ArrayList values1 = new ArrayList<>();
+ ArrayList values2 = new ArrayList<>();
+ ArrayList values3 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ values1.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
+ values2.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
+ values3.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range)));
+ }
+
+ // create a dataset and give it a type
+ BubbleDataSet set1 = new BubbleDataSet(values1, "DS 1");
+ set1.setDrawIcons(false);
+ set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
+ set1.setDrawValues(true);
+
+ BubbleDataSet set2 = new BubbleDataSet(values2, "DS 2");
+ set2.setDrawIcons(false);
+ set2.setIconsOffset(new MPPointF(0, 15));
+ set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
+ set2.setDrawValues(true);
+
+ BubbleDataSet set3 = new BubbleDataSet(values3, "DS 3");
+ set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
+ set3.setDrawValues(true);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1); // add the data sets
+ dataSets.add(set2);
+ dataSets.add(set3);
+
+ // create a data object with the data sets
+ BubbleData data = new BubbleData(dataSets);
+ data.setDrawValues(false);
+ data.setValueTypeface(tfLight);
+ data.setValueTextSize(8f);
+ data.setValueTextColor(Color.WHITE);
+ data.setHighlightCircleWidth(1.5f);
+
+ chart.setData(data);
+ chart.invalidate();
}
@Override
@@ -102,56 +160,65 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
}
@@ -159,70 +226,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- int count = mSeekBarX.getProgress();
- int range = mSeekBarY.getProgress();
-
- tvX.setText("" + count);
- tvY.setText("" + range);
-
- ArrayList yVals1 = new ArrayList();
- ArrayList yVals2 = new ArrayList();
- ArrayList yVals3 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- float size = (float) (Math.random() * range);
-
- yVals1.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
- }
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- float size = (float) (Math.random() * range);
-
- yVals2.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
- }
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- float size = (float) (Math.random() * range);
-
- yVals3.add(new BubbleEntry(i, val, size));
- }
-
- // create a dataset and give it a type
- BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
- set1.setDrawIcons(false);
- set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
- set1.setDrawValues(true);
-
- BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
- set2.setDrawIcons(false);
- set2.setIconsOffset(new MPPointF(0, 15));
- set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
- set2.setDrawValues(true);
-
- BubbleDataSet set3 = new BubbleDataSet(yVals3, "DS 3");
- set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
- set3.setDrawValues(true);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1); // add the datasets
- dataSets.add(set2);
- dataSets.add(set3);
-
- // create a data object with the datasets
- BubbleData data = new BubbleData(dataSets);
- data.setDrawValues(false);
- data.setValueTypeface(mTfLight);
- data.setValueTextSize(8f);
- data.setValueTextColor(Color.WHITE);
- data.setHighlightCircleWidth(1.5f);
-
- mChart.setData(data);
- mChart.invalidate();
+ public void saveToGallery() {
+ saveToGallery(chart, "BubbleChartActivity");
}
@Override
@@ -233,20 +238,11 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- // TODO Auto-generated method stub
-
- }
+ public void onNothingSelected() {}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
index 54eb768a7b..b0b29dfbe4 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java
@@ -1,16 +1,20 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Paint;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.components.XAxis;
@@ -28,8 +32,8 @@
public class CandleStickChartActivity extends DemoBase implements OnSeekBarChangeListener {
- private CandleStickChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private CandleStickChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -39,48 +43,103 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_candlechart);
+ setTitle("CandleStickChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
// leftAxis.setEnabled(false);
leftAxis.setLabelCount(7, false);
leftAxis.setDrawGridLines(false);
leftAxis.setDrawAxisLine(false);
-
- YAxis rightAxis = mChart.getAxisRight();
+
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// rightAxis.setStartAtZero(false);
// setting data
- mSeekBarX.setProgress(40);
- mSeekBarY.setProgress(100);
-
- mChart.getLegend().setEnabled(false);
+ seekBarX.setProgress(40);
+ seekBarY.setProgress(100);
+
+ chart.getLegend().setEnabled(false);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ progress = (seekBarX.getProgress());
+
+ tvX.setText(String.valueOf(progress));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ chart.resetTracking();
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < progress; i++) {
+ float multi = (seekBarY.getProgress() + 1);
+ float val = (float) (Math.random() * 40) + multi;
+
+ float high = (float) (Math.random() * 9) + 8f;
+ float low = (float) (Math.random() * 9) + 8f;
+
+ float open = (float) (Math.random() * 6) + 1f;
+ float close = (float) (Math.random() * 6) + 1f;
+
+ boolean even = i % 2 == 0;
+
+ values.add(new CandleEntry(
+ i, val + high,
+ val - low,
+ even ? val + open : val - open,
+ even ? val - close : val + close,
+ getResources().getDrawable(R.drawable.star)
+ ));
+ }
+
+ CandleDataSet set1 = new CandleDataSet(values, "Data Set");
+
+ set1.setDrawIcons(false);
+ set1.setAxisDependency(AxisDependency.LEFT);
+// set1.setColor(Color.rgb(80, 80, 80));
+ set1.setShadowColor(Color.DKGRAY);
+ set1.setShadowWidth(0.7f);
+ set1.setDecreasingColor(Color.RED);
+ set1.setDecreasingPaintStyle(Paint.Style.FILL);
+ set1.setIncreasingColor(Color.rgb(122, 242, 84));
+ set1.setIncreasingPaintStyle(Paint.Style.STROKE);
+ set1.setNeutralColor(Color.BLUE);
+ //set1.setHighlightLineWidth(1f);
+
+ CandleData data = new CandleData(set1);
+
+ chart.setData(data);
+ chart.invalidate();
}
@Override
@@ -93,69 +152,73 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawIcons(!set.isDrawIconsEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleMakeShadowSameColorAsCandle: {
- for (ICandleDataSet set : mChart.getData().getDataSets()) {
- //TODO: set.setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
+ for (ICandleDataSet set : chart.getData().getDataSets()) {
+ ((CandleDataSet) set).setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -163,67 +226,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- int prog = (mSeekBarX.getProgress() + 1);
-
- tvX.setText("" + prog);
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- mChart.resetTracking();
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < prog; i++) {
- float mult = (mSeekBarY.getProgress() + 1);
- float val = (float) (Math.random() * 40) + mult;
-
- float high = (float) (Math.random() * 9) + 8f;
- float low = (float) (Math.random() * 9) + 8f;
-
- float open = (float) (Math.random() * 6) + 1f;
- float close = (float) (Math.random() * 6) + 1f;
-
- boolean even = i % 2 == 0;
-
- yVals1.add(new CandleEntry(
- i, val + high,
- val - low,
- even ? val + open : val - open,
- even ? val - close : val + close,
- getResources().getDrawable(R.drawable.star)
- ));
- }
-
- CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set");
-
- set1.setDrawIcons(false);
- set1.setAxisDependency(AxisDependency.LEFT);
-// set1.setColor(Color.rgb(80, 80, 80));
- set1.setShadowColor(Color.DKGRAY);
- set1.setShadowWidth(0.7f);
- set1.setDecreasingColor(Color.RED);
- set1.setDecreasingPaintStyle(Paint.Style.FILL);
- set1.setIncreasingColor(Color.rgb(122, 242, 84));
- set1.setIncreasingPaintStyle(Paint.Style.STROKE);
- set1.setNeutralColor(Color.BLUE);
- //set1.setHighlightLineWidth(1f);
-
- CandleData data = new CandleData(set1);
-
- mChart.setData(data);
- mChart.invalidate();
+ public void saveToGallery() {
+ saveToGallery(chart, "CandleStickChartActivity");
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
index e4d8fb2e3b..7526dc1d59 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
@@ -1,7 +1,9 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@@ -38,8 +40,8 @@
public class CombinedChartActivity extends DemoBase {
- private CombinedChart mChart;
- private final int itemcount = 12;
+ private CombinedChart chart;
+ private final int count = 12;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -48,41 +50,43 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_combined);
- mChart = findViewById(R.id.chart1);
- mChart.getDescription().setEnabled(false);
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setDrawGridBackground(false);
- mChart.setDrawBarShadow(false);
- mChart.setHighlightFullBarEnabled(false);
+ setTitle("CombinedChartActivity");
+
+ chart = findViewById(R.id.chart1);
+ chart.getDescription().setEnabled(false);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setDrawGridBackground(false);
+ chart.setDrawBarShadow(false);
+ chart.setHighlightFullBarEnabled(false);
// draw bars behind lines
- mChart.setDrawOrder(new DrawOrder[]{
+ chart.setDrawOrder(new DrawOrder[]{
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
});
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
- return mMonths[(int) value % mMonths.length];
+ return months[(int) value % months.length];
}
});
@@ -93,21 +97,21 @@ public String getFormattedValue(float value, AxisBase axis) {
data.setData(generateBubbleData());
data.setData(generateScatterData());
data.setData(generateCandleData());
- data.setValueTypeface(mTfLight);
+ data.setValueTypeface(tfLight);
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
- mChart.setData(data);
- mChart.invalidate();
+ chart.setData(data);
+ chart.invalidate();
}
private LineData generateLineData() {
LineData d = new LineData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (int index = 0; index < itemcount; index++)
+ for (int index = 0; index < count; index++)
entries.add(new Entry(index + 0.5f, getRandom(15, 5)));
LineDataSet set = new LineDataSet(entries, "Line DataSet");
@@ -129,10 +133,10 @@ private LineData generateLineData() {
private BarData generateBarData() {
- ArrayList entries1 = new ArrayList();
- ArrayList entries2 = new ArrayList();
+ ArrayList entries1 = new ArrayList<>();
+ ArrayList entries2 = new ArrayList<>();
- for (int index = 0; index < itemcount; index++) {
+ for (int index = 0; index < count; index++) {
entries1.add(new BarEntry(0, getRandom(25, 25)));
// stacked
@@ -147,7 +151,7 @@ private BarData generateBarData() {
BarDataSet set2 = new BarDataSet(entries2, "");
set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
- set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
+ set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255));
set2.setValueTextColor(Color.rgb(61, 165, 255));
set2.setValueTextSize(10f);
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
@@ -166,13 +170,13 @@ private BarData generateBarData() {
return d;
}
- protected ScatterData generateScatterData() {
+ ScatterData generateScatterData() {
ScatterData d = new ScatterData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (float index = 0; index < itemcount; index += 0.5f)
+ for (float index = 0; index < count; index += 0.5f)
entries.add(new Entry(index + 0.25f, getRandom(10, 55)));
ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet");
@@ -185,13 +189,13 @@ protected ScatterData generateScatterData() {
return d;
}
- protected CandleData generateCandleData() {
+ CandleData generateCandleData() {
CandleData d = new CandleData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (int index = 0; index < itemcount; index += 2)
+ for (int index = 0; index < count; index += 2)
entries.add(new CandleEntry(index + 1f, 90, 70, 85, 75f));
CandleDataSet set = new CandleDataSet(entries, "Candle DataSet");
@@ -205,13 +209,13 @@ protected CandleData generateCandleData() {
return d;
}
- protected BubbleData generateBubbleData() {
+ BubbleData generateBubbleData() {
BubbleData bd = new BubbleData();
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
- for (int index = 0; index < itemcount; index++) {
+ for (int index = 0; index < count; index++) {
float y = getRandom(10, 105);
float size = getRandom(100, 105);
entries.add(new BubbleEntry(index + 0.5f, y, size));
@@ -237,34 +241,42 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleLineValues: {
- for (IDataSet set : mChart.getData().getDataSets()) {
+ for (IDataSet set : chart.getData().getDataSets()) {
if (set instanceof LineDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleBarValues: {
- for (IDataSet set : mChart.getData().getDataSets()) {
+ for (IDataSet set : chart.getData().getDataSets()) {
if (set instanceof BarDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionRemoveDataSet: {
-
- int rnd = (int) getRandom(mChart.getData().getDataSetCount(), 0);
- mChart.getData().removeDataSet(mChart.getData().getDataSetByIndex(rnd));
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ int rnd = (int) getRandom(chart.getData().getDataSetCount(), 0);
+ chart.getData().removeDataSet(chart.getData().getDataSetByIndex(rnd));
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
break;
}
}
return true;
}
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
index 4a278c398e..25134f71fd 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java
@@ -1,15 +1,19 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
@@ -28,8 +32,8 @@
public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -39,60 +43,115 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("CubicLineChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
-
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
-
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
- mChart = findViewById(R.id.chart1);
- mChart.setViewPortOffsets(0, 0, 0, 0);
- mChart.setBackgroundColor(Color.rgb(104, 241, 175));
+ chart = findViewById(R.id.chart1);
+ chart.setViewPortOffsets(0, 0, 0, 0);
+ chart.setBackgroundColor(Color.rgb(104, 241, 175));
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- mChart.setDrawGridBackground(false);
- mChart.setMaxHighlightDistance(300);
-
- XAxis x = mChart.getXAxis();
+ chart.setDrawGridBackground(false);
+ chart.setMaxHighlightDistance(300);
+
+ XAxis x = chart.getXAxis();
x.setEnabled(false);
-
- YAxis y = mChart.getAxisLeft();
- y.setTypeface(mTfLight);
+
+ YAxis y = chart.getAxisLeft();
+ y.setTypeface(tfLight);
y.setLabelCount(6, false);
y.setTextColor(Color.WHITE);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
-
- mChart.getAxisRight().setEnabled(false);
+
+ chart.getAxisRight().setEnabled(false);
// add data
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
+
+ // lower max, as cubic runs significantly slower than linear
+ seekBarX.setMax(700);
+
+ seekBarX.setProgress(45);
+ seekBarY.setProgress(100);
setData(45, 100);
-
- mChart.getLegend().setEnabled(false);
-
- mChart.animateXY(2000, 2000);
- // dont forget to refresh the drawing
- mChart.invalidate();
+ chart.getLegend().setEnabled(false);
+
+ chart.animateXY(2000, 2000);
+
+ // don't forget to refresh the drawing
+ chart.invalidate();
+ }
+
+ private void setData(int count, float range) {
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * (range + 1)) + 20;
+ values.add(new Entry(i, val));
+ }
+
+ LineDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ // create a dataset and give it a type
+ set1 = new LineDataSet(values, "DataSet 1");
+
+ set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
+ set1.setCubicIntensity(0.2f);
+ set1.setDrawFilled(true);
+ set1.setDrawCircles(false);
+ set1.setLineWidth(1.8f);
+ set1.setCircleRadius(4f);
+ set1.setCircleColor(Color.WHITE);
+ set1.setHighLightColor(Color.rgb(244, 117, 117));
+ set1.setColor(Color.WHITE);
+ set1.setFillColor(Color.WHITE);
+ set1.setFillAlpha(100);
+ set1.setDrawHorizontalHighlightIndicator(false);
+ set1.setFillFormatter(new IFillFormatter() {
+ @Override
+ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
+ return chart.getAxisLeft().getAxisMinimum();
+ }
+ });
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1);
+ data.setValueTypeface(tfLight);
+ data.setValueTextSize(9f);
+ data.setDrawValues(false);
+
+ // set data
+ chart.setData(data);
+ }
}
@Override
@@ -105,23 +164,29 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet set : mChart.getData().getDataSets())
+ for (IDataSet set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -133,11 +198,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -148,11 +213,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -162,11 +227,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -176,11 +241,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHorizontalCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -190,44 +255,41 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -237,78 +299,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ public void saveToGallery() {
+ saveToGallery(chart, "CubicLineChartActivity");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList yVals = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = (range + 1);
- float val = (float) (Math.random() * mult) + 20;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals.add(new Entry(i, val));
- }
-
- LineDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- // create a dataset and give it a type
- set1 = new LineDataSet(yVals, "DataSet 1");
-
- set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
- set1.setCubicIntensity(0.2f);
- //set1.setDrawFilled(true);
- set1.setDrawCircles(false);
- set1.setLineWidth(1.8f);
- set1.setCircleRadius(4f);
- set1.setCircleColor(Color.WHITE);
- set1.setHighLightColor(Color.rgb(244, 117, 117));
- set1.setColor(Color.WHITE);
- set1.setFillColor(Color.WHITE);
- set1.setFillAlpha(100);
- set1.setDrawHorizontalHighlightIndicator(false);
- set1.setFillFormatter(new IFillFormatter() {
- @Override
- public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
- return -10;
- }
- });
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- // create a data object with the datasets
- LineData data = new LineData(set1);
- data.setValueTypeface(mTfLight);
- data.setValueTextSize(9f);
- data.setDrawValues(false);
-
- // set data
- mChart.setData(data);
- }
- }
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
index d3551068c1..348b9ad0fc 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java
@@ -1,8 +1,10 @@
-
+// TODO: Finish and add to main activity list
package com.xxmassdeveloper.mpchartexample;
-import android.graphics.Typeface;
+import android.Manifest;
+import android.content.pm.PackageManager;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -28,13 +30,13 @@
/**
* This Activity demonstrates drawing into the Chart with the finger. Both line,
* bar and scatter charts can be used for drawing.
- *
+ *
* @author Philipp Jahoda
*/
public class DrawChartActivity extends DemoBase implements OnChartValueSelectedListener,
OnDrawListener {
- private LineChart mChart;
+ private LineChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -43,49 +45,49 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_draw_chart);
- mChart = findViewById(R.id.chart1);
+ setTitle("DrawChartActivity");
+
+ chart = findViewById(R.id.chart1);
// listener for selecting and drawing
- mChart.setOnChartValueSelectedListener(this);
- mChart.setOnDrawListener(this);
+ chart.setOnChartValueSelectedListener(this);
+ chart.setOnDrawListener(this);
- // if disabled, drawn datasets with the finger will not be automatically
+ // if disabled, drawn data sets with the finger will not be automatically
// finished
- // mChart.setAutoFinish(true);
- mChart.setDrawGridBackground(false);
+ // chart.setAutoFinish(true);
+ chart.setDrawGridBackground(false);
// add dummy-data to the chart
initWithDummyData();
- Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
-
- XAxis xl = mChart.getXAxis();
- xl.setTypeface(tf);
+ XAxis xl = chart.getXAxis();
+ xl.setTypeface(tfRegular);
xl.setAvoidFirstLastClipping(true);
- YAxis yl = mChart.getAxisLeft();
- yl.setTypeface(tf);
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfRegular);
- mChart.getLegend().setEnabled(false);
+ chart.getLegend().setEnabled(false);
- // mChart.setYRange(-40f, 40f, true);
+ // chart.setYRange(-40f, 40f, true);
// call this to reset the changed y-range
- // mChart.resetYRange(true);
+ // chart.resetYRange(true);
}
private void initWithDummyData() {
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
// create a dataset and give it a type (0)
- LineDataSet set1 = new LineDataSet(yVals, "DataSet");
+ LineDataSet set1 = new LineDataSet(values, "DataSet");
set1.setLineWidth(3f);
set1.setCircleRadius(5f);
- // create a data object with the datasets
+ // create a data object with the data sets
LineData data = new LineData(set1);
- mChart.setData(data);
+ chart.setData(data);
}
@Override
@@ -99,7 +101,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -108,39 +110,47 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
return true;
}
+ @Override
+ public void saveToGallery() {
+ saveToGallery(chart, "DrawChartActivity");
+ }
+
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.i("VAL SELECTED",
@@ -164,7 +174,7 @@ public void onDrawFinished(DataSet> dataSet) {
Log.i(Chart.LOG_TAG, "DataSet drawn. " + dataSet.toSimpleString());
// prepare the legend again
- mChart.getLegendRenderer().computeLegend(mChart.getData());
+ chart.getLegendRenderer().computeLegend(chart.getData());
}
@Override
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
index f8f64c374f..501090af62 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
@@ -23,7 +28,7 @@
public class DynamicalAddingActivity extends DemoBase implements OnChartValueSelectedListener {
- private LineChart mChart;
+ private LineChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -32,24 +37,30 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
- mChart.getDescription().setEnabled(false);
+ setTitle("DynamicalAddingActivity");
- // add an empty data object
- mChart.setData(new LineData());
-// mChart.getXAxis().setDrawLabels(false);
-// mChart.getXAxis().setDrawGridLines(false);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ chart.setDrawGridBackground(false);
+ chart.getDescription().setEnabled(false);
+ chart.setNoDataText("No chart data available. Use the menu to add entries and data sets!");
- mChart.invalidate();
+// chart.getXAxis().setDrawLabels(false);
+// chart.getXAxis().setDrawGridLines(false);
+
+ chart.invalidate();
}
- int[] mColors = ColorTemplate.VORDIPLOM_COLORS;
+ private final int[] colors = ColorTemplate.VORDIPLOM_COLORS;
private void addEntry() {
- LineData data = mChart.getData();
+ LineData data = chart.getData();
+
+ if (data == null) {
+ data = new LineData();
+ chart.setData(data);
+ }
ILineDataSet set = data.getDataSetByIndex(0);
// set.addEntry(...); // can be called as well
@@ -61,25 +72,26 @@ private void addEntry() {
// choose a random dataSet
int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
- float yValue = (float) (Math.random() * 10) + 50f;
+ ILineDataSet randomSet = data.getDataSetByIndex(randomDataSetIndex);
+ float value = (float) (Math.random() * 50) + 50f * (randomDataSetIndex + 1);
- data.addEntry(new Entry(data.getDataSetByIndex(randomDataSetIndex).getEntryCount(), yValue), randomDataSetIndex);
+ data.addEntry(new Entry(randomSet.getEntryCount(), value), randomDataSetIndex);
data.notifyDataChanged();
// let the chart know it's data has changed
- mChart.notifyDataSetChanged();
+ chart.notifyDataSetChanged();
- mChart.setVisibleXRangeMaximum(6);
- //mChart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
-//
+ chart.setVisibleXRangeMaximum(6);
+ //chart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
+//
// // this automatically refreshes the chart (calls invalidate())
- mChart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
+ chart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
}
private void removeLastEntry() {
- LineData data = mChart.getData();
+ LineData data = chart.getData();
if (data != null) {
@@ -93,31 +105,33 @@ private void removeLastEntry() {
// or remove by index
// mData.removeEntryByXValue(xIndex, dataSetIndex);
data.notifyDataChanged();
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
}
}
}
private void addDataSet() {
- LineData data = mChart.getData();
-
- if (data != null) {
+ LineData data = chart.getData();
+ if (data == null) {
+ chart.setData(new LineData());
+ } else {
int count = (data.getDataSetCount() + 1);
+ int amount = data.getDataSetByIndex(0).getEntryCount();
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
- for (int i = 0; i < data.getEntryCount(); i++) {
- yVals.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
+ for (int i = 0; i < amount; i++) {
+ values.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
}
- LineDataSet set = new LineDataSet(yVals, "DataSet " + count);
+ LineDataSet set = new LineDataSet(values, "DataSet " + count);
set.setLineWidth(2.5f);
set.setCircleRadius(4.5f);
- int color = mColors[count % mColors.length];
+ int color = colors[count % colors.length];
set.setColor(color);
set.setCircleColor(color);
@@ -127,33 +141,45 @@ private void addDataSet() {
data.addDataSet(set);
data.notifyDataChanged();
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
}
}
private void removeDataSet() {
- LineData data = mChart.getData();
+ LineData data = chart.getData();
if (data != null) {
data.removeDataSet(data.getDataSetByIndex(data.getDataSetCount() - 1));
- mChart.notifyDataSetChanged();
- mChart.invalidate();
+ chart.notifyDataSetChanged();
+ chart.invalidate();
}
}
+ private LineDataSet createSet() {
+
+ LineDataSet set = new LineDataSet(null, "DataSet 1");
+ set.setLineWidth(2.5f);
+ set.setCircleRadius(4.5f);
+ set.setColor(Color.rgb(240, 99, 99));
+ set.setCircleColor(Color.rgb(240, 99, 99));
+ set.setHighLightColor(Color.rgb(190, 190, 190));
+ set.setAxisDependency(AxisDependency.LEFT);
+ set.setValueTextSize(10f);
+
+ return set;
+ }
+
@Override
public void onValueSelected(Entry e, Highlight h) {
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
@Override
- public void onNothingSelected() {
-
- }
+ public void onNothingSelected() {}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -165,47 +191,52 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.actionAddEntry:
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java"));
+ startActivity(i);
+ break;
+ }
+ case R.id.actionAddEntry: {
addEntry();
Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionRemoveEntry:
+ }
+ case R.id.actionRemoveEntry: {
removeLastEntry();
Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionAddDataSet:
+ }
+ case R.id.actionAddDataSet: {
addDataSet();
Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionRemoveDataSet:
+ }
+ case R.id.actionRemoveDataSet: {
removeDataSet();
Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show();
break;
- case R.id.actionAddEmptyLineData:
- mChart.setData(new LineData());
- mChart.invalidate();
- Toast.makeText(this, "Empty data added!", Toast.LENGTH_SHORT).show();
- break;
- case R.id.actionClear:
- mChart.clear();
+ }
+ case R.id.actionClear: {
+ chart.clear();
Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show();
break;
+ }
+ case R.id.actionSave: {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
+ break;
+ }
}
return true;
}
- private LineDataSet createSet() {
-
- LineDataSet set = new LineDataSet(null, "DataSet 1");
- set.setLineWidth(2.5f);
- set.setCircleRadius(4.5f);
- set.setColor(Color.rgb(240, 99, 99));
- set.setCircleColor(Color.rgb(240, 99, 99));
- set.setHighLightColor(Color.rgb(190, 190, 190));
- set.setAxisDependency(AxisDependency.LEFT);
- set.setValueTextSize(10f);
-
- return set;
+ @Override
+ public void saveToGallery() {
+ saveToGallery(chart, "DynamicalAddingActivity");
}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
index 9109d5d29c..e821a04969 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java
@@ -1,8 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.LineChart;
@@ -19,10 +23,19 @@
import java.util.ArrayList;
+/**
+ * This works by inverting the background and desired "fill" color. First, we draw the fill color
+ * that we want between the lines as the actual background of the chart. Then, we fill the area
+ * above the highest line and the area under the lowest line with the desired background color.
+ *
+ * This method makes it look like we filled the area between the lines, but really we are filling
+ * the area OUTSIDE the lines!
+ */
+@SuppressWarnings("SameParameterValue")
public class FilledLineActivity extends DemoBase {
- private LineChart mChart;
- private int mFillColor = Color.argb(150, 51, 181, 229);
+ private LineChart chart;
+ private final int fillColor = Color.argb(150, 51, 181, 229);
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -31,73 +44,71 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setGridBackgroundColor(mFillColor);
- mChart.setDrawGridBackground(true);
+ setTitle("FilledLineActivity");
- mChart.setDrawBorders(true);
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setGridBackgroundColor(fillColor);
+ chart.setDrawGridBackground(true);
+
+ chart.setDrawBorders(true);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setEnabled(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setAxisMaximum(900f);
leftAxis.setAxisMinimum(-250f);
leftAxis.setDrawAxisLine(false);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(false);
- mChart.getAxisRight().setEnabled(false);
+ chart.getAxisRight().setEnabled(false);
// add data
setData(100, 60);
- mChart.invalidate();
+ chart.invalidate();
}
private void setData(int count, float range) {
- ArrayList yVals1 = new ArrayList();
+ ArrayList values1 = new ArrayList<>();
for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range) + 50;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals1.add(new Entry(i, val));
+ float val = (float) (Math.random() * range) + 50;
+ values1.add(new Entry(i, val));
}
- ArrayList yVals2 = new ArrayList();
+ ArrayList values2 = new ArrayList<>();
for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range) + 450;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals2.add(new Entry(i, val));
+ float val = (float) (Math.random() * range) + 450;
+ values2.add(new Entry(i, val));
}
LineDataSet set1, set2;
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
- set2 = (LineDataSet)mChart.getData().getDataSetByIndex(1);
- set1.setValues(yVals1);
- set2.setValues(yVals2);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set2 = (LineDataSet) chart.getData().getDataSetByIndex(1);
+ set1.setValues(values1);
+ set2.setValues(values2);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
- set1 = new LineDataSet(yVals1, "DataSet 1");
+ set1 = new LineDataSet(values1, "DataSet 1");
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setColor(Color.rgb(255, 241, 46));
@@ -112,12 +123,14 @@ private void setData(int count, float range) {
set1.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
- return mChart.getAxisLeft().getAxisMinimum();
+ // change the return value here to better understand the effect
+ // return 0;
+ return chart.getAxisLeft().getAxisMinimum();
}
});
// create a dataset and give it a type
- set2 = new LineDataSet(yVals2, "DataSet 2");
+ set2 = new LineDataSet(values2, "DataSet 2");
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
set2.setColor(Color.rgb(255, 241, 46));
set2.setDrawCircles(false);
@@ -131,20 +144,46 @@ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProv
set2.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
- return mChart.getAxisLeft().getAxisMaximum();
+ // change the return value here to better understand the effect
+ // return 600;
+ return chart.getAxisLeft().getAxisMaximum();
}
});
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1); // add the datasets
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1); // add the data sets
dataSets.add(set2);
- // create a data object with the datasets
+ // create a data object with the data sets
LineData data = new LineData(dataSets);
data.setDrawValues(false);
// set data
- mChart.setData(data);
+ chart.setData(data);
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
index 38a228b322..ed2adcc960 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java
@@ -1,22 +1,24 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
-import android.graphics.Point;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
-import android.view.Display;
+import android.util.DisplayMetrics;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
@@ -26,9 +28,10 @@
import java.util.ArrayList;
+@SuppressWarnings("SameParameterValue")
public class HalfPieChartActivity extends DemoBase {
- private PieChart mChart;
+ private PieChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -37,40 +40,42 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart_half);
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.WHITE);
+ setTitle("HalfPieChartActivity");
+
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.WHITE);
moveOffScreen();
- mChart.setUsePercentValues(true);
- mChart.getDescription().setEnabled(false);
+ chart.setUsePercentValues(true);
+ chart.getDescription().setEnabled(false);
- mChart.setCenterTextTypeface(mTfLight);
- mChart.setCenterText(generateCenterSpannableText());
+ chart.setCenterTextTypeface(tfLight);
+ chart.setCenterText(generateCenterSpannableText());
- mChart.setDrawHoleEnabled(true);
- mChart.setHoleColor(Color.WHITE);
+ chart.setDrawHoleEnabled(true);
+ chart.setHoleColor(Color.WHITE);
- mChart.setTransparentCircleColor(Color.WHITE);
- mChart.setTransparentCircleAlpha(110);
+ chart.setTransparentCircleColor(Color.WHITE);
+ chart.setTransparentCircleAlpha(110);
- mChart.setHoleRadius(58f);
- mChart.setTransparentCircleRadius(61f);
+ chart.setHoleRadius(58f);
+ chart.setTransparentCircleRadius(61f);
- mChart.setDrawCenterText(true);
+ chart.setDrawCenterText(true);
- mChart.setRotationEnabled(false);
- mChart.setHighlightPerTapEnabled(true);
+ chart.setRotationEnabled(false);
+ chart.setHighlightPerTapEnabled(true);
- mChart.setMaxAngle(180f); // HALF CHART
- mChart.setRotationAngle(180f);
- mChart.setCenterTextOffset(0, -20);
+ chart.setMaxAngle(180f); // HALF CHART
+ chart.setRotationAngle(180f);
+ chart.setCenterTextOffset(0, -20);
setData(4, 100);
- mChart.animateY(1400, Easing.EaseInOutQuad);
+ chart.animateY(1400, Easing.EaseInOutQuad);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -80,17 +85,17 @@ protected void onCreate(Bundle savedInstanceState) {
l.setYOffset(0f);
// entry label styling
- mChart.setEntryLabelColor(Color.WHITE);
- mChart.setEntryLabelTypeface(mTfRegular);
- mChart.setEntryLabelTextSize(12f);
+ chart.setEntryLabelColor(Color.WHITE);
+ chart.setEntryLabelTypeface(tfRegular);
+ chart.setEntryLabelTextSize(12f);
}
private void setData(int count, float range) {
- ArrayList values = new ArrayList();
+ ArrayList values = new ArrayList<>();
for (int i = 0; i < count; i++) {
- values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.length]));
+ values.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.length]));
}
PieDataSet dataSet = new PieDataSet(values, "Election Results");
@@ -104,10 +109,10 @@ private void setData(int count, float range) {
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.WHITE);
- data.setValueTypeface(mTfLight);
- mChart.setData(data);
+ data.setValueTypeface(tfLight);
+ chart.setData(data);
- mChart.invalidate();
+ chart.invalidate();
}
private SpannableString generateCenterSpannableText() {
@@ -124,14 +129,40 @@ private SpannableString generateCenterSpannableText() {
private void moveOffScreen() {
- Display display = getWindowManager().getDefaultDisplay();
- int height = display.getHeight(); // deprecated
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+
+ int height = displayMetrics.heightPixels;
int offset = (int)(height * 0.65); /* percent to move */
RelativeLayout.LayoutParams rlParams =
- (RelativeLayout.LayoutParams)mChart.getLayoutParams();
+ (RelativeLayout.LayoutParams) chart.getLayoutParams();
rlParams.setMargins(0, 0, 0, -offset);
- mChart.setLayoutParams(rlParams);
+ chart.setLayoutParams(rlParams);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
}
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
index 95e138aade..6e4e9275bf 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java
@@ -1,9 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
-import android.annotation.SuppressLint;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.RectF;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -11,11 +15,9 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.components.YAxis;
@@ -35,8 +37,8 @@
public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- protected HorizontalBarChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private HorizontalBarChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -46,67 +48,69 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_horizontalbarchart);
+ setTitle("HorizontalBarChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- // mChart.setHighlightEnabled(false);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ // chart.setHighlightEnabled(false);
- mChart.setDrawBarShadow(false);
+ chart.setDrawBarShadow(false);
- mChart.setDrawValueAboveBar(true);
+ chart.setDrawValueAboveBar(true);
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
- mChart.setMaxVisibleValueCount(60);
+ chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
- mChart.setPinchZoom(false);
+ chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
- // mChart.setDrawBarShadow(true);
+ // chart.setDrawBarShadow(true);
- mChart.setDrawGridBackground(false);
+ chart.setDrawGridBackground(false);
- XAxis xl = mChart.getXAxis();
+ XAxis xl = chart.getXAxis();
xl.setPosition(XAxisPosition.BOTTOM);
- xl.setTypeface(mTfLight);
+ xl.setTypeface(tfLight);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
xl.setGranularity(10f);
- YAxis yl = mChart.getAxisLeft();
- yl.setTypeface(mTfLight);
+ YAxis yl = chart.getAxisLeft();
+ yl.setTypeface(tfLight);
yl.setDrawAxisLine(true);
yl.setDrawGridLines(true);
yl.setAxisMinimum(0f); // this replaces setStartAtZero(true)
// yl.setInverted(true);
- YAxis yr = mChart.getAxisRight();
- yr.setTypeface(mTfLight);
+ YAxis yr = chart.getAxisRight();
+ yr.setTypeface(tfLight);
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
yr.setAxisMinimum(0f); // this replaces setStartAtZero(true)
// yr.setInverted(true);
setData(12, 50);
- mChart.setFitBars(true);
- mChart.animateY(2500);
+ chart.setFitBars(true);
+ chart.animateY(2500);
// setting data
- mSeekBarY.setProgress(50);
- mSeekBarX.setProgress(12);
+ seekBarY.setProgress(50);
+ seekBarX.setProgress(12);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
-
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
@@ -115,6 +119,42 @@ protected void onCreate(Bundle savedInstanceState) {
l.setXEntrySpace(4f);
}
+ private void setData(int count, float range) {
+
+ float barWidth = 9f;
+ float spaceForBar = 10f;
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range);
+ values.add(new BarEntry(i * spaceForBar, val,
+ getResources().getDrawable(R.drawable.star)));
+ }
+
+ BarDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ set1 = new BarDataSet(values, "DataSet 1");
+
+ set1.setDrawIcons(false);
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1);
+
+ BarData data = new BarData(dataSets);
+ data.setValueTextSize(10f);
+ data.setValueTypeface(tfLight);
+ data.setBarWidth(barWidth);
+ chart.setData(data);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
@@ -125,80 +165,80 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
-
- IBarDataSet set = (BarDataSet) iSet;
- set.setDrawValues(!set.isDrawValuesEnabled());
+ iSet.setDrawValues(!iSet.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
-
- IBarDataSet set = (BarDataSet) iSet;
- set.setDrawIcons(!set.isDrawIconsEnabled());
+ iSet.setDrawIcons(!iSet.isDrawIconsEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
- for (IBarDataSet set : mChart.getData().getDataSets())
+ for (IBarDataSet set : chart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
-
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -208,64 +248,27 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
- mChart.setFitBars(true);
- mChart.invalidate();
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
+ chart.setFitBars(true);
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ public void saveToGallery() {
+ saveToGallery(chart, "HorizontalBarChartActivity");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- float barWidth = 9f;
- float spaceForBar = 10f;
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float val = (float) (Math.random() * range);
- yVals1.add(new BarEntry(i * spaceForBar, val,
- getResources().getDrawable(R.drawable.star)));
- }
-
- BarDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(yVals1);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- set1 = new BarDataSet(yVals1, "DataSet 1");
-
- set1.setDrawIcons(false);
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1);
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
- BarData data = new BarData(dataSets);
- data.setValueTextSize(10f);
- data.setValueTypeface(mTfLight);
- data.setBarWidth(barWidth);
- mChart.setData(data);
- }
- }
+ private RectF mOnValueSelectedRectF = new RectF();
- protected RectF mOnValueSelectedRectF = new RectF();
- @SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
@@ -273,9 +276,9 @@ public void onValueSelected(Entry e, Highlight h) {
return;
RectF bounds = mOnValueSelectedRectF;
- mChart.getBarBounds((BarEntry) e, bounds);
+ chart.getBarBounds((BarEntry) e, bounds);
- MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
+ MPPointF position = chart.getPosition(e, chart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency());
Log.i("bounds", bounds.toString());
@@ -285,6 +288,5 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- };
+ public void onNothingSelected() {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
index 4ad4e691ef..cdc3188854 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java
@@ -1,7 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -9,7 +14,6 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
@@ -33,8 +37,8 @@
public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -44,72 +48,100 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("InvertedLineChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarX.setProgress(45);
+ seekBarY.setProgress(100);
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
+ seekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
+ chart.setDrawGridBackground(false);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
-
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
// set an alternative background color
- // mChart.setBackgroundColor(Color.GRAY);
+ // chart.setBackgroundColor(Color.GRAY);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
- mv.setChartView(mChart); // For bounds control
- mChart.setMarker(mv); // Set the marker to the chart
-
- XAxis xl = mChart.getXAxis();
+ mv.setChartView(chart); // For bounds control
+ chart.setMarker(mv); // Set the marker to the chart
+
+ XAxis xl = chart.getXAxis();
xl.setAvoidFirstLastClipping(true);
xl.setAxisMinimum(0f);
-
- YAxis leftAxis = mChart.getAxisLeft();
+
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setInverted(true);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
-
- YAxis rightAxis = mChart.getAxisRight();
+
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// add data
setData(25, 50);
// // restrain the maximum scale-out factor
- // mChart.setScaleMinima(3f, 3f);
+ // chart.setScaleMinima(3f, 3f);
//
// // center the view to a specific position inside the chart
- // mChart.centerViewPort(10, 50);
+ // chart.centerViewPort(10, 50);
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
- // dont forget to refresh the drawing
- mChart.invalidate();
+ // don't forget to refresh the drawing
+ chart.invalidate();
+ }
+
+ private void setData(int count, float range) {
+
+ ArrayList entries = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float xVal = (float) (Math.random() * range);
+ float yVal = (float) (Math.random() * range);
+ entries.add(new Entry(xVal, yVal));
+ }
+
+ // sort by x-value
+ Collections.sort(entries, new EntryXComparator());
+
+ // create a dataset and give it a type
+ LineDataSet set1 = new LineDataSet(entries, "DataSet 1");
+
+ set1.setLineWidth(1.5f);
+ set1.setCircleRadius(4f);
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1);
+
+ // set data
+ chart.setData(data);
}
@Override
@@ -122,8 +154,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -132,19 +170,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -155,11 +193,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -170,45 +208,42 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -218,13 +253,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
+ chart.invalidate();
+ }
+
+ @Override
+ public void saveToGallery() {
+ saveToGallery(chart, "InvertedLineChartActivity");
}
@Override
@@ -235,46 +275,11 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- // TODO Auto-generated method stub
-
- }
+ public void onNothingSelected() {}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList entries = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float xVal = (float) (Math.random() * range);
- float yVal = (float) (Math.random() * range);
- entries.add(new Entry(xVal, yVal));
- }
-
- // sort by x-value
- Collections.sort(entries, new EntryXComparator());
-
- // create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(entries, "DataSet 1");
-
- set1.setLineWidth(1.5f);
- set1.setCircleRadius(4f);
-
- // create a data object with the datasets
- LineData data = new LineData(set1);
-
- // set data
- mChart.setData(data);
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
index 85d213e351..4a970df995 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java
@@ -1,21 +1,22 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.DashPathEffect;
-import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.Bundle;
-import android.support.v4.content.ContextCompat;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-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;
@@ -28,10 +29,10 @@
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
+import com.github.mikephil.charting.formatter.IFillFormatter;
import com.github.mikephil.charting.highlight.Highlight;
+import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
-import com.github.mikephil.charting.listener.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;
@@ -40,11 +41,17 @@
import java.util.ArrayList;
import java.util.List;
+/**
+ * Example of a heavily customized {@link LineChart} with limit lines, custom line shapes, etc.
+ *
+ * @since 1.7.4
+ * @version 3.0.3
+ */
public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListener,
- OnChartGestureListener, OnChartValueSelectedListener {
+ OnChartValueSelectedListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -54,117 +61,200 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("LineChartActivity1");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setMax(180);
+ seekBarY.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartGestureListener(this);
- mChart.setOnChartValueSelectedListener(this);
- mChart.setDrawGridBackground(false);
+ { // // Chart Style // //
+ chart = findViewById(R.id.chart1);
- // no description text
- mChart.getDescription().setEnabled(false);
+ // background color
+ chart.setBackgroundColor(Color.WHITE);
- // enable touch gestures
- mChart.setTouchEnabled(true);
+ // disable description text
+ chart.getDescription().setEnabled(false);
- // enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
- // mChart.setScaleXEnabled(true);
- // mChart.setScaleYEnabled(true);
+ // enable touch gestures
+ chart.setTouchEnabled(true);
- // if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(true);
+ // set listeners
+ chart.setOnChartValueSelectedListener(this);
+ chart.setDrawGridBackground(false);
- // set an alternative background color
- // mChart.setBackgroundColor(Color.GRAY);
+ // create marker to display box when values are selected
+ MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
- // 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
+ // Set the marker to the chart
+ mv.setChartView(chart);
+ chart.setMarker(mv);
- // x-axis limit line
- LimitLine llXAxis = new LimitLine(10f, "Index 10");
- llXAxis.setLineWidth(4f);
- llXAxis.enableDashedLine(10f, 10f, 0f);
- llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
- llXAxis.setTextSize(10f);
+ // enable scaling and dragging
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
+ // chart.setScaleXEnabled(true);
+ // chart.setScaleYEnabled(true);
- XAxis xAxis = mChart.getXAxis();
- xAxis.enableGridDashedLine(10f, 10f, 0f);
- //xAxis.setValueFormatter(new MyCustomXAxisValueFormatter());
- //xAxis.addLimitLine(llXAxis); // add x-axis limit line
+ // force pinch zoom along both axis
+ chart.setPinchZoom(true);
+ }
+ XAxis xAxis;
+ { // // X-Axis Style // //
+ xAxis = chart.getXAxis();
- Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
+ // vertical grid lines
+ xAxis.enableGridDashedLine(10f, 10f, 0f);
+ }
- 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);
+ YAxis yAxis;
+ { // // Y-Axis Style // //
+ yAxis = chart.getAxisLeft();
- 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);
+ // disable dual axis (only use LEFT axis)
+ chart.getAxisRight().setEnabled(false);
- 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);
+ // horizontal grid lines
+ yAxis.enableGridDashedLine(10f, 10f, 0f);
- // limit lines are drawn behind data (and not on top)
- leftAxis.setDrawLimitLinesBehindData(true);
+ // axis range
+ yAxis.setAxisMaximum(200f);
+ yAxis.setAxisMinimum(-50f);
+ }
- mChart.getAxisRight().setEnabled(false);
- //mChart.getViewPortHandler().setMaximumScaleY(2f);
- //mChart.getViewPortHandler().setMaximumScaleX(2f);
+ { // // Create Limit Lines // //
+ LimitLine llXAxis = new LimitLine(9f, "Index 10");
+ llXAxis.setLineWidth(4f);
+ llXAxis.enableDashedLine(10f, 10f, 0f);
+ llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
+ llXAxis.setTextSize(10f);
+ llXAxis.setTypeface(tfRegular);
+
+ LimitLine ll1 = new LimitLine(150f, "Upper Limit");
+ ll1.setLineWidth(4f);
+ ll1.enableDashedLine(10f, 10f, 0f);
+ ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
+ ll1.setTextSize(10f);
+ ll1.setTypeface(tfRegular);
+
+ LimitLine ll2 = new LimitLine(-30f, "Lower Limit");
+ ll2.setLineWidth(4f);
+ ll2.enableDashedLine(10f, 10f, 0f);
+ ll2.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
+ ll2.setTextSize(10f);
+ ll2.setTypeface(tfRegular);
+
+ // draw limit lines behind data instead of on top
+ yAxis.setDrawLimitLinesBehindData(true);
+ xAxis.setDrawLimitLinesBehindData(true);
+
+ // add limit lines
+ yAxis.addLimitLine(ll1);
+ yAxis.addLimitLine(ll2);
+ //xAxis.addLimitLine(llXAxis);
+ }
// add data
- setData(45, 100);
+ seekBarX.setProgress(45);
+ seekBarY.setProgress(180);
+ setData(45, 180);
-// mChart.setVisibleXRange(20);
-// mChart.setVisibleYRange(20f, AxisDependency.LEFT);
-// mChart.centerViewTo(20, 50, AxisDependency.LEFT);
-
- mChart.animateX(2500);
- //mChart.invalidate();
+ // draw points over time
+ chart.animateX(1500);
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
- // modify the legend ...
+ // draw legend entries as lines
l.setForm(LegendForm.LINE);
-
- // // dont forget to refresh the drawing
- // mChart.invalidate();
}
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- super.onWindowFocusChanged(hasFocus);
+ private void setData(int count, float range) {
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+
+ float val = (float) (Math.random() * range) - 30;
+ values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
+ }
+
+ LineDataSet set1;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set1.setValues(values);
+ set1.notifyDataSetChanged();
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ // create a dataset and give it a type
+ set1 = new LineDataSet(values, "DataSet 1");
+
+ set1.setDrawIcons(false);
+
+ // draw dashed line
+ set1.enableDashedLine(10f, 5f, 0f);
+
+ // black lines and points
+ set1.setColor(Color.BLACK);
+ set1.setCircleColor(Color.BLACK);
+
+ // line thickness and point size
+ set1.setLineWidth(1f);
+ set1.setCircleRadius(3f);
+
+ // draw points as solid circles
+ set1.setDrawCircleHole(false);
+
+ // customize legend entry
+ set1.setFormLineWidth(1f);
+ set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
+ set1.setFormSize(15.f);
+
+ // text size of values
+ set1.setValueTextSize(9f);
+
+ // draw selection line as dashed
+ set1.enableDashedHighlightLine(10f, 5f, 0f);
+
+ // set the filled area
+ set1.setDrawFilled(true);
+ set1.setFillFormatter(new IFillFormatter() {
+ @Override
+ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
+ return chart.getAxisLeft().getAxisMinimum();
+ }
+ });
+
+ // set color of filled area
+ if (Utils.getSDKInt() >= 18) {
+ // drawables only supported on api level 18 and above
+ Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
+ set1.setFillDrawable(drawable);
+ } else {
+ set1.setFillColor(Color.BLACK);
+ }
+
+ ArrayList dataSets = new ArrayList<>();
+ dataSets.add(set1); // add the data sets
+
+ // create a data object with the data sets
+ LineData data = new LineData(dataSets);
+
+ // set data
+ chart.setData(data);
+ }
}
@Override
@@ -177,8 +267,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -187,11 +283,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleIcons: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -200,19 +296,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
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.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -223,11 +319,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -238,11 +334,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -252,11 +348,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -266,11 +362,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHorizontalCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -280,44 +376,41 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000, Easing.EaseInCubic);
+ chart.animateY(2000, Easing.EaseInCubic);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -327,134 +420,31 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
-
- private void setData(int count, float range) {
-
- ArrayList values = new ArrayList();
-
- for (int i = 0; i < count; i++) {
-
- float val = (float) (Math.random() * range) + 3;
- values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
- }
-
- LineDataSet set1;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
- set1.setValues(values);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- // create a dataset and give it a type
- set1 = new LineDataSet(values, "DataSet 1");
-
- set1.setDrawIcons(false);
-
- // set the line to be drawn like this "- - - - - -"
- set1.enableDashedLine(10f, 5f, 0f);
- set1.enableDashedHighlightLine(10f, 5f, 0f);
- set1.setColor(Color.BLACK);
- set1.setCircleColor(Color.BLACK);
- set1.setLineWidth(1f);
- set1.setCircleRadius(3f);
- set1.setDrawCircleHole(false);
- set1.setValueTextSize(9f);
- set1.setDrawFilled(true);
- set1.setFormLineWidth(1f);
- set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
- set1.setFormSize(15.f);
-
- if (Utils.getSDKInt() >= 18) {
- // fill drawable only supported on api level 18 and above
- Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
- set1.setFillDrawable(drawable);
- }
- else {
- set1.setFillColor(Color.BLACK);
- }
-
- ArrayList dataSets = new ArrayList();
- dataSets.add(set1); // add the datasets
-
- // create a data object with the datasets
- LineData data = new LineData(dataSets);
-
- // set data
- mChart.setData(data);
- }
- }
-
- @Override
- public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
- Log.i("Gesture", "START, x: " + me.getX() + ", y: " + me.getY());
- }
-
- @Override
- public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
- Log.i("Gesture", "END, lastGesture: " + lastPerformedGesture);
-
- // un-highlight values after the gesture is finished and no single-tap
- if(lastPerformedGesture != ChartTouchListener.ChartGesture.SINGLE_TAP)
- mChart.highlightValues(null); // or highlightTouch(null) for callback to onNothingSelected(...)
- }
-
- @Override
- public void onChartLongPressed(MotionEvent me) {
- Log.i("LongPress", "Chart longpressed.");
+ chart.invalidate();
}
@Override
- public void onChartDoubleTapped(MotionEvent me) {
- Log.i("DoubleTap", "Chart double-tapped.");
+ public void saveToGallery() {
+ saveToGallery(chart, "LineChartActivity1");
}
@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);
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@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);
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
@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());
+ Log.i("LOW HIGH", "low: " + chart.getLowestVisibleX() + ", high: " + chart.getHighestVisibleX());
+ Log.i("MIN MAX", "xMin: " + chart.getXChartMin() + ", xMax: " + chart.getXChartMax() + ", yMin: " + chart.getYChartMin() + ", yMax: " + chart.getYChartMax());
}
@Override
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
index e2a381ff91..c0f72d87fa 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
@@ -1,8 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -10,7 +15,6 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
@@ -30,11 +34,17 @@
import java.util.ArrayList;
import java.util.List;
+/**
+ * Example of a dual axis {@link LineChart} with multiple data sets.
+ *
+ * @since 1.7.4
+ * @version 3.0.3
+ */
public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -44,51 +54,53 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("LineChartActivity2");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarX.setProgress(45);
- mSeekBarY.setProgress(100);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
- mChart.setDragDecelerationFrictionCoef(0.9f);
+ chart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
- mChart.setDrawGridBackground(false);
- mChart.setHighlightPerDragEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
+ chart.setDrawGridBackground(false);
+ chart.setHighlightPerDragEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
// set an alternative background color
- mChart.setBackgroundColor(Color.LTGRAY);
+ chart.setBackgroundColor(Color.LTGRAY);
// add data
+ seekBarX.setProgress(20);
+ seekBarY.setProgress(30);
setData(20, 30);
- mChart.animateX(2500);
+ chart.animateX(1500);
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
l.setTextSize(11f);
l.setTextColor(Color.WHITE);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
@@ -97,23 +109,23 @@ protected void onCreate(Bundle savedInstanceState) {
l.setDrawInside(false);
// l.setYOffset(11f);
- XAxis xAxis = mChart.getXAxis();
- xAxis.setTypeface(mTfLight);
+ XAxis xAxis = chart.getXAxis();
+ xAxis.setTypeface(tfLight);
xAxis.setTextSize(11f);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
- YAxis leftAxis = mChart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ YAxis leftAxis = chart.getAxisLeft();
+ leftAxis.setTypeface(tfLight);
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setAxisMaximum(200f);
leftAxis.setAxisMinimum(0f);
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
- YAxis rightAxis = mChart.getAxisRight();
- rightAxis.setTypeface(mTfLight);
+ YAxis rightAxis = chart.getAxisRight();
+ rightAxis.setTypeface(tfLight);
rightAxis.setTextColor(Color.RED);
rightAxis.setAxisMaximum(900);
rightAxis.setAxisMinimum(-200);
@@ -122,6 +134,93 @@ protected void onCreate(Bundle savedInstanceState) {
rightAxis.setGranularityEnabled(false);
}
+ private void setData(int count, float range) {
+
+ ArrayList values1 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * (range / 2f)) + 50;
+ values1.add(new Entry(i, val));
+ }
+
+ ArrayList values2 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range) + 450;
+ values2.add(new Entry(i, val));
+ }
+
+ ArrayList values3 = new ArrayList<>();
+
+ for (int i = 0; i < count; i++) {
+ float val = (float) (Math.random() * range) + 500;
+ values3.add(new Entry(i, val));
+ }
+
+ LineDataSet set1, set2, set3;
+
+ if (chart.getData() != null &&
+ chart.getData().getDataSetCount() > 0) {
+ set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
+ set2 = (LineDataSet) chart.getData().getDataSetByIndex(1);
+ set3 = (LineDataSet) chart.getData().getDataSetByIndex(2);
+ set1.setValues(values1);
+ set2.setValues(values2);
+ set3.setValues(values3);
+ chart.getData().notifyDataChanged();
+ chart.notifyDataSetChanged();
+ } else {
+ // create a dataset and give it a type
+ set1 = new LineDataSet(values1, "DataSet 1");
+
+ set1.setAxisDependency(AxisDependency.LEFT);
+ set1.setColor(ColorTemplate.getHoloBlue());
+ set1.setCircleColor(Color.WHITE);
+ set1.setLineWidth(2f);
+ set1.setCircleRadius(3f);
+ set1.setFillAlpha(65);
+ set1.setFillColor(ColorTemplate.getHoloBlue());
+ set1.setHighLightColor(Color.rgb(244, 117, 117));
+ set1.setDrawCircleHole(false);
+ //set1.setFillFormatter(new MyFillFormatter(0f));
+ //set1.setDrawHorizontalHighlightIndicator(false);
+ //set1.setVisible(false);
+ //set1.setCircleHoleColor(Color.WHITE);
+
+ // create a dataset and give it a type
+ set2 = new LineDataSet(values2, "DataSet 2");
+ set2.setAxisDependency(AxisDependency.RIGHT);
+ set2.setColor(Color.RED);
+ set2.setCircleColor(Color.WHITE);
+ set2.setLineWidth(2f);
+ set2.setCircleRadius(3f);
+ set2.setFillAlpha(65);
+ set2.setFillColor(Color.RED);
+ set2.setDrawCircleHole(false);
+ set2.setHighLightColor(Color.rgb(244, 117, 117));
+ //set2.setFillFormatter(new MyFillFormatter(900f));
+
+ set3 = new LineDataSet(values3, "DataSet 3");
+ set3.setAxisDependency(AxisDependency.RIGHT);
+ set3.setColor(Color.YELLOW);
+ set3.setCircleColor(Color.WHITE);
+ set3.setLineWidth(2f);
+ set3.setCircleRadius(3f);
+ set3.setFillAlpha(65);
+ set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
+ set3.setDrawCircleHole(false);
+ set3.setHighLightColor(Color.rgb(244, 117, 117));
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1, set2, set3);
+ data.setValueTextColor(Color.WHITE);
+ data.setValueTextSize(9f);
+
+ // set data
+ chart.setData(data);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
@@ -132,8 +231,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -142,19 +247,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -165,11 +270,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -180,11 +285,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -194,11 +299,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -208,11 +313,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHorizontalCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -222,46 +327,41 @@ public boolean onOptionsItemSelected(MenuItem item) {
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
- //mChart.highlightValue(9.7f, 1, false);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
-
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -271,117 +371,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress() + 1));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
// redraw
- mChart.invalidate();
+ chart.invalidate();
}
- private void setData(int count, float range) {
-
- ArrayList yVals1 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = range / 2f;
- float val = (float) (Math.random() * mult) + 50;
- yVals1.add(new Entry(i, val));
- }
-
- ArrayList yVals2 = new ArrayList();
-
- for (int i = 0; i < count-1; i++) {
- float mult = range;
- float val = (float) (Math.random() * mult) + 450;
- yVals2.add(new Entry(i, val));
-// if(i == 10) {
-// yVals2.add(new Entry(i, val + 50));
-// }
- }
-
- ArrayList yVals3 = new ArrayList();
-
- for (int i = 0; i < count; i++) {
- float mult = range;
- float val = (float) (Math.random() * mult) + 500;
- yVals3.add(new Entry(i, val));
- }
-
- LineDataSet set1, set2, set3;
-
- if (mChart.getData() != null &&
- mChart.getData().getDataSetCount() > 0) {
- set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
- set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
- set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2);
- set1.setValues(yVals1);
- set2.setValues(yVals2);
- set3.setValues(yVals3);
- mChart.getData().notifyDataChanged();
- mChart.notifyDataSetChanged();
- } else {
- // create a dataset and give it a type
- set1 = new LineDataSet(yVals1, "DataSet 1");
-
- set1.setAxisDependency(AxisDependency.LEFT);
- set1.setColor(ColorTemplate.getHoloBlue());
- set1.setCircleColor(Color.WHITE);
- set1.setLineWidth(2f);
- set1.setCircleRadius(3f);
- set1.setFillAlpha(65);
- set1.setFillColor(ColorTemplate.getHoloBlue());
- set1.setHighLightColor(Color.rgb(244, 117, 117));
- set1.setDrawCircleHole(false);
- //set1.setFillFormatter(new MyFillFormatter(0f));
- //set1.setDrawHorizontalHighlightIndicator(false);
- //set1.setVisible(false);
- //set1.setCircleHoleColor(Color.WHITE);
-
- // create a dataset and give it a type
- set2 = new LineDataSet(yVals2, "DataSet 2");
- set2.setAxisDependency(AxisDependency.RIGHT);
- set2.setColor(Color.RED);
- set2.setCircleColor(Color.WHITE);
- set2.setLineWidth(2f);
- set2.setCircleRadius(3f);
- set2.setFillAlpha(65);
- set2.setFillColor(Color.RED);
- set2.setDrawCircleHole(false);
- set2.setHighLightColor(Color.rgb(244, 117, 117));
- //set2.setFillFormatter(new MyFillFormatter(900f));
-
- set3 = new LineDataSet(yVals3, "DataSet 3");
- set3.setAxisDependency(AxisDependency.RIGHT);
- set3.setColor(Color.YELLOW);
- set3.setCircleColor(Color.WHITE);
- set3.setLineWidth(2f);
- set3.setCircleRadius(3f);
- set3.setFillAlpha(65);
- set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
- set3.setDrawCircleHole(false);
- set3.setHighLightColor(Color.rgb(244, 117, 117));
-
- // create a data object with the datasets
- LineData data = new LineData(set1, set2, set3);
- data.setValueTextColor(Color.WHITE);
- data.setValueTextSize(9f);
-
- // set data
- mChart.setData(data);
- }
+ @Override
+ public void saveToGallery() {
+ saveToGallery(chart, "LineChartActivity2");
}
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.i("Entry selected", e.toString());
- mChart.centerViewToAnimated(e.getX(), e.getY(), mChart.getData().getDataSetByIndex(h.getDataSetIndex())
+ chart.centerViewToAnimated(e.getX(), e.getY(), chart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency(), 500);
- //mChart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex)
+ //chart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex)
// .getAxisDependency(), 1000);
- //mChart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex)
+ //chart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex)
// .getAxisDependency(), 1000);
}
@@ -391,14 +403,8 @@ public void onNothingSelected() {
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
index 39730d55b1..7bb95b83ed 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java
@@ -1,9 +1,13 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.LineChart;
@@ -15,10 +19,10 @@
import java.util.ArrayList;
+@SuppressWarnings("SameParameterValue")
public class LineChartActivityColored extends DemoBase {
- private LineChart[] mCharts = new LineChart[4];
- private Typeface mTf;
+ private LineChart[] charts = new LineChart[4];
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -27,26 +31,28 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_colored_lines);
- mCharts[0] = findViewById(R.id.chart1);
- mCharts[1] = findViewById(R.id.chart2);
- mCharts[2] = findViewById(R.id.chart3);
- mCharts[3] = findViewById(R.id.chart4);
+ setTitle("LineChartActivityColored");
- mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");
+ charts[0] = findViewById(R.id.chart1);
+ charts[1] = findViewById(R.id.chart2);
+ charts[2] = findViewById(R.id.chart3);
+ charts[3] = findViewById(R.id.chart4);
- for (int i = 0; i < mCharts.length; i++) {
+ Typeface mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");
+
+ for (int i = 0; i < charts.length; i++) {
LineData data = getData(36, 100);
data.setValueTypeface(mTf);
// add some transparency to the color with "& 0x90FFFFFF"
- setupChart(mCharts[i], data, mColors[i % mColors.length]);
+ setupChart(charts[i], data, colors[i % colors.length]);
}
}
- private int[] mColors = new int[] {
- Color.rgb(137, 230, 81),
- Color.rgb(240, 240, 30),
+ private final int[] colors = new int[] {
+ Color.rgb(137, 230, 81),
+ Color.rgb(240, 240, 30),
Color.rgb(89, 199, 250),
Color.rgb(250, 104, 104)
};
@@ -57,8 +63,8 @@ private void setupChart(LineChart chart, LineData data, int color) {
// no description text
chart.getDescription().setEnabled(false);
-
- // mChart.setDrawHorizontalGrid(false);
+
+ // chart.setDrawHorizontalGrid(false);
//
// enable / disable grid background
chart.setDrawGridBackground(false);
@@ -75,7 +81,7 @@ private void setupChart(LineChart chart, LineData data, int color) {
chart.setPinchZoom(false);
chart.setBackgroundColor(color);
-
+
// set custom chart offsets (automatic offset calculation is hereby disabled)
chart.setViewPortOffsets(10, 0, 10, 0);
@@ -96,18 +102,18 @@ private void setupChart(LineChart chart, LineData data, int color) {
// animate calls invalidate()...
chart.animateX(2500);
}
-
+
private LineData getData(int count, float range) {
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) + 3;
- yVals.add(new Entry(i, val));
+ values.add(new Entry(i, val));
}
// create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
+ LineDataSet set1 = new LineDataSet(values, "DataSet 1");
// set1.setFillAlpha(110);
// set1.setFillColor(Color.RED);
@@ -119,9 +125,31 @@ private LineData getData(int count, float range) {
set1.setHighLightColor(Color.WHITE);
set1.setDrawValues(false);
- // create a data object with the datasets
- LineData data = new LineData(set1);
+ // create a data object with the data sets
+ return new LineData(set1);
+ }
- return data;
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.only_github, menu);
+ return true;
}
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java
index 6bf96f02a7..a88842c5d0 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java
@@ -1,15 +1,19 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
@@ -25,17 +29,17 @@
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
-import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.concurrent.TimeUnit;
public class LineChartTime extends DemoBase implements OnSeekBarChangeListener {
- private LineChart mChart;
- private SeekBar mSeekBarX;
+ private LineChart chart;
+ private SeekBar seekBarX;
private TextView tvX;
@Override
@@ -45,44 +49,44 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_time);
- tvX = findViewById(R.id.tvXMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setProgress(100);
- tvX.setText("100");
+ setTitle("LineChartTime");
- mSeekBarX.setOnSeekBarChangeListener(this);
+ tvX = findViewById(R.id.tvXMax);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
+ chart = findViewById(R.id.chart1);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
- mChart.setDragDecelerationFrictionCoef(0.9f);
+ chart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
- mChart.setDrawGridBackground(false);
- mChart.setHighlightPerDragEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
+ chart.setDrawGridBackground(false);
+ chart.setHighlightPerDragEnabled(true);
// set an alternative background color
- mChart.setBackgroundColor(Color.WHITE);
- mChart.setViewPortOffsets(0f, 0f, 0f, 0f);
+ chart.setBackgroundColor(Color.WHITE);
+ chart.setViewPortOffsets(0f, 0f, 0f, 0f);
// add data
+ seekBarX.setProgress(100);
setData(100, 30);
- mChart.invalidate();
+ chart.invalidate();
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setEnabled(false);
- XAxis xAxis = mChart.getXAxis();
+ XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
- xAxis.setTypeface(mTfLight);
+ xAxis.setTypeface(tfLight);
xAxis.setTextSize(10f);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawAxisLine(false);
@@ -92,7 +96,7 @@ protected void onCreate(Bundle savedInstanceState) {
xAxis.setGranularity(1f); // one hour
xAxis.setValueFormatter(new IAxisValueFormatter() {
- private SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm");
+ private SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);
@Override
public String getFormattedValue(float value, AxisBase axis) {
@@ -102,9 +106,9 @@ public String getFormattedValue(float value, AxisBase axis) {
}
});
- YAxis leftAxis = mChart.getAxisLeft();
+ YAxis leftAxis = chart.getAxisLeft();
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
- leftAxis.setTypeface(mTfLight);
+ leftAxis.setTypeface(tfLight);
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
@@ -113,10 +117,49 @@ public String getFormattedValue(float value, AxisBase axis) {
leftAxis.setYOffset(-9f);
leftAxis.setTextColor(Color.rgb(255, 192, 56));
- YAxis rightAxis = mChart.getAxisRight();
+ YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
}
+ private void setData(int count, float range) {
+
+ // now in hours
+ long now = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis());
+
+ ArrayList values = new ArrayList<>();
+
+ // count = hours
+ float to = now + count;
+
+ // increment by 1 hour
+ for (float x = now; x < to; x++) {
+
+ float y = getRandom(range, 50);
+ values.add(new Entry(x, y)); // add one entry per hour
+ }
+
+ // create a dataset and give it a type
+ LineDataSet set1 = new LineDataSet(values, "DataSet 1");
+ set1.setAxisDependency(AxisDependency.LEFT);
+ set1.setColor(ColorTemplate.getHoloBlue());
+ set1.setValueTextColor(ColorTemplate.getHoloBlue());
+ set1.setLineWidth(1.5f);
+ set1.setDrawCircles(false);
+ set1.setDrawValues(false);
+ set1.setFillAlpha(65);
+ set1.setFillColor(ColorTemplate.getHoloBlue());
+ set1.setHighLightColor(Color.rgb(244, 117, 117));
+ set1.setDrawCircleHole(false);
+
+ // create a data object with the data sets
+ LineData data = new LineData(set1);
+ data.setValueTextColor(Color.WHITE);
+ data.setValueTextSize(9f);
+
+ // set data
+ chart.setData(data);
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
@@ -127,8 +170,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -137,19 +186,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -160,11 +209,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -175,11 +224,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCubic: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -190,11 +239,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleStepped: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -205,45 +254,42 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setMode(LineDataSet.Mode.STEPPED);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionTogglePinch: {
- if (mChart.isPinchZoomEnabled())
- mChart.setPinchZoom(false);
+ if (chart.isPinchZoomEnabled())
+ chart.setPinchZoom(false);
else
- mChart.setPinchZoom(true);
+ chart.setPinchZoom(true);
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
- mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
- mChart.notifyDataSetChanged();
+ chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
+ chart.notifyDataSetChanged();
break;
}
case R.id.animateX: {
- mChart.animateX(3000);
+ chart.animateX(2000);
break;
}
case R.id.animateY: {
- mChart.animateY(3000);
+ chart.animateY(2000);
break;
}
case R.id.animateXY: {
- mChart.animateXY(3000, 3000);
+ chart.animateXY(2000, 2000);
break;
}
case R.id.actionSave: {
- if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
- Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
- Toast.LENGTH_SHORT).show();
- } else
- Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
- .show();
-
- // mChart.saveToGallery("title"+System.currentTimeMillis())
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -253,64 +299,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
- setData(mSeekBarX.getProgress(), 50);
+ setData(seekBarX.getProgress(), 50);
// redraw
- mChart.invalidate();
- }
-
- private void setData(int count, float range) {
-
- // now in hours
- long now = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis());
-
- ArrayList values = new ArrayList();
-
- float from = now;
-
- // count = hours
- float to = now + count;
-
- // increment by 1 hour
- for (float x = from; x < to; x++) {
-
- float y = getRandom(range, 50);
- values.add(new Entry(x, y)); // add one entry per hour
- }
-
- // create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(values, "DataSet 1");
- set1.setAxisDependency(AxisDependency.LEFT);
- set1.setColor(ColorTemplate.getHoloBlue());
- set1.setValueTextColor(ColorTemplate.getHoloBlue());
- set1.setLineWidth(1.5f);
- set1.setDrawCircles(false);
- set1.setDrawValues(false);
- set1.setFillAlpha(65);
- set1.setFillColor(ColorTemplate.getHoloBlue());
- set1.setHighLightColor(Color.rgb(244, 117, 117));
- set1.setDrawCircleHole(false);
-
- // create a data object with the datasets
- LineData data = new LineData(set1);
- data.setValueTextColor(Color.WHITE);
- data.setValueTextSize(9f);
-
- // set data
- mChart.setData(data);
+ chart.invalidate();
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
+ public void saveToGallery() {
+ saveToGallery(chart, "LineChartTime");
}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
+ public void onStartTrackingTouch(SeekBar seekBar) {}
- }
-}
\ No newline at end of file
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
+}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java
index 54218a53da..1466e5f9de 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java
@@ -1,11 +1,16 @@
package com.xxmassdeveloper.mpchartexample;
+import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.Intent;
import android.graphics.Color;
-import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.annotation.NonNull;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
@@ -28,8 +33,8 @@
/**
* Demonstrates the use of charts inside a ListView. IMPORTANT: provide a
- * specific height attribute for the chart inside your listview-item
- *
+ * specific height attribute for the chart inside your ListView item
+ *
* @author Philipp Jahoda
*/
public class ListViewBarChartActivity extends DemoBase {
@@ -40,10 +45,12 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_listview_chart);
-
+
+ setTitle("ListViewBarChartActivity");
+
ListView lv = findViewById(R.id.listView1);
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList<>();
// 20 items
for (int i = 0; i < 20; i++) {
@@ -56,16 +63,18 @@ protected void onCreate(Bundle savedInstanceState) {
private class ChartDataAdapter extends ArrayAdapter {
- public ChartDataAdapter(Context context, List objects) {
+ ChartDataAdapter(Context context, List objects) {
super(context, 0, objects);
}
+ @SuppressLint("InflateParams")
+ @NonNull
@Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
BarData data = getItem(position);
- ViewHolder holder = null;
+ ViewHolder holder;
if (convertView == null) {
@@ -82,30 +91,32 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
// apply styling
- data.setValueTypeface(mTfLight);
- data.setValueTextColor(Color.BLACK);
+ if (data != null) {
+ data.setValueTypeface(tfLight);
+ data.setValueTextColor(Color.BLACK);
+ }
holder.chart.getDescription().setEnabled(false);
holder.chart.setDrawGridBackground(false);
XAxis xAxis = holder.chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
- xAxis.setTypeface(mTfLight);
+ xAxis.setTypeface(tfLight);
xAxis.setDrawGridLines(false);
-
+
YAxis leftAxis = holder.chart.getAxisLeft();
- leftAxis.setTypeface(mTfLight);
+ leftAxis.setTypeface(tfLight);
leftAxis.setLabelCount(5, false);
leftAxis.setSpaceTop(15f);
-
+
YAxis rightAxis = holder.chart.getAxisRight();
- rightAxis.setTypeface(mTfLight);
+ rightAxis.setTypeface(tfLight);
rightAxis.setLabelCount(5, false);
rightAxis.setSpaceTop(15f);
// set data
holder.chart.setData(data);
holder.chart.setFitBars(true);
-
+
// do not forget to refresh the chart
// holder.chart.invalidate();
holder.chart.animateY(700);
@@ -121,12 +132,12 @@ private class ViewHolder {
/**
* generates a random ChartData object with just one DataSet
- *
- * @return
+ *
+ * @return Bar data
*/
private BarData generateData(int cnt) {
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
@@ -135,12 +146,36 @@ private BarData generateData(int cnt) {
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setBarShadowColor(Color.rgb(203, 203, 203));
-
- ArrayList sets = new ArrayList();
+
+ ArrayList sets = new ArrayList<>();
sets.add(d);
-
+
BarData cd = new BarData(sets);
cd.setBarWidth(0.9f);
return cd;
}
+
+ @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/ListViewBarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java
index 0c9f132f03..1455691620 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java
@@ -2,8 +2,13 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Context;
+import android.content.Intent;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.annotation.NonNull;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
@@ -32,8 +37,8 @@
/**
* Demonstrates the use of charts inside a ListView. IMPORTANT: provide a
- * specific height attribute for the chart inside your listview-item
- *
+ * specific height attribute for the chart inside your ListView item
+ *
* @author Philipp Jahoda
*/
public class ListViewMultiChartActivity extends DemoBase {
@@ -44,20 +49,22 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_listview_chart);
-
+
+ setTitle("ListViewMultiChartActivity");
+
ListView lv = findViewById(R.id.listView1);
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList<>();
// 30 items
for (int i = 0; i < 30; i++) {
-
+
if(i % 3 == 0) {
list.add(new LineChartItem(generateDataLine(i + 1), getApplicationContext()));
} else if(i % 3 == 1) {
list.add(new BarChartItem(generateDataBar(i + 1), getApplicationContext()));
} else if(i % 3 == 2) {
- list.add(new PieChartItem(generateDataPie(i + 1), getApplicationContext()));
+ list.add(new PieChartItem(generateDataPie(), getApplicationContext()));
}
}
@@ -67,77 +74,79 @@ protected void onCreate(Bundle savedInstanceState) {
/** adapter that supports 3 different item types */
private class ChartDataAdapter extends ArrayAdapter {
-
- public ChartDataAdapter(Context context, List objects) {
+
+ ChartDataAdapter(Context context, List objects) {
super(context, 0, objects);
}
+ @NonNull
@Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
+ //noinspection ConstantConditions
return getItem(position).getView(position, convertView, getContext());
}
-
+
@Override
- public int getItemViewType(int position) {
+ public int getItemViewType(int position) {
// return the views type
- return getItem(position).getItemType();
+ ChartItem ci = getItem(position);
+ return ci != null ? ci.getItemType() : 0;
}
-
+
@Override
public int getViewTypeCount() {
return 3; // we have 3 different item-types
}
}
-
+
/**
* generates a random ChartData object with just one DataSet
- *
- * @return
+ *
+ * @return Line data
*/
private LineData generateDataLine(int cnt) {
- ArrayList e1 = new ArrayList();
+ ArrayList values1 = new ArrayList<>();
for (int i = 0; i < 12; i++) {
- e1.add(new Entry(i, (int) (Math.random() * 65) + 40));
+ values1.add(new Entry(i, (int) (Math.random() * 65) + 40));
}
- LineDataSet d1 = new LineDataSet(e1, "New DataSet " + cnt + ", (1)");
+ LineDataSet d1 = new LineDataSet(values1, "New DataSet " + cnt + ", (1)");
d1.setLineWidth(2.5f);
d1.setCircleRadius(4.5f);
d1.setHighLightColor(Color.rgb(244, 117, 117));
d1.setDrawValues(false);
-
- ArrayList e2 = new ArrayList();
+
+ ArrayList values2 = new ArrayList<>();
for (int i = 0; i < 12; i++) {
- e2.add(new Entry(i, e1.get(i).getY() - 30));
+ values2.add(new Entry(i, values1.get(i).getY() - 30));
}
- LineDataSet d2 = new LineDataSet(e2, "New DataSet " + cnt + ", (2)");
+ LineDataSet d2 = new LineDataSet(values2, "New DataSet " + cnt + ", (2)");
d2.setLineWidth(2.5f);
d2.setCircleRadius(4.5f);
d2.setHighLightColor(Color.rgb(244, 117, 117));
d2.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
d2.setDrawValues(false);
-
- ArrayList sets = new ArrayList();
+
+ ArrayList sets = new ArrayList<>();
sets.add(d1);
sets.add(d2);
-
- LineData cd = new LineData(sets);
- return cd;
+
+ return new LineData(sets);
}
-
+
/**
* generates a random ChartData object with just one DataSet
- *
- * @return
+ *
+ * @return Bar data
*/
private BarData generateDataBar(int cnt) {
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
@@ -146,32 +155,55 @@ private BarData generateDataBar(int cnt) {
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setHighLightAlpha(255);
-
+
BarData cd = new BarData(d);
cd.setBarWidth(0.9f);
return cd;
}
-
+
/**
* generates a random ChartData object with just one DataSet
- *
- * @return
+ *
+ * @return Pie data
*/
- private PieData generateDataPie(int cnt) {
+ private PieData generateDataPie() {
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
for (int i = 0; i < 4; i++) {
entries.add(new PieEntry((float) ((Math.random() * 70) + 30), "Quarter " + (i+1)));
}
PieDataSet d = new PieDataSet(entries, "");
-
+
// space between slices
d.setSliceSpace(2f);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
-
- PieData cd = new PieData(d);
- return cd;
+
+ return new PieData(d);
+ }
+
+ @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/ListViewMultiChartActivity.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
}
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java
index e6acf01670..c5cbd570c6 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java
@@ -1,10 +1,16 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -12,12 +18,13 @@
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.ChartTouchListener;
+import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@@ -26,10 +33,10 @@
import java.util.List;
public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
- OnChartValueSelectedListener {
+ OnChartGestureListener, OnChartValueSelectedListener {
- private LineChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private LineChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -39,51 +46,101 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
+ setTitle("MultiLineChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarX.setOnSeekBarChangeListener(this);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarX.setOnSeekBarChangeListener(this);
+
+ seekBarY = findViewById(R.id.seekBar2);
+ seekBarY.setOnSeekBarChangeListener(this);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ chart = findViewById(R.id.chart1);
+ chart.setOnChartValueSelectedListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setOnChartValueSelectedListener(this);
-
- mChart.setDrawGridBackground(false);
- mChart.getDescription().setEnabled(false);
- mChart.setDrawBorders(false);
+ chart.setDrawGridBackground(false);
+ chart.getDescription().setEnabled(false);
+ chart.setDrawBorders(false);
- mChart.getAxisLeft().setEnabled(false);
- mChart.getAxisRight().setDrawAxisLine(false);
- mChart.getAxisRight().setDrawGridLines(false);
- mChart.getXAxis().setDrawAxisLine(false);
- mChart.getXAxis().setDrawGridLines(false);
+ chart.getAxisLeft().setEnabled(false);
+ chart.getAxisRight().setDrawAxisLine(false);
+ chart.getAxisRight().setDrawGridLines(false);
+ chart.getXAxis().setDrawAxisLine(false);
+ chart.getXAxis().setDrawGridLines(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);
- mSeekBarX.setProgress(20);
- mSeekBarY.setProgress(100);
+ seekBarX.setProgress(20);
+ 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(false);
}
+ private final int[] colors = new int[] {
+ ColorTemplate.VORDIPLOM_COLORS[0],
+ ColorTemplate.VORDIPLOM_COLORS[1],
+ ColorTemplate.VORDIPLOM_COLORS[2]
+ };
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ chart.resetTracking();
+
+ progress = seekBarX.getProgress();
+
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
+
+ ArrayList dataSets = new ArrayList<>();
+
+ for (int z = 0; z < 3; z++) {
+
+ ArrayList values = new ArrayList<>();
+
+ for (int i = 0; i < progress; i++) {
+ double val = (Math.random() * seekBarY.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 = colors[z % colors.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);
+ chart.setData(data);
+ chart.invalidate();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
+ menu.removeItem(R.id.actionToggleIcons);
return true;
}
@@ -91,8 +148,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -101,32 +164,35 @@ public boolean onOptionsItemSelected(MenuItem item) {
set.setDrawValues(!set.isDrawValuesEnabled());
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
+ /*
+ case R.id.actionToggleIcons: { 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.actionToggleHighlight: {
- if(mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if(chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleFilled: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -137,11 +203,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawFilled(true);
}
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleCircles: {
- List sets = mChart.getData()
+ List sets = chart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
@@ -152,74 +218,122 @@ public boolean onOptionsItemSelected(MenuItem item) {
else
set.setDrawCircles(true);
}
- mChart.invalidate();
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleCubic: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER
+ ? LineDataSet.Mode.LINEAR
+ : LineDataSet.Mode.CUBIC_BEZIER);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleStepped: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setMode(set.getMode() == LineDataSet.Mode.STEPPED
+ ? LineDataSet.Mode.LINEAR
+ : LineDataSet.Mode.STEPPED);
+ }
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleHorizontalCubic: {
+ List sets = chart.getData()
+ .getDataSets();
+
+ for (ILineDataSet iSet : sets) {
+
+ LineDataSet set = (LineDataSet) iSet;
+ set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER
+ ? LineDataSet.Mode.LINEAR
+ : LineDataSet.Mode.HORIZONTAL_BEZIER);
+ }
+ chart.invalidate();
break;
}
case R.id.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;
}
}
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();
+ public void saveToGallery() {
+ saveToGallery(chart, "MultiLineChartActivity");
+ }
- tvX.setText("" + (mSeekBarX.getProgress()));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ @Override
+ public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
+ Log.i("Gesture", "START, x: " + me.getX() + ", y: " + me.getY());
+ }
- ArrayList dataSets = new ArrayList();
+ @Override
+ public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
+ Log.i("Gesture", "END, lastGesture: " + lastPerformedGesture);
- for (int z = 0; z < 3; z++) {
+ // un-highlight values after the gesture is finished and no single-tap
+ if(lastPerformedGesture != ChartTouchListener.ChartGesture.SINGLE_TAP)
+ chart.highlightValues(null); // or highlightTouch(null) for callback to onNothingSelected(...)
+ }
- ArrayList values = new ArrayList();
+ @Override
+ public void onChartLongPressed(MotionEvent me) {
+ Log.i("LongPress", "Chart long pressed.");
+ }
- for (int i = 0; i < mSeekBarX.getProgress(); i++) {
- double val = (Math.random() * mSeekBarY.getProgress()) + 3;
- values.add(new Entry(i, (float) val));
- }
+ @Override
+ public void onChartDoubleTapped(MotionEvent me) {
+ Log.i("DoubleTap", "Chart double-tapped.");
+ }
- LineDataSet d = new LineDataSet(values, "DataSet " + (z + 1));
- d.setLineWidth(2.5f);
- d.setCircleRadius(4f);
+ @Override
+ public void onChartSingleTapped(MotionEvent me) {
+ Log.i("SingleTap", "Chart single-tapped.");
+ }
- int color = mColors[z % mColors.length];
- d.setColor(color);
- d.setCircleColor(color);
- dataSets.add(d);
- }
+ @Override
+ public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
+ Log.i("Fling", "Chart fling. VelocityX: " + velocityX + ", VelocityY: " + velocityY);
+ }
- // 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);
+ @Override
+ public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
+ Log.i("Scale / Zoom", "ScaleX: " + scaleX + ", ScaleY: " + scaleY);
+ }
- LineData data = new LineData(dataSets);
- mChart.setData(data);
- mChart.invalidate();
+ @Override
+ public void onChartTranslate(MotionEvent me, float dX, float dY) {
+ Log.i("Translate / Move", "dX: " + dX + ", dY: " + dY);
}
@Override
@@ -230,16 +344,11 @@ public void onValueSelected(Entry e, Highlight h) {
}
@Override
- public void onNothingSelected() {
- // TODO Auto-generated method stub
-
- }
+ public void onNothingSelected() {}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java
index a2d4becadc..c557323451 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java
@@ -1,8 +1,12 @@
package com.xxmassdeveloper.mpchartexample;
+import android.content.Intent;
import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -17,11 +21,12 @@
import java.util.ArrayList;
+@SuppressWarnings("SameParameterValue")
public class PerformanceLineChart extends DemoBase implements OnSeekBarChangeListener {
- private LineChart mChart;
- private SeekBar mSeekBarValues;
- private TextView mTvCount;
+ private LineChart chart;
+ private SeekBar seekBarValues;
+ private TextView tvCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -30,80 +35,51 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_performance_linechart);
- mTvCount = findViewById(R.id.tvValueCount);
- mSeekBarValues = findViewById(R.id.seekbarValues);
- mTvCount.setText("500");
+ setTitle("PerformanceLineChart");
- mSeekBarValues.setProgress(500);
-
- mSeekBarValues.setOnSeekBarChangeListener(this);
+ tvCount = findViewById(R.id.tvValueCount);
+ seekBarValues = findViewById(R.id.seekbarValues);
+ seekBarValues.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setDrawGridBackground(false);
+ chart = findViewById(R.id.chart1);
+ chart.setDrawGridBackground(false);
// no description text
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
// enable touch gestures
- mChart.setTouchEnabled(true);
+ chart.setTouchEnabled(true);
// enable scaling and dragging
- mChart.setDragEnabled(true);
- mChart.setScaleEnabled(true);
+ chart.setDragEnabled(true);
+ chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
- mChart.setPinchZoom(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
+ chart.setPinchZoom(false);
- }
+ chart.getAxisLeft().setDrawGridLines(false);
+ chart.getAxisRight().setEnabled(false);
+ chart.getXAxis().setDrawGridLines(true);
+ chart.getXAxis().setDrawAxisLine(false);
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
+ seekBarValues.setProgress(9000);
+ // don't forget to refresh the drawing
+ chart.invalidate();
}
private void setData(int count, float range) {
- ArrayList yVals = new ArrayList();
+ ArrayList values = new ArrayList<>();
for (int i = 0; i < count; i++) {
- float mult = (range + 1);
- float val = (float) (Math.random() * mult) + 3;// + (float)
- // ((mult *
- // 0.1) / 10);
- yVals.add(new Entry(i * 0.001f, val));
+ float val = (float) (Math.random() * (range + 1)) + 3;
+ values.add(new Entry(i * 0.001f, val));
}
// create a dataset and give it a type
- LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
-
+ LineDataSet set1 = new LineDataSet(values, "DataSet 1");
+
set1.setColor(Color.BLACK);
set1.setLineWidth(0.5f);
set1.setDrawValues(false);
@@ -111,14 +87,58 @@ private void setData(int count, float range) {
set1.setMode(LineDataSet.Mode.LINEAR);
set1.setDrawFilled(false);
- // create a data object with the datasets
+ // create a data object with the data sets
LineData data = new LineData(set1);
// set data
- mChart.setData(data);
-
+ chart.setData(data);
+
// get the legend (only possible after setting data)
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setEnabled(false);
}
+
+ @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/PerformanceLineChart.java"));
+ startActivity(i);
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+
+ int count = seekBarValues.getProgress() + 1000;
+ tvCount.setText(String.valueOf(count));
+
+ chart.resetTracking();
+
+ setData(count, 500f);
+
+ // redraw
+ chart.invalidate();
+ }
+
+ @Override
+ public void saveToGallery() { /* Intentionally left empty */ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {}
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java
index 0252ff8ff0..9d77dcc8b7 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java
@@ -1,9 +1,14 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
@@ -19,7 +24,6 @@
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
-import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
@@ -37,8 +41,8 @@
public class PieChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private PieChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private PieChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
@Override
@@ -48,55 +52,57 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart);
+ setTitle("PieChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
- mSeekBarX.setProgress(4);
- mSeekBarY.setProgress(10);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
+
+ seekBarX.setOnSeekBarChangeListener(this);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setUsePercentValues(true);
- mChart.getDescription().setEnabled(false);
- mChart.setExtraOffsets(5, 10, 5, 5);
+ chart = findViewById(R.id.chart1);
+ chart.setUsePercentValues(true);
+ chart.getDescription().setEnabled(false);
+ chart.setExtraOffsets(5, 10, 5, 5);
- mChart.setDragDecelerationFrictionCoef(0.95f);
+ chart.setDragDecelerationFrictionCoef(0.95f);
- 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.setRotationAngle(0);
+ chart.setRotationAngle(0);
// enable rotation of the chart by touch
- mChart.setRotationEnabled(true);
- mChart.setHighlightPerTapEnabled(true);
+ chart.setRotationEnabled(true);
+ chart.setHighlightPerTapEnabled(true);
- // mChart.setUnit(" €");
- // mChart.setDrawUnitsInChart(true);
+ // chart.setUnit(" €");
+ // chart.setDrawUnitsInChart(true);
// add a selection listener
- mChart.setOnChartValueSelectedListener(this);
+ chart.setOnChartValueSelectedListener(this);
+ seekBarX.setProgress(4);
+ seekBarY.setProgress(10);
setData(4, 100);
- mChart.animateY(1400, Easing.EaseInOutQuad);
- // mChart.spin(2000, 0, 360);
+ chart.animateY(1400, Easing.EaseInOutQuad);
+ // chart.spin(2000, 0, 360);
- mSeekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
-
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
@@ -106,9 +112,65 @@ protected void onCreate(Bundle savedInstanceState) {
l.setYOffset(0f);
// entry label styling
- mChart.setEntryLabelColor(Color.WHITE);
- mChart.setEntryLabelTypeface(mTfRegular);
- mChart.setEntryLabelTextSize(12f);
+ chart.setEntryLabelColor(Color.WHITE);
+ chart.setEntryLabelTypeface(tfRegular);
+ chart.setEntryLabelTextSize(12f);
+ }
+
+ private void setData(int count, float range) {
+ ArrayList entries = new ArrayList<>();
+
+ // NOTE: The order of the entries when being added to the entries array determines their position around the center of
+ // the chart.
+ for (int i = 0; i < count ; i++) {
+ entries.add(new PieEntry((float) ((Math.random() * range) + range / 5),
+ parties[i % parties.length],
+ getResources().getDrawable(R.drawable.star)));
+ }
+
+ PieDataSet dataSet = new PieDataSet(entries, "Election Results");
+
+ dataSet.setDrawIcons(false);
+
+ dataSet.setSliceSpace(3f);
+ dataSet.setIconsOffset(new MPPointF(0, 40));
+ dataSet.setSelectionShift(5f);
+
+ // add a lot of colors
+
+ ArrayList colors = new ArrayList<>();
+
+ for (int c : ColorTemplate.VORDIPLOM_COLORS)
+ colors.add(c);
+
+ for (int c : ColorTemplate.JOYFUL_COLORS)
+ colors.add(c);
+
+ for (int c : ColorTemplate.COLORFUL_COLORS)
+ colors.add(c);
+
+ for (int c : ColorTemplate.LIBERTY_COLORS)
+ colors.add(c);
+
+ for (int c : ColorTemplate.PASTEL_COLORS)
+ colors.add(c);
+
+ colors.add(ColorTemplate.getHoloBlue());
+
+ dataSet.setColors(colors);
+ //dataSet.setSelectionShift(0f);
+
+ PieData data = new PieData(dataSet);
+ data.setValueFormatter(new PercentFormatter());
+ data.setValueTextSize(11f);
+ data.setValueTextColor(Color.WHITE);
+ data.setValueTypeface(tfLight);
+ chart.setData(data);
+
+ // undo all highlights
+ chart.highlightValues(null);
+
+ chart.invalidate();
}
@Override
@@ -121,65 +183,74 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.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.actionToggleHole: {
- if (mChart.isDrawHoleEnabled())
- mChart.setDrawHoleEnabled(false);
+ if (chart.isDrawHoleEnabled())
+ chart.setDrawHoleEnabled(false);
else
- mChart.setDrawHoleEnabled(true);
- mChart.invalidate();
+ chart.setDrawHoleEnabled(true);
+ chart.invalidate();
break;
}
case R.id.actionDrawCenter: {
- if (mChart.isDrawCenterTextEnabled())
- mChart.setDrawCenterText(false);
+ if (chart.isDrawCenterTextEnabled())
+ chart.setDrawCenterText(false);
else
- mChart.setDrawCenterText(true);
- mChart.invalidate();
+ chart.setDrawCenterText(true);
+ chart.invalidate();
break;
}
- case R.id.actionToggleXVals: {
+ case R.id.actionToggleXValues: {
- mChart.setDrawEntryLabels(!mChart.isDrawEntryLabelsEnabled());
- mChart.invalidate();
- break;
- }
- case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
+ chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled());
+ chart.invalidate();
break;
}
case R.id.actionTogglePercent:
- mChart.setUsePercentValues(!mChart.isUsePercentValuesEnabled());
- mChart.invalidate();
+ chart.setUsePercentValues(!chart.isUsePercentValuesEnabled());
+ chart.invalidate();
break;
case R.id.animateX: {
- mChart.animateX(1400);
+ chart.animateX(1400);
break;
}
case R.id.animateY: {
- mChart.animateY(1400);
+ chart.animateY(1400);
break;
}
case R.id.animateXY: {
- mChart.animateXY(1400, 1400);
+ chart.animateXY(1400, 1400);
break;
}
case R.id.actionToggleSpin: {
- mChart.spin(1000, mChart.getRotationAngle(), mChart.getRotationAngle() + 360, Easing.EaseInCubic);
+ chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic);
+ break;
+ }
+ case R.id.actionSave: {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ saveToGallery();
+ } else {
+ requestStoragePermission(chart);
+ }
break;
}
}
@@ -189,69 +260,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvX.setText("" + (mSeekBarX.getProgress()));
- tvY.setText("" + (mSeekBarY.getProgress()));
+ tvX.setText(String.valueOf(seekBarX.getProgress()));
+ tvY.setText(String.valueOf(seekBarY.getProgress()));
- setData(mSeekBarX.getProgress(), mSeekBarY.getProgress());
+ setData(seekBarX.getProgress(), seekBarY.getProgress());
}
- private void setData(int count, float range) {
-
- float mult = range;
-
- ArrayList entries = new ArrayList();
-
- // NOTE: The order of the entries when being added to the entries array determines their position around the center of
- // the chart.
- for (int i = 0; i < count ; i++) {
- entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5),
- mParties[i % mParties.length],
- getResources().getDrawable(R.drawable.star)));
- }
-
- PieDataSet dataSet = new PieDataSet(entries, "Election Results");
-
- dataSet.setDrawIcons(false);
-
- dataSet.setSliceSpace(3f);
- dataSet.setIconsOffset(new MPPointF(0, 40));
- dataSet.setSelectionShift(5f);
-
- // add a lot of colors
-
- ArrayList colors = new ArrayList();
-
- for (int c : ColorTemplate.VORDIPLOM_COLORS)
- colors.add(c);
-
- for (int c : ColorTemplate.JOYFUL_COLORS)
- colors.add(c);
-
- for (int c : ColorTemplate.COLORFUL_COLORS)
- colors.add(c);
-
- for (int c : ColorTemplate.LIBERTY_COLORS)
- colors.add(c);
-
- for (int c : ColorTemplate.PASTEL_COLORS)
- colors.add(c);
-
- colors.add(ColorTemplate.getHoloBlue());
-
- dataSet.setColors(colors);
- //dataSet.setSelectionShift(0f);
-
- PieData data = new PieData(dataSet);
- data.setValueFormatter(new PercentFormatter());
- data.setValueTextSize(11f);
- data.setValueTextColor(Color.WHITE);
- data.setValueTypeface(mTfLight);
- mChart.setData(data);
-
- // undo all highlights
- mChart.highlightValues(null);
-
- mChart.invalidate();
+ @Override
+ public void saveToGallery() {
+ saveToGallery(chart, "PieChartActivity");
}
private SpannableString generateCenterSpannableText() {
@@ -282,14 +299,8 @@ public void onNothingSelected() {
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java
index c0199723d9..80ca82cde9 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java
@@ -1,9 +1,14 @@
package com.xxmassdeveloper.mpchartexample;
+import android.Manifest;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Bundle;
+import androidx.core.content.ContextCompat;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
@@ -35,8 +40,8 @@
public class PiePolylineChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
- private PieChart mChart;
- private SeekBar mSeekBarX, mSeekBarY;
+ private PieChart chart;
+ private SeekBar seekBarX, seekBarY;
private TextView tvX, tvY;
private Typeface tf;
@@ -48,59 +53,61 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart);
+ setTitle("PiePolylineChartActivity");
+
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
- mSeekBarX = findViewById(R.id.seekBar1);
- mSeekBarY = findViewById(R.id.seekBar2);
-
- mSeekBarY.setProgress(10);
+ seekBarX = findViewById(R.id.seekBar1);
+ seekBarY = findViewById(R.id.seekBar2);
- mSeekBarX.setOnSeekBarChangeListener(this);
- mSeekBarY.setOnSeekBarChangeListener(this);
+ seekBarX.setOnSeekBarChangeListener(this);
+ seekBarY.setOnSeekBarChangeListener(this);
- mChart = findViewById(R.id.chart1);
- mChart.setUsePercentValues(true);
- mChart.getDescription().setEnabled(false);
- mChart.setExtraOffsets(5, 10, 5, 5);
+ chart = findViewById(R.id.chart1);
+ chart.setUsePercentValues(true);
+ chart.getDescription().setEnabled(false);
+ chart.setExtraOffsets(5, 10, 5, 5);
- mChart.setDragDecelerationFrictionCoef(0.95f);
+ chart.setDragDecelerationFrictionCoef(0.95f);
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
- mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
- mChart.setCenterText(generateCenterSpannableText());
+ chart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
+ chart.setCenterText(generateCenterSpannableText());
- mChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
+ chart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
- 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.setRotationAngle(0);
+ chart.setRotationAngle(0);
// enable rotation of the chart by touch
- mChart.setRotationEnabled(true);
- mChart.setHighlightPerTapEnabled(true);
+ chart.setRotationEnabled(true);
+ chart.setHighlightPerTapEnabled(true);
- // mChart.setUnit(" €");
- // mChart.setDrawUnitsInChart(true);
+ // chart.setUnit(" €");
+ // chart.setDrawUnitsInChart(true);
// add a selection listener
- mChart.setOnChartValueSelectedListener(this);
+ chart.setOnChartValueSelectedListener(this);
+ seekBarX.setProgress(4);
+ seekBarY.setProgress(100);
setData(4, 100);
- mChart.animateY(1400, Easing.EaseInOutQuad);
- // mChart.spin(2000, 0, 360);
+ chart.animateY(1400, Easing.EaseInOutQuad);
+ // chart.spin(2000, 0, 360);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
@@ -108,89 +115,14 @@ protected void onCreate(Bundle savedInstanceState) {
l.setEnabled(false);
}
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.pie, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
-
- switch (item.getItemId()) {
- case R.id.actionToggleValues: {
- for (IDataSet> set : mChart.getData().getDataSets())
- set.setDrawValues(!set.isDrawValuesEnabled());
-
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleHole: {
- if (mChart.isDrawHoleEnabled())
- mChart.setDrawHoleEnabled(false);
- else
- mChart.setDrawHoleEnabled(true);
- mChart.invalidate();
- break;
- }
- case R.id.actionDrawCenter: {
- if (mChart.isDrawCenterTextEnabled())
- mChart.setDrawCenterText(false);
- else
- mChart.setDrawCenterText(true);
- mChart.invalidate();
- break;
- }
- case R.id.actionToggleXVals: {
-
- mChart.setDrawEntryLabels(!mChart.isDrawEntryLabelsEnabled());
- mChart.invalidate();
- break;
- }
- case R.id.actionSave: {
- // mChart.saveToGallery("title"+System.currentTimeMillis());
- mChart.saveToPath("title" + System.currentTimeMillis(), "");
- break;
- }
- case R.id.actionTogglePercent:
- mChart.setUsePercentValues(!mChart.isUsePercentValuesEnabled());
- mChart.invalidate();
- break;
- case R.id.animateX: {
- mChart.animateX(1400);
- break;
- }
- case R.id.animateY: {
- mChart.animateY(1400);
- break;
- }
- case R.id.animateXY: {
- mChart.animateXY(1400, 1400);
- break;
- }
- }
- return true;
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-
- tvX.setText("" + (mSeekBarX.getProgress()));
- tvY.setText("" + (mSeekBarY.getProgress()));
-
- setData(mSeekBarX.getProgress(), mSeekBarY.getProgress());
- }
-
private void setData(int count, float range) {
- float mult = range;
-
- ArrayList entries = new ArrayList();
+ ArrayList entries = new ArrayList<>();
// NOTE: The order of the entries when being added to the entries array determines their position around the center of
// the chart.
for (int i = 0; i < count; i++) {
- entries.add(new PieEntry((float) (Math.random() * mult) + mult / 5, mParties[i % mParties.length]));
+ entries.add(new PieEntry((float) (Math.random() * range) + range / 5, parties[i % parties.length]));
}
PieDataSet dataSet = new PieDataSet(entries, "Election Results");
@@ -199,7 +131,7 @@ private void setData(int count, float range) {
// add a lot of colors
- ArrayList colors = new ArrayList();
+ ArrayList colors = new ArrayList<>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
@@ -235,12 +167,103 @@ private void setData(int count, float range) {
data.setValueTextSize(11f);
data.setValueTextColor(Color.BLACK);
data.setValueTypeface(tf);
- mChart.setData(data);
+ chart.setData(data);
// undo all highlights
- mChart.highlightValues(null);
+ chart.highlightValues(null);
+
+ chart.invalidate();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.pie, menu);
+ return true;
+ }
- mChart.invalidate();
+ @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/PiePolylineChartActivity.java"));
+ startActivity(i);
+ break;
+ }
+ case R.id.actionToggleValues: {
+ for (IDataSet> set : chart.getData().getDataSets())
+ set.setDrawValues(!set.isDrawValuesEnabled());
+
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleHole: {
+ if (chart.isDrawHoleEnabled())
+ chart.setDrawHoleEnabled(false);
+ else
+ chart.setDrawHoleEnabled(true);
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionDrawCenter: {
+ if (chart.isDrawCenterTextEnabled())
+ chart.setDrawCenterText(false);
+ else
+ chart.setDrawCenterText(true);
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionToggleXValues: {
+
+ chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled());
+ chart.invalidate();
+ break;
+ }
+ case R.id.actionTogglePercent:
+ chart.setUsePercentValues(!chart.isUsePercentValuesEnabled());
+ chart.invalidate();
+ break;
+ case R.id.animateX: {
+ chart.animateX(1400);
+ break;
+ }
+ case R.id.animateY: {
+ chart.animateY(1400);
+ break;
+ }
+ case R.id.animateXY: {
+ chart.animateXY(1400, 1400);
+ break;
+ }
+ case R.id.actionToggleSpin: {
+ chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic);
+ 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());
+ }
+
+ @Override
+ public void saveToGallery() {
+ saveToGallery(chart, "PiePolylineChartActivity");
}
private SpannableString generateCenterSpannableText() {
@@ -271,14 +294,8 @@ public void onNothingSelected() {
}
@Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- // TODO Auto-generated method stub
-
- }
+ public void onStopTrackingTouch(SeekBar seekBar) {}
}
diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
index d354886f6e..c2a5eb3d0a 100644
--- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
+++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
@@ -1,13 +1,16 @@
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.TextView;
-import android.widget.Toast;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.RadarChart;
@@ -29,49 +32,46 @@
public class RadarChartActivity extends DemoBase {
- private RadarChart mChart;
+ private RadarChart chart;
@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);
+ setContentView(R.layout.activity_radarchart);
- TextView tv = findViewById(R.id.textView);
- tv.setTypeface(mTfLight);
- tv.setTextColor(Color.WHITE);
- tv.setBackgroundColor(Color.rgb(60, 65, 82));
+ setTitle("RadarChartActivity");
- mChart = findViewById(R.id.chart1);
- mChart.setBackgroundColor(Color.rgb(60, 65, 82));
+ chart = findViewById(R.id.chart1);
+ chart.setBackgroundColor(Color.rgb(60, 65, 82));
- mChart.getDescription().setEnabled(false);
+ chart.getDescription().setEnabled(false);
- mChart.setWebLineWidth(1f);
- mChart.setWebColor(Color.LTGRAY);
- mChart.setWebLineWidthInner(1f);
- mChart.setWebColorInner(Color.LTGRAY);
- mChart.setWebAlpha(100);
+ chart.setWebLineWidth(1f);
+ chart.setWebColor(Color.LTGRAY);
+ chart.setWebLineWidthInner(1f);
+ chart.setWebColorInner(Color.LTGRAY);
+ chart.setWebAlpha(100);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
- 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
setData();
- mChart.animateXY(1400, 1400, Easing.EaseInOutQuad);
+ chart.animateXY(1400, 1400, Easing.EaseInOutQuad);
- XAxis xAxis = mChart.getXAxis();
- xAxis.setTypeface(mTfLight);
+ XAxis xAxis = chart.getXAxis();
+ xAxis.setTypeface(tfLight);
xAxis.setTextSize(9f);
xAxis.setYOffset(0f);
xAxis.setXOffset(0f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
- private String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};
+ private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};
@Override
public String getFormattedValue(float value, AxisBase axis) {
@@ -80,25 +80,76 @@ public String getFormattedValue(float value, AxisBase axis) {
});
xAxis.setTextColor(Color.WHITE);
- YAxis yAxis = mChart.getYAxis();
- yAxis.setTypeface(mTfLight);
+ YAxis yAxis = chart.getYAxis();
+ yAxis.setTypeface(tfLight);
yAxis.setLabelCount(5, false);
yAxis.setTextSize(9f);
yAxis.setAxisMinimum(0f);
yAxis.setAxisMaximum(80f);
yAxis.setDrawLabels(false);
- Legend l = mChart.getLegend();
+ Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
- l.setTypeface(mTfLight);
+ l.setTypeface(tfLight);
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
l.setTextColor(Color.WHITE);
}
+ private void setData() {
+
+ float mul = 80;
+ float min = 20;
+ int cnt = 5;
+
+ ArrayList entries1 = new ArrayList<>();
+ ArrayList entries2 = new ArrayList<>();
+
+ // NOTE: The order of the entries when being added to the entries array determines their position around the center of
+ // the chart.
+ for (int i = 0; i < cnt; i++) {
+ float val1 = (float) (Math.random() * mul) + min;
+ entries1.add(new RadarEntry(val1));
+
+ float val2 = (float) (Math.random() * mul) + min;
+ entries2.add(new RadarEntry(val2));
+ }
+
+ RadarDataSet set1 = new RadarDataSet(entries1, "Last Week");
+ set1.setColor(Color.rgb(103, 110, 129));
+ set1.setFillColor(Color.rgb(103, 110, 129));
+ set1.setDrawFilled(true);
+ set1.setFillAlpha(180);
+ set1.setLineWidth(2f);
+ set1.setDrawHighlightCircleEnabled(true);
+ set1.setDrawHighlightIndicators(false);
+
+ RadarDataSet set2 = new RadarDataSet(entries2, "This Week");
+ set2.setColor(Color.rgb(121, 162, 175));
+ set2.setFillColor(Color.rgb(121, 162, 175));
+ set2.setDrawFilled(true);
+ set2.setFillAlpha(180);
+ set2.setLineWidth(2f);
+ set2.setDrawHighlightCircleEnabled(true);
+ set2.setDrawHighlightIndicators(false);
+
+ ArrayList sets = new ArrayList<>();
+ sets.add(set1);
+ sets.add(set2);
+
+ RadarData data = new RadarData(sets);
+ data.setValueTypeface(tfLight);
+ data.setValueTextSize(8f);
+ data.setDrawValues(false);
+ data.setValueTextColor(Color.WHITE);
+
+ chart.setData(data);
+ chart.invalidate();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.radar, menu);
@@ -109,31 +160,37 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.viewGithub: {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java"));
+ startActivity(i);
+ break;
+ }
case R.id.actionToggleValues: {
- for (IDataSet> set : mChart.getData().getDataSets())
+ for (IDataSet> set : chart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
- mChart.invalidate();
+ chart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
- if (mChart.getData() != null) {
- mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
- mChart.invalidate();
+ if (chart.getData() != null) {
+ chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
+ chart.invalidate();
}
break;
}
case R.id.actionToggleRotate: {
- if (mChart.isRotationEnabled())
- mChart.setRotationEnabled(false);
+ if (chart.isRotationEnabled())
+ chart.setRotationEnabled(false);
else
- mChart.setRotationEnabled(true);
- mChart.invalidate();
+ chart.setRotationEnabled(true);
+ chart.invalidate();
break;
}
case R.id.actionToggleFilled: {
- ArrayList sets = (ArrayList