Skip to content

Commit

Permalink
Minor improvements and changes to the arcitecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Nov 18, 2014
1 parent 86f7770 commit 7ad2cc5
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 32 deletions.
7 changes: 4 additions & 3 deletions MPChartExample/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxmassdeveloper.mpchartexample"
android:versionCode="28"
android:versionName="1.7.1" >
android:versionCode="29"
android:versionName="1.7.4" >

<uses-sdk
android:minSdkVersion="8"
Expand All @@ -23,7 +23,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="LineChartActivity"></activity>
<activity android:name="LineChartActivity1"></activity>
<activity android:name="LineChartActivity2"></activity>
<activity android:screenOrientation="landscape" android:name="MultipleChartsActivity"></activity>
<activity android:name="BarChartActivity"></activity>
<activity android:name="PieChartActivity"></activity>
Expand Down
4 changes: 2 additions & 2 deletions MPChartExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.xxmassdeveloper.mpchartexample'
minSdkVersion 16
targetSdkVersion 19
versionCode 28
versionName '1.7.1'
versionCode 29

This comment has been minimized.

Copy link
@johnjohndoe

johnjohndoe Feb 3, 2015

@PhilJay I wonder if you increased the versions in MPChartExample/build.gradle on purpose? IMHO you should update the versions of MPChartLib/build.gradle instead since the MPChartLib 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 and build.gradle. The later overwrites the values anyways - so just remove version information from AndroidManifest.xml.

The example application can however be versioned, too - not necessarily using the same version name and code.

versionName '1.7.4'

sourceSets {
main {
Expand Down
Binary file not shown.
1 change: 0 additions & 1 deletion MPChartExample/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@

# Project target.
target=android-19
android.library.reference.1=../MPChartLib
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import java.util.ArrayList;

public class LineChartActivity extends DemoBase implements OnSeekBarChangeListener,
public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListener,
OnChartGestureListener, OnChartValueSelectedListener {

private LineChart mChart;
Expand Down
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

}
}
Loading

0 comments on commit 7ad2cc5

Please sign in to comment.