-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor improvements and changes to the arcitecture.
- Loading branch information
Showing
10 changed files
with
395 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,3 @@ | |
|
||
# Project target. | ||
target=android-19 | ||
android.library.reference.1=../MPChartLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
328 changes: 328 additions & 0 deletions
328
MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,328 @@ | ||
|
||
package com.xxmassdeveloper.mpchartexample; | ||
|
||
import android.graphics.Color; | ||
import android.graphics.Typeface; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.WindowManager; | ||
import android.widget.SeekBar; | ||
import android.widget.SeekBar.OnSeekBarChangeListener; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.github.mikephil.charting.charts.BarLineChartBase.BorderPosition; | ||
import com.github.mikephil.charting.charts.LineChart; | ||
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.data.filter.Approximator; | ||
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType; | ||
import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener; | ||
import com.github.mikephil.charting.utils.ColorTemplate; | ||
import com.github.mikephil.charting.utils.Legend; | ||
import com.github.mikephil.charting.utils.Legend.LegendForm; | ||
import com.github.mikephil.charting.utils.XLabels; | ||
import com.github.mikephil.charting.utils.YLabels; | ||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListener, | ||
OnChartValueSelectedListener { | ||
|
||
private LineChart mChart; | ||
private SeekBar mSeekBarX, mSeekBarY; | ||
private TextView tvX, tvY; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
setContentView(R.layout.activity_linechart); | ||
|
||
tvX = (TextView) findViewById(R.id.tvXMax); | ||
tvY = (TextView) findViewById(R.id.tvYMax); | ||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); | ||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); | ||
|
||
mSeekBarX.setProgress(45); | ||
mSeekBarY.setProgress(100); | ||
|
||
mSeekBarY.setOnSeekBarChangeListener(this); | ||
mSeekBarX.setOnSeekBarChangeListener(this); | ||
|
||
mChart = (LineChart) findViewById(R.id.chart1); | ||
mChart.setOnChartValueSelectedListener(this); | ||
|
||
mChart.setUnit(" $"); | ||
mChart.setDrawUnitsInChart(true); | ||
|
||
// if enabled, the chart will always start at zero on the y-axis | ||
mChart.setStartAtZero(false); | ||
|
||
// disable the drawing of values into the chart | ||
mChart.setDrawYValues(false); | ||
|
||
mChart.setDrawBorder(true); | ||
mChart.setBorderPositions(new BorderPosition[] { | ||
BorderPosition.BOTTOM | ||
}); | ||
|
||
// no description text | ||
mChart.setDescription(""); | ||
mChart.setNoDataTextDescription("You need to provide data for the chart."); | ||
|
||
// enable value highlighting | ||
mChart.setHighlightEnabled(true); | ||
|
||
// enable touch gestures | ||
mChart.setTouchEnabled(true); | ||
|
||
// enable scaling and dragging | ||
mChart.setDragEnabled(true); | ||
mChart.setScaleEnabled(true); | ||
mChart.setDrawGridBackground(false); | ||
mChart.setDrawVerticalGrid(false); | ||
mChart.setDrawHorizontalGrid(false); | ||
|
||
// if disabled, scaling can be done on x- and y-axis separately | ||
mChart.setPinchZoom(true); | ||
|
||
// set an alternative background color | ||
mChart.setBackgroundColor(Color.GRAY); | ||
|
||
// add data | ||
setData(45, 100); | ||
|
||
mChart.animateX(2500); | ||
|
||
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | ||
|
||
// get the legend (only possible after setting data) | ||
Legend l = mChart.getLegend(); | ||
|
||
// modify the legend ... | ||
// l.setPosition(LegendPosition.LEFT_OF_CHART); | ||
l.setForm(LegendForm.LINE); | ||
l.setTypeface(tf); | ||
l.setTextColor(Color.WHITE); | ||
|
||
XLabels xl = mChart.getXLabels(); | ||
xl.setTypeface(tf); | ||
xl.setTextColor(Color.WHITE); | ||
|
||
YLabels yl = mChart.getYLabels(); | ||
yl.setTypeface(tf); | ||
yl.setTextColor(Color.WHITE); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.line, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
|
||
switch (item.getItemId()) { | ||
case R.id.actionToggleValues: { | ||
if (mChart.isDrawYValuesEnabled()) | ||
mChart.setDrawYValues(false); | ||
else | ||
mChart.setDrawYValues(true); | ||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionToggleHighlight: { | ||
if (mChart.isHighlightEnabled()) | ||
mChart.setHighlightEnabled(false); | ||
else | ||
mChart.setHighlightEnabled(true); | ||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionToggleFilled: { | ||
|
||
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData() | ||
.getDataSets(); | ||
|
||
for (LineDataSet set : sets) { | ||
if (set.isDrawFilledEnabled()) | ||
set.setDrawFilled(false); | ||
else | ||
set.setDrawFilled(true); | ||
} | ||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionToggleCircles: { | ||
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData() | ||
.getDataSets(); | ||
|
||
for (LineDataSet set : sets) { | ||
if (set.isDrawCirclesEnabled()) | ||
set.setDrawCircles(false); | ||
else | ||
set.setDrawCircles(true); | ||
} | ||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionToggleCubic: { | ||
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData() | ||
.getDataSets(); | ||
|
||
for (LineDataSet set : sets) { | ||
if (set.isDrawCubicEnabled()) | ||
set.setDrawCubic(false); | ||
else | ||
set.setDrawCubic(true); | ||
} | ||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionToggleStartzero: { | ||
if (mChart.isStartAtZeroEnabled()) | ||
mChart.setStartAtZero(false); | ||
else | ||
mChart.setStartAtZero(true); | ||
|
||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionTogglePinch: { | ||
if (mChart.isPinchZoomEnabled()) | ||
mChart.setPinchZoom(false); | ||
else | ||
mChart.setPinchZoom(true); | ||
|
||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.animateX: { | ||
mChart.animateX(3000); | ||
break; | ||
} | ||
case R.id.animateY: { | ||
mChart.animateY(3000); | ||
break; | ||
} | ||
case R.id.animateXY: { | ||
mChart.animateXY(3000, 3000); | ||
break; | ||
} | ||
case R.id.actionToggleAdjustXLegend: { | ||
XLabels xLabels = mChart.getXLabels(); | ||
|
||
if (xLabels.isAdjustXLabelsEnabled()) | ||
xLabels.setAdjustXLabels(false); | ||
else | ||
xLabels.setAdjustXLabels(true); | ||
|
||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionToggleFilter: { | ||
|
||
// the angle of filtering is 35° | ||
Approximator a = new Approximator(ApproximatorType.DOUGLAS_PEUCKER, 35); | ||
|
||
if (!mChart.isFilteringEnabled()) { | ||
mChart.enableFiltering(a); | ||
} else { | ||
mChart.disableFiltering(); | ||
} | ||
mChart.invalidate(); | ||
break; | ||
} | ||
case R.id.actionSave: { | ||
if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) { | ||
Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!", | ||
Toast.LENGTH_SHORT).show(); | ||
} else | ||
Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT) | ||
.show(); | ||
|
||
// mChart.saveToGallery("title"+System.currentTimeMillis()) | ||
break; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | ||
|
||
tvX.setText("" + (mSeekBarX.getProgress() + 1)); | ||
tvY.setText("" + (mSeekBarY.getProgress())); | ||
|
||
setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress()); | ||
|
||
// redraw | ||
mChart.invalidate(); | ||
} | ||
|
||
private void setData(int count, float range) { | ||
|
||
ArrayList<String> xVals = new ArrayList<String>(); | ||
for (int i = 0; i < count; i++) { | ||
xVals.add((i) + ""); | ||
} | ||
|
||
ArrayList<Entry> yVals = new ArrayList<Entry>(); | ||
|
||
for (int i = 0; i < count; i++) { | ||
float mult = (range + 1); | ||
float val = (float) (Math.random() * mult) + 3;// + (float) | ||
// ((mult * | ||
// 0.1) / 10); | ||
yVals.add(new Entry(val, i)); | ||
} | ||
|
||
// create a dataset and give it a type | ||
LineDataSet set1 = new LineDataSet(yVals, "DataSet 1"); | ||
set1.setColor(ColorTemplate.getHoloBlue()); | ||
set1.setCircleColor(ColorTemplate.getHoloBlue()); | ||
set1.setLineWidth(2f); | ||
set1.setCircleSize(4f); | ||
set1.setFillAlpha(65); | ||
set1.setFillColor(ColorTemplate.getHoloBlue()); | ||
set1.setHighLightColor(Color.rgb(244, 117, 117)); | ||
|
||
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); | ||
dataSets.add(set1); // add the datasets | ||
|
||
// create a data object with the datasets | ||
LineData data = new LineData(xVals, dataSets); | ||
|
||
// set data | ||
mChart.setData(data); | ||
} | ||
|
||
@Override | ||
public void onValueSelected(Entry e, int dataSetIndex) { | ||
Log.i("Entry selected", e.toString()); | ||
} | ||
|
||
@Override | ||
public void onNothingSelected() { | ||
Log.i("Nothing selected", "Nothing selected."); | ||
} | ||
|
||
@Override | ||
public void onStartTrackingTouch(SeekBar seekBar) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void onStopTrackingTouch(SeekBar seekBar) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
} |
Oops, something went wrong.
@PhilJay I wonder if you increased the versions in
MPChartExample/build.gradle
on purpose? IMHO you should update the versions ofMPChartLib/build.gradle
instead since theMPChartLib
folder contains the source code of the library. The version information will be used and published when you deploy the library to MavenLocal, MavenCentral or jCenter. Therefore, it is not correct when the library is still at version 1.0.Further, please do not maintain version information both in
AndroidManifest.xml
andbuild.gradle
. The later overwrites the values anyways - so just remove version information fromAndroidManifest.xml
.The example application can however be versioned, too - not necessarily using the same version name and code.