Skip to content

Commit 8c649ed

Browse files
committed
Update build.gradle
1 parent 4a1a802 commit 8c649ed

7 files changed

Lines changed: 355 additions & 5 deletions

File tree

MPChartExample/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.xxmassdeveloper.mpchartexample"
44
android:versionCode="35"
5-
android:versionName="2.0.3" >
5+
android:versionName="2.0.5" >
66

77
<uses-sdk
88
android:minSdkVersion="8"
@@ -46,6 +46,7 @@
4646
<activity android:name="DynamicalAddingActivity"></activity>
4747
<activity android:name="RealtimeLineChartActivity"></activity>
4848
<activity android:name="CombinedChartActivity"></activity>
49+
<activity android:name="PerformanceLineChart"></activity>
4950
</application>
5051

5152
</manifest>

MPChartExample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion 16
88
targetSdkVersion 21
99
versionCode 35
10-
versionName '2.0.3'
10+
versionName '2.0.5'
1111

1212
sourceSets {
1313
main {
@@ -53,5 +53,5 @@ dependencies {
5353
//compile fileTree(dir: 'libs', include: ['*.jar'])
5454
compile project(':MPChartLib') // remove this if you only imported the example project
5555
compile 'com.android.support:appcompat-v7:21.0.3'
56-
//compile 'com.github.PhilJay:MPAndroidChart:v2.0.4'
56+
//compile 'com.github.PhilJay:MPAndroidChart:v2.0.5'
5757
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<com.github.mikephil.charting.charts.LineChart
7+
android:id="@+id/chart1"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:layout_above="@+id/seekbarValues" />
11+
12+
<SeekBar
13+
android:id="@+id/seekbarValues"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:layout_alignParentBottom="true"
17+
android:layout_alignParentLeft="true"
18+
android:layout_margin="8dp"
19+
android:layout_marginBottom="35dp"
20+
android:layout_toLeftOf="@+id/tvValueCount"
21+
android:layout_marginRight="5dp"
22+
android:max="3000"
23+
android:paddingBottom="12dp" />
24+
25+
<TextView
26+
android:id="@+id/tvValueCount"
27+
android:layout_width="50dp"
28+
android:layout_height="wrap_content"
29+
android:layout_alignBottom="@+id/seekbarValues"
30+
android:layout_alignParentRight="true"
31+
android:text="0"
32+
android:layout_marginBottom="15dp"
33+
android:layout_marginRight="10dp"
34+
android:gravity="right"
35+
android:textAppearance="?android:attr/textAppearanceMedium" />
36+
37+
</RelativeLayout>
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
2+
package com.xxmassdeveloper.mpchartexample;
3+
4+
import android.graphics.Color;
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
import android.view.Menu;
8+
import android.view.MenuItem;
9+
import android.view.WindowManager;
10+
import android.widget.SeekBar;
11+
import android.widget.SeekBar.OnSeekBarChangeListener;
12+
import android.widget.TextView;
13+
import android.widget.Toast;
14+
15+
import com.github.mikephil.charting.charts.LineChart;
16+
import com.github.mikephil.charting.components.Legend;
17+
import com.github.mikephil.charting.components.XAxis;
18+
import com.github.mikephil.charting.data.DataSet;
19+
import com.github.mikephil.charting.data.Entry;
20+
import com.github.mikephil.charting.data.LineData;
21+
import com.github.mikephil.charting.data.LineDataSet;
22+
import com.github.mikephil.charting.data.filter.Approximator;
23+
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
24+
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
25+
import com.github.mikephil.charting.utils.Highlight;
26+
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
27+
28+
import java.util.ArrayList;
29+
30+
public class PerformanceLineChart extends DemoBase implements OnSeekBarChangeListener {
31+
32+
private LineChart mChart;
33+
private SeekBar mSeekBarValues;
34+
private TextView mTvCount;
35+
36+
@Override
37+
protected void onCreate(Bundle savedInstanceState) {
38+
super.onCreate(savedInstanceState);
39+
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
40+
WindowManager.LayoutParams.FLAG_FULLSCREEN);
41+
setContentView(R.layout.activity_performance_linechart);
42+
43+
mTvCount = (TextView) findViewById(R.id.tvValueCount);
44+
mSeekBarValues = (SeekBar) findViewById(R.id.seekbarValues);
45+
mTvCount.setText("500");
46+
47+
mSeekBarValues.setProgress(500);
48+
49+
mSeekBarValues.setOnSeekBarChangeListener(this);
50+
51+
mChart = (LineChart) findViewById(R.id.chart1);
52+
mChart.setDrawGridBackground(false);
53+
54+
// no description text
55+
mChart.setDescription("");
56+
mChart.setNoDataTextDescription("You need to provide data for the chart.");
57+
58+
// disable value highlighting
59+
mChart.setHighlightEnabled(false);
60+
61+
// enable touch gestures
62+
mChart.setTouchEnabled(true);
63+
64+
// enable scaling and dragging
65+
mChart.setDragEnabled(true);
66+
mChart.setScaleEnabled(true);
67+
68+
// if disabled, scaling can be done on x- and y-axis separately
69+
mChart.setPinchZoom(false);
70+
71+
// enable/disable highlight indicators (the lines that indicate the
72+
// highlighted Entry)
73+
mChart.setHighlightIndicatorEnabled(false);
74+
75+
mChart.getAxisLeft().setDrawGridLines(false);
76+
mChart.getAxisRight().setEnabled(false);
77+
mChart.getXAxis().setDrawGridLines(false);
78+
mChart.getXAxis().setDrawAxisLine(false);
79+
80+
// dont forget to refresh the drawing
81+
mChart.invalidate();
82+
}
83+
84+
@Override
85+
public boolean onCreateOptionsMenu(Menu menu) {
86+
getMenuInflater().inflate(R.menu.line, menu);
87+
return true;
88+
}
89+
90+
@Override
91+
public boolean onOptionsItemSelected(MenuItem item) {
92+
93+
switch (item.getItemId()) {
94+
case R.id.actionToggleValues: {
95+
mChart.resetAverage();
96+
break;
97+
}
98+
case R.id.actionToggleHighlight: {
99+
if (mChart.isHighlightEnabled())
100+
mChart.setHighlightEnabled(false);
101+
else
102+
mChart.setHighlightEnabled(true);
103+
mChart.invalidate();
104+
break;
105+
}
106+
case R.id.actionToggleFilled: {
107+
108+
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
109+
.getDataSets();
110+
111+
for (LineDataSet set : sets) {
112+
if (set.isDrawFilledEnabled())
113+
set.setDrawFilled(false);
114+
else
115+
set.setDrawFilled(true);
116+
}
117+
mChart.invalidate();
118+
break;
119+
}
120+
case R.id.actionToggleCircles: {
121+
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
122+
.getDataSets();
123+
124+
for (LineDataSet set : sets) {
125+
if (set.isDrawCirclesEnabled())
126+
set.setDrawCircles(false);
127+
else
128+
set.setDrawCircles(true);
129+
}
130+
mChart.invalidate();
131+
break;
132+
}
133+
case R.id.actionToggleCubic: {
134+
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
135+
.getDataSets();
136+
137+
for (LineDataSet set : sets) {
138+
if (set.isDrawCubicEnabled())
139+
set.setDrawCubic(false);
140+
else
141+
set.setDrawCubic(true);
142+
}
143+
mChart.invalidate();
144+
break;
145+
}
146+
case R.id.actionToggleStartzero: {
147+
mChart.getAxisLeft().setStartAtZero(!mChart.getAxisLeft().isStartAtZeroEnabled());
148+
mChart.getAxisRight().setStartAtZero(!mChart.getAxisRight().isStartAtZeroEnabled());
149+
mChart.invalidate();
150+
break;
151+
}
152+
case R.id.actionTogglePinch: {
153+
if (mChart.isPinchZoomEnabled())
154+
mChart.setPinchZoom(false);
155+
else
156+
mChart.setPinchZoom(true);
157+
158+
mChart.invalidate();
159+
break;
160+
}
161+
case R.id.animateX: {
162+
mChart.animateX(3000);
163+
break;
164+
}
165+
case R.id.animateY: {
166+
mChart.animateY(3000);
167+
break;
168+
}
169+
case R.id.animateXY: {
170+
mChart.animateXY(3000, 3000);
171+
break;
172+
}
173+
case R.id.actionToggleAdjustXLegend: {
174+
XAxis xLabels = mChart.getXAxis();
175+
176+
if (xLabels.isAdjustXLabelsEnabled())
177+
xLabels.setAdjustXLabels(false);
178+
else
179+
xLabels.setAdjustXLabels(true);
180+
181+
mChart.invalidate();
182+
break;
183+
}
184+
case R.id.actionToggleFilter: {
185+
186+
// the angle of filtering is 35°
187+
Approximator a = new Approximator(ApproximatorType.DOUGLAS_PEUCKER, 35);
188+
189+
if (!mChart.isFilteringEnabled()) {
190+
mChart.enableFiltering(a);
191+
} else {
192+
mChart.disableFiltering();
193+
}
194+
mChart.invalidate();
195+
196+
//
197+
// for(int i = 0; i < 10; i++) {
198+
// mChart.addEntry(new Entry((float) (Math.random() * 100),
199+
// i+2), 0);
200+
// mChart.invalidate();
201+
// }
202+
//
203+
// Toast.makeText(getApplicationContext(), "valcount: " +
204+
// mChart.getDataOriginal().getYValCount() + ", valsum: " +
205+
// mChart.getDataOriginal().getYValueSum(),
206+
// Toast.LENGTH_SHORT).show();
207+
//
208+
break;
209+
}
210+
case R.id.actionSave: {
211+
if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) {
212+
Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
213+
Toast.LENGTH_SHORT).show();
214+
} else
215+
Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
216+
.show();
217+
218+
// mChart.saveToGallery("title"+System.currentTimeMillis())
219+
break;
220+
}
221+
}
222+
return true;
223+
}
224+
225+
@Override
226+
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
227+
228+
mTvCount.setText("" + (mSeekBarValues.getProgress()));
229+
230+
setData(mSeekBarValues.getProgress(), 500f);
231+
232+
// redraw
233+
mChart.invalidate();
234+
}
235+
236+
@Override
237+
public void onStartTrackingTouch(SeekBar seekBar) {
238+
// TODO Auto-generated method stub
239+
240+
}
241+
242+
@Override
243+
public void onStopTrackingTouch(SeekBar seekBar) {
244+
// TODO Auto-generated method stub
245+
246+
}
247+
248+
private void setData(int count, float range) {
249+
250+
ArrayList<String> xVals = new ArrayList<String>();
251+
for (int i = 0; i < count; i++) {
252+
xVals.add((i) + "");
253+
}
254+
255+
ArrayList<Entry> yVals = new ArrayList<Entry>();
256+
257+
for (int i = 0; i < count; i++) {
258+
float mult = (range + 1);
259+
float val = (float) (Math.random() * mult) + 3;// + (float)
260+
// ((mult *
261+
// 0.1) / 10);
262+
yVals.add(new Entry(val, i));
263+
}
264+
265+
// create a dataset and give it a type
266+
LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
267+
268+
set1.setColor(Color.BLACK);
269+
set1.setLineWidth(1f);
270+
set1.setDrawValues(false);
271+
set1.setDrawCircles(false);
272+
273+
// create a data object with the datasets
274+
LineData data = new LineData(xVals, set1);
275+
276+
// set data
277+
mChart.setData(data);
278+
279+
// get the legend (only possible after setting data)
280+
Legend l = mChart.getLegend();
281+
l.setEnabled(false);
282+
}
283+
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.xxmassdeveloper.mpchartexample.ListViewBarChartActivity;
3636
import com.xxmassdeveloper.mpchartexample.ListViewMultiChartActivity;
3737
import com.xxmassdeveloper.mpchartexample.MultiLineChartActivity;
38+
import com.xxmassdeveloper.mpchartexample.PerformanceLineChart;
3839
import com.xxmassdeveloper.mpchartexample.PieChartActivity;
3940
import com.xxmassdeveloper.mpchartexample.R;
4041
import com.xxmassdeveloper.mpchartexample.RadarChartActivitry;
@@ -110,6 +111,9 @@ protected void onCreate(Bundle savedInstanceState) {
110111
objects.add(new ContentItem(
111112
"Dynamical data adding",
112113
"This Activity demonstrates dynamical adding of Entries and DataSets (real time graph)."));
114+
// objects.add(new ContentItem(
115+
// "Performance Line Chart",
116+
// "Renders up to 3000 objects."));
113117

114118
MyAdapter adapter = new MyAdapter(this, objects);
115119

@@ -219,6 +223,10 @@ public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
219223
i = new Intent(this, DynamicalAddingActivity.class);
220224
startActivity(i);
221225
break;
226+
case 22:
227+
i = new Intent(this, PerformanceLineChart.class);
228+
startActivity(i);
229+
break;
222230
}
223231

224232
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);

MPChartLib/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ dependencies {
3737
//compile 'com.nineoldandroids:library:2.4.+'
3838
}
3939

40+
android.libraryVariants.all { variant ->
41+
def name = variant.buildType.name
42+
def task = project.tasks.create "jar${name.capitalize()}", Jar
43+
task.dependsOn variant.javaCompile
44+
task.from variant.javaCompile.destinationDir
45+
artifacts.add('archives', task);
46+
}
47+
4048
task sourcesJar(type: Jar) {
4149
from android.sourceSets.main.java.srcDirs
4250
classifier = 'sources'

0 commit comments

Comments
 (0)