Improvements in the example project.
This commit is contained in:
parent
34fe3c547b
commit
f179354e23
20 changed files with 294 additions and 228 deletions
|
@ -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="2"
|
||||
android:versionName="1.0.2" >
|
||||
android:versionCode="4"
|
||||
android:versionName="1.0.4" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9"
|
||||
|
@ -15,7 +15,7 @@
|
|||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name="com.xxmassdeveloper.mpchartexample.MainActivity"
|
||||
android:name="com.xxmassdeveloper.mpchartexample.notimportant.MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
7
MPChartExample/res/anim/move_left_in_activity.xml
Normal file
7
MPChartExample/res/anim/move_left_in_activity.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<translate
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="300"
|
||||
android:fromXDelta="-100%p"
|
||||
android:toXDelta="0%p">
|
||||
</translate>
|
7
MPChartExample/res/anim/move_left_out_activity.xml
Normal file
7
MPChartExample/res/anim/move_left_out_activity.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<translate
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="300"
|
||||
android:fromXDelta="0%p"
|
||||
android:toXDelta="-100%p">
|
||||
</translate>
|
7
MPChartExample/res/anim/move_right_in_activity.xml
Normal file
7
MPChartExample/res/anim/move_right_in_activity.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<translate
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="300"
|
||||
android:fromXDelta="100%p"
|
||||
android:toXDelta="0%p">
|
||||
</translate>
|
7
MPChartExample/res/anim/move_right_out_activity.xml
Normal file
7
MPChartExample/res/anim/move_right_out_activity.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<translate
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="300"
|
||||
android:fromXDelta="0%p"
|
||||
android:toXDelta="100%p">
|
||||
</translate>
|
|
@ -1,76 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/listView1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/button1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="LineChart" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="BarChart" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="PieChart" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="ScatterChart" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="LineChart (more datasets)" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="BarChart (more datasets)" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button7"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="Draw Chart" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button8"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="AWESOME DESIGN" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
||||
</ListView>
|
27
MPChartExample/res/layout/list_item.xml
Normal file
27
MPChartExample/res/layout/list_item.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:text="Medium Text"
|
||||
android:textSize="16dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDesc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/tvName"
|
||||
android:layout_below="@+id/tvName"
|
||||
android:layout_marginTop="3dp"
|
||||
android:text="Small Text"
|
||||
android:textSize="12dp" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -23,10 +22,11 @@ import com.github.mikephil.charting.utils.XLabels;
|
|||
import com.github.mikephil.charting.utils.XLabels.XLabelPosition;
|
||||
import com.github.mikephil.charting.utils.YLabels;
|
||||
import com.github.mikephil.charting.utils.YLabels.YLabelPosition;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BarChartActivity extends Activity implements OnSeekBarChangeListener {
|
||||
public class BarChartActivity extends DemoBase implements OnSeekBarChangeListener {
|
||||
|
||||
private BarChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -16,15 +15,13 @@ import com.github.mikephil.charting.data.DataSet;
|
|||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Legend;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.github.mikephil.charting.utils.Legend.LegendPosition;
|
||||
import com.github.mikephil.charting.utils.XLabels.XLabelPosition;
|
||||
import com.github.mikephil.charting.utils.YLabels.YLabelPosition;
|
||||
import com.github.mikephil.charting.utils.YLabels;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BarChartActivityMultiDataset extends Activity implements OnSeekBarChangeListener {
|
||||
public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarChangeListener {
|
||||
|
||||
private BarChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -18,6 +17,7 @@ import com.github.mikephil.charting.interfaces.OnDrawListener;
|
|||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Highlight;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -27,7 +27,7 @@ import java.util.ArrayList;
|
|||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class DrawChartActivity extends Activity implements OnChartValueSelectedListener,
|
||||
public class DrawChartActivity extends DemoBase implements OnChartValueSelectedListener,
|
||||
OnDrawListener {
|
||||
|
||||
private LineChart mChart;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -22,12 +21,13 @@ import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener;
|
|||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Highlight;
|
||||
import com.github.mikephil.charting.utils.Legend;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.github.mikephil.charting.utils.Legend.LegendForm;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LineChartActivity extends Activity implements OnSeekBarChangeListener,
|
||||
public class LineChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
private LineChart mChart;
|
||||
|
@ -127,11 +127,11 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
// add data
|
||||
setData(45, 100);
|
||||
|
||||
// restrain the maximum scale-out factor
|
||||
mChart.setScaleMinima(3f, 3f);
|
||||
|
||||
// center the view to a specific position inside the chart
|
||||
mChart.centerViewPort(10, 50);
|
||||
// // restrain the maximum scale-out factor
|
||||
// mChart.setScaleMinima(3f, 3f);
|
||||
//
|
||||
// // center the view to a specific position inside the chart
|
||||
// mChart.centerViewPort(10, 50);
|
||||
|
||||
// get the legend (only possible after setting data)
|
||||
Legend l = mChart.getLegend();
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo;
|
||||
|
||||
public class MainActivity extends Activity implements OnClickListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Button btn1 = (Button) findViewById(R.id.button1);
|
||||
Button btn2 = (Button) findViewById(R.id.button2);
|
||||
Button btn3 = (Button) findViewById(R.id.button3);
|
||||
Button btn4 = (Button) findViewById(R.id.button4);
|
||||
Button btn5 = (Button) findViewById(R.id.button5);
|
||||
Button btn6 = (Button) findViewById(R.id.button6);
|
||||
Button btn7 = (Button) findViewById(R.id.button7);
|
||||
Button btn8 = (Button) findViewById(R.id.button8);
|
||||
btn1.setOnClickListener(this);
|
||||
btn2.setOnClickListener(this);
|
||||
btn3.setOnClickListener(this);
|
||||
btn4.setOnClickListener(this);
|
||||
btn5.setOnClickListener(this);
|
||||
btn6.setOnClickListener(this);
|
||||
btn7.setOnClickListener(this);
|
||||
btn8.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Intent i;
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.button1:
|
||||
i = new Intent(this, LineChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button2:
|
||||
i = new Intent(this, BarChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button3:
|
||||
i = new Intent(this, PieChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button4:
|
||||
i = new Intent(this, MultiLineChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button5:
|
||||
i = new Intent(this, BarChartActivityMultiDataset.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button6:
|
||||
i = new Intent(this, ScatterChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button7:
|
||||
i = new Intent(this, DrawChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button8:
|
||||
i = new Intent(this, SimpleChartDemo.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
Intent i = null;
|
||||
|
||||
switch(item.getItemId()) {
|
||||
case R.id.viewGithub:
|
||||
i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart"));
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.report:
|
||||
i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
|
||||
"mailto","philjay.librarysup@gmail.com", null));
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, "MPAndroidChart Issue");
|
||||
i.putExtra(Intent.EXTRA_TEXT, "Your error report here...");
|
||||
startActivity(Intent.createChooser(i, "Report Problem"));
|
||||
break;
|
||||
case R.id.website:
|
||||
i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("http://www.xxmassdeveloper.com"));
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -20,13 +19,12 @@ 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.Highlight;
|
||||
import com.github.mikephil.charting.utils.Legend;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.github.mikephil.charting.utils.Legend.LegendPosition;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MultiLineChartActivity extends Activity implements OnSeekBarChangeListener,
|
||||
public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
private LineChart mChart;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -19,10 +18,11 @@ import com.github.mikephil.charting.utils.ColorTemplate;
|
|||
import com.github.mikephil.charting.utils.Highlight;
|
||||
import com.github.mikephil.charting.utils.Legend;
|
||||
import com.github.mikephil.charting.utils.Legend.LegendPosition;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PieChartActivity extends Activity implements OnSeekBarChangeListener, OnChartValueSelectedListener {
|
||||
public class PieChartActivity extends DemoBase implements OnSeekBarChangeListener, OnChartValueSelectedListener {
|
||||
|
||||
private PieChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -22,10 +21,11 @@ import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener;
|
|||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Highlight;
|
||||
import com.github.mikephil.charting.utils.XLabels;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ScatterChartActivity extends Activity implements OnSeekBarChangeListener,
|
||||
public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
private ScatterChart mChart;
|
||||
|
|
|
@ -6,20 +6,20 @@ import android.content.DialogInterface;
|
|||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
/**
|
||||
* Demonstrates how to keep your charts straight forward, simple and beautiful with the MPAndroidChart library.
|
||||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class SimpleChartDemo extends FragmentActivity {
|
||||
public class SimpleChartDemo extends DemoBase {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.xxmassdeveloper.mpchartexample.notimportant;
|
||||
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
public abstract class DemoBase extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
overridePendingTransition(R.anim.move_left_in_activity, R.anim.move_right_out_activity);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample.notimportant;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.xxmassdeveloper.mpchartexample.BarChartActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.BarChartActivityMultiDataset;
|
||||
import com.xxmassdeveloper.mpchartexample.DrawChartActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.LineChartActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.MultiLineChartActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.PieChartActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.ScatterChartActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends Activity implements OnItemClickListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
ArrayList<ContentItem> objects = new ArrayList<ContentItem>();
|
||||
|
||||
objects.add(new ContentItem("Line Chart", "A simple demonstration of the linechart."));
|
||||
objects.add(new ContentItem("Bar Chart", "A simple demonstration of the bar chart."));
|
||||
objects.add(new ContentItem("Pie Chart", "A simple demonstration of the pie chart."));
|
||||
objects.add(new ContentItem("Scatter Chart", "A simple demonstration of the scatter chart."));
|
||||
objects.add(new ContentItem("Multiple Lines Chart",
|
||||
"A line chart with multiple DataSet objects. One color per DataSet."));
|
||||
objects.add(new ContentItem("Multiple Bars Chart",
|
||||
"A bar chart with multiple DataSet objects. One multiple colors per DataSet."));
|
||||
objects.add(new ContentItem("Draw Chart",
|
||||
"Demonstration of drawing values into the chart per touch-gesture. With callbacks."));
|
||||
objects.add(new ContentItem(
|
||||
"Charts in Fragments, awesome design.",
|
||||
"Demonstration of charts inside Fragments. In this example the focus was on the design and look and feel of the chart."));
|
||||
|
||||
MyAdapter adapter = new MyAdapter(this, objects);
|
||||
|
||||
ListView lv = (ListView) findViewById(R.id.listView1);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
lv.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
|
||||
|
||||
Intent i;
|
||||
|
||||
switch (pos) {
|
||||
case 0:
|
||||
i = new Intent(this, LineChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 1:
|
||||
i = new Intent(this, BarChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 2:
|
||||
i = new Intent(this, PieChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 3:
|
||||
i = new Intent(this, ScatterChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 4:
|
||||
i = new Intent(this, MultiLineChartActivity.class);
|
||||
startActivity(i);
|
||||
|
||||
break;
|
||||
case 5:
|
||||
i = new Intent(this, BarChartActivityMultiDataset.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 6:
|
||||
i = new Intent(this, DrawChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 7:
|
||||
i = new Intent(this, SimpleChartDemo.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
|
||||
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
Intent i = null;
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.viewGithub:
|
||||
i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart"));
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.report:
|
||||
i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
|
||||
"mailto", "philjay.librarysup@gmail.com", null));
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, "MPAndroidChart Issue");
|
||||
i.putExtra(Intent.EXTRA_TEXT, "Your error report here...");
|
||||
startActivity(Intent.createChooser(i, "Report Problem"));
|
||||
break;
|
||||
case R.id.website:
|
||||
i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("http://www.xxmassdeveloper.com"));
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class ContentItem {
|
||||
String name;
|
||||
String desc;
|
||||
|
||||
public ContentItem(String n, String d) {
|
||||
name = n;
|
||||
desc = d;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyAdapter extends ArrayAdapter<ContentItem> {
|
||||
|
||||
public MyAdapter(Context context, List<ContentItem> objects) {
|
||||
super(context, 0, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
|
||||
ContentItem c = getItem(position);
|
||||
|
||||
ViewHolder holder = null;
|
||||
|
||||
if (convertView == null) {
|
||||
|
||||
holder = new ViewHolder();
|
||||
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
|
||||
holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
|
||||
holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
|
||||
|
||||
convertView.setTag(holder);
|
||||
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.tvName.setText(c.name);
|
||||
holder.tvDesc.setText(c.desc);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
|
||||
TextView tvName, tvDesc;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -501,14 +501,14 @@ public abstract class BarLineChartBase extends Chart {
|
|||
|
||||
// additional handling for space (default 10% space), spacing only
|
||||
// applies with non-rounded y-label
|
||||
float space = mDeltaY / 100f * 10f;
|
||||
float space = mDeltaY / 100f * 10f;
|
||||
|
||||
if (mStartAtZero) {
|
||||
mYChartMin = 0;
|
||||
} else {
|
||||
mYChartMin = mYChartMin - space;
|
||||
}
|
||||
|
||||
|
||||
// calc delta
|
||||
mYChartMax = mYChartMax + space;
|
||||
mDeltaY = Math.abs(mYChartMax - mYChartMin);
|
||||
|
|
|
@ -350,15 +350,10 @@ public abstract class Chart extends View {
|
|||
if (!fixedValues) {
|
||||
mYChartMin = mCurrentData.getYMin();
|
||||
mYChartMax = mCurrentData.getYMax();
|
||||
|
||||
if(mYChartMin == mYChartMax) {
|
||||
mYChartMin--;
|
||||
mYChartMax++;
|
||||
}
|
||||
}
|
||||
|
||||
// calc delta
|
||||
mDeltaY = Math.abs(mCurrentData.getYMax() - mCurrentData.getYMin());
|
||||
mDeltaY = Math.abs(mYChartMax - mYChartMin);
|
||||
mDeltaX = mCurrentData.getXVals().size() - 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue