Improved and cleaned up the example project, added documentation.
This commit is contained in:
parent
15df9ff505
commit
fbc5324d87
24 changed files with 3610 additions and 3594 deletions
|
@ -18,7 +18,7 @@
|
|||
android:layout_margin="8dp"
|
||||
android:layout_toLeftOf="@+id/tvYMax"
|
||||
android:layout_marginRight="5dp"
|
||||
android:max="2000"
|
||||
android:max="200"
|
||||
android:paddingBottom="12dp" />
|
||||
|
||||
<SeekBar
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
android:layout_margin="8dp"
|
||||
android:layout_toLeftOf="@+id/tvYMax"
|
||||
android:layout_marginRight="5dp"
|
||||
android:max="2000"
|
||||
android:max="200"
|
||||
android:paddingBottom="12dp" />
|
||||
|
||||
<SeekBar
|
||||
|
|
|
@ -36,7 +36,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="PieChart" />
|
||||
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"
|
||||
|
@ -52,33 +59,13 @@
|
|||
android:layout_margin="4dp"
|
||||
android:text="BarChart (more datasets)" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="MultipleCharts" />
|
||||
|
||||
<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="View on GitHub" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button9"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="ScatterChart" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/barChart1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/barChart2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical" >
|
||||
|
||||
com.github.mikephil.charting.charts.PieChartieChart
|
||||
android:id="@+id/pieChart1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/barChart4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -18,7 +18,7 @@
|
|||
android:layout_margin="8dp"
|
||||
android:layout_toLeftOf="@+id/tvYMax"
|
||||
android:layout_marginRight="5dp"
|
||||
android:max="300"
|
||||
android:max="200"
|
||||
android:paddingBottom="12dp" />
|
||||
|
||||
<SeekBar
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
android:layout_margin="8dp"
|
||||
android:layout_toLeftOf="@+id/tvYMax"
|
||||
android:layout_marginRight="5dp"
|
||||
android:max="2000"
|
||||
android:max="200"
|
||||
android:paddingBottom="12dp" />
|
||||
|
||||
<SeekBar
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/actionToggleRound" android:title="Toggle Round"></item>
|
||||
<item android:id="@+id/actionToggleValues" android:title="Toggle Values"></item>
|
||||
<item android:id="@+id/actionToggleFilled" android:title="Toggle Filled"></item>
|
||||
<item android:id="@+id/actionToggleHighlight" android:title="Toggle Highlight"></item>
|
||||
<item android:id="@+id/actionToggleHighlightArrow" android:title="Toggle Highlight Arrow"></item>
|
||||
<item android:id="@+id/actionToggle3D" android:title="Toggle 3D"></item>
|
||||
|
@ -13,4 +11,8 @@
|
|||
android:title="Toggle filter">
|
||||
</item>
|
||||
<item android:id="@+id/actionSave" android:title="Save to Gallery"></item>
|
||||
<item
|
||||
android:id="@+id/actionTogglePinch"
|
||||
android:title="Toggle PinchZoom">
|
||||
</item>
|
||||
</menu>
|
||||
|
|
40
MPChartExample/res/menu/draw.xml
Normal file
40
MPChartExample/res/menu/draw.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionToggleValues"
|
||||
android:title="Toggle Values">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleFilled"
|
||||
android:title="Toggle Filled">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleCircles"
|
||||
android:title="Toggle Circles">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleHighlight"
|
||||
android:title="Toggle Highlight">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleStartzero"
|
||||
android:title="Toggle StartZero">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleAdjustXLegend"
|
||||
android:title="Toggle AdjustXLegend">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleFilter"
|
||||
android:title="Toggle filter">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionSave"
|
||||
android:title="Save to Gallery">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionTogglePinch"
|
||||
android:title="Toggle PinchZoom">
|
||||
</item>
|
||||
</menu>
|
|
@ -1,10 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionToggleRound"
|
||||
android:title="Toggle Round">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleValues"
|
||||
android:title="Toggle Values">
|
||||
|
@ -37,5 +33,8 @@
|
|||
android:id="@+id/actionSave"
|
||||
android:title="Save to Gallery">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionTogglePinch"
|
||||
android:title="Toggle PinchZoom">
|
||||
</item>
|
||||
</menu>
|
|
@ -1,10 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/actionToggleRound"
|
||||
android:title="Toggle Round">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/actionToggleValues"
|
||||
android:title="Toggle Values">
|
||||
|
@ -29,5 +25,8 @@
|
|||
android:id="@+id/actionSave"
|
||||
android:title="Save to Gallery">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionTogglePinch"
|
||||
android:title="Toggle PinchZoom">
|
||||
</item>
|
||||
</menu>
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.example.mpchartexample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -18,167 +19,181 @@ import com.github.mikephil.charting.data.Entry;
|
|||
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
|
||||
|
||||
public class BarChartActivity extends Activity implements OnSeekBarChangeListener {
|
||||
|
||||
private BarChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
private TextView tvX, tvY;
|
||||
private BarChart 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_barchart);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_barchart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
|
||||
// add colors for one dataset
|
||||
ct.addDataSetColors(ColorTemplate.FRESH_COLORS, this);
|
||||
|
||||
mChart.setColorTemplate(ct);
|
||||
// mChart.setLegendDigits(2);
|
||||
// mChart.setValueDigits(2);
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
// mChart.setDrawFilled(true);
|
||||
// mChart.setRoundedYLegend(false);
|
||||
// mChart.setStartAtZero(true);
|
||||
mChart.setDrawYValues(false);
|
||||
mChart.set3DEnabled(false);
|
||||
// mChart.setSpacePercent(20, 10);
|
||||
mChart.setYLegendCount(5);
|
||||
mChart.setTouchEnabled(true);
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
// add colors for one dataset
|
||||
ct.addDataSetColors(ColorTemplate.FRESH_COLORS, this);
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.bar, menu);
|
||||
return true;
|
||||
}
|
||||
mChart.setColorTemplate(ct);
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// enable the drawing of values
|
||||
mChart.setDrawYValues(true);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.actionToggleValues: {
|
||||
if (mChart.isDrawYValuesEnabled())
|
||||
mChart.setDrawYValues(false);
|
||||
else
|
||||
mChart.setDrawYValues(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggle3D: {
|
||||
if (mChart.is3DEnabled())
|
||||
mChart.set3DEnabled(false);
|
||||
else
|
||||
mChart.set3DEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlight: {
|
||||
if (mChart.isHighlightEnabled())
|
||||
mChart.setHighlightEnabled(false);
|
||||
else
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlightArrow: {
|
||||
if (mChart.isDrawHighlightArrowEnabled())
|
||||
mChart.setDrawHighlightArrow(false);
|
||||
else
|
||||
mChart.setDrawHighlightArrow(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
// if more than 60 entries are displayed in the chart, no values will be
|
||||
// drawn
|
||||
mChart.setMaxVisibleValueCount(60);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
// sets the number of digits for values inside the chart
|
||||
mChart.setValueDigits(2);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleFilter:
|
||||
if (mChart.isFilterSet()) {
|
||||
mChart.setFilter(ApproximatorType.NONE, 0);
|
||||
} else {
|
||||
mChart.setFilter(ApproximatorType.DOUGLAS_PEUCKER, 2);
|
||||
// disable 3D
|
||||
mChart.set3DEnabled(false);
|
||||
mChart.setYLegendCount(5);
|
||||
|
||||
// scaling can now only be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.bar, 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;
|
||||
}
|
||||
mChart.invalidate();
|
||||
break;
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case R.id.actionToggle3D: {
|
||||
if (mChart.is3DEnabled())
|
||||
mChart.set3DEnabled(false);
|
||||
else
|
||||
mChart.set3DEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlight: {
|
||||
if (mChart.isHighlightEnabled())
|
||||
mChart.setHighlightEnabled(false);
|
||||
else
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionTogglePinch: {
|
||||
if (mChart.isPinchZoomEnabled())
|
||||
mChart.setPinchZoom(false);
|
||||
else
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlightArrow: {
|
||||
if (mChart.isDrawHighlightArrowEnabled())
|
||||
mChart.setDrawHighlightArrow(false);
|
||||
else
|
||||
mChart.setDrawHighlightArrow(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
xVals.add((i) + "");
|
||||
}
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleFilter:
|
||||
if (mChart.isFilterSet()) {
|
||||
mChart.setFilter(ApproximatorType.NONE, 0);
|
||||
} else {
|
||||
mChart.setFilter(ApproximatorType.DOUGLAS_PEUCKER, 5);
|
||||
}
|
||||
mChart.invalidate();
|
||||
break;
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float) ((mult * 0.1) / 10);
|
||||
yVals1.add(new Entry(val, i));
|
||||
}
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress() / 10));
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
DataSet set1 = new DataSet(yVals1, 0);
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
xVals.add((i) + "");
|
||||
}
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals1.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
DataSet set1 = new DataSet(yVals1, 0);
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
dataSets.add(set1);
|
||||
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.example.mpchartexample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -19,160 +20,170 @@ import com.github.mikephil.charting.utils.ColorTemplate;
|
|||
|
||||
public class BarChartActivityMultiDataset extends Activity implements OnSeekBarChangeListener {
|
||||
|
||||
private BarChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
private TextView tvX, tvY;
|
||||
private BarChart 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_barchart);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_barchart);
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
|
||||
// add colors for the datasets
|
||||
ct.addDataSetColors(ColorTemplate.FRESH_COLORS, this);
|
||||
|
||||
// the second dataset only has one color
|
||||
ct.addDataSetColors(new int[] {R.color.liberty_2}, this);
|
||||
ct.addDataSetColors(ColorTemplate.COLORFUL_COLORS, this);
|
||||
|
||||
mChart.setColorTemplate(ct);
|
||||
// mChart.setLegendDigits(2);
|
||||
// mChart.setValueDigits(2);
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
|
||||
// mChart.setDrawFilled(true);
|
||||
// mChart.setRoundedYLegend(false);
|
||||
// mChart.setStartAtZero(true);
|
||||
mChart.setDrawYValues(false);
|
||||
mChart.set3DEnabled(false);
|
||||
// mChart.setSpacePercent(20, 10);
|
||||
mChart.setYLegendCount(5);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setDescription("");
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
// add colors for the first dataset
|
||||
ct.addDataSetColors(ColorTemplate.FRESH_COLORS, this);
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.bar, menu);
|
||||
return true;
|
||||
}
|
||||
// the second dataset only has one color
|
||||
ct.addDataSetColors(new int[] {
|
||||
R.color.liberty_2
|
||||
}, this);
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// add colors for the third dataset
|
||||
ct.addDataSetColors(ColorTemplate.COLORFUL_COLORS, this);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.actionToggleValues: {
|
||||
if (mChart.isDrawYValuesEnabled())
|
||||
mChart.setDrawYValues(false);
|
||||
else
|
||||
mChart.setDrawYValues(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggle3D: {
|
||||
if (mChart.is3DEnabled())
|
||||
mChart.set3DEnabled(false);
|
||||
else
|
||||
mChart.set3DEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlight: {
|
||||
if (mChart.isHighlightEnabled())
|
||||
mChart.setHighlightEnabled(false);
|
||||
else
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlightArrow: {
|
||||
if (mChart.isDrawHighlightArrowEnabled())
|
||||
mChart.setDrawHighlightArrow(false);
|
||||
else
|
||||
mChart.setDrawHighlightArrow(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
mChart.setColorTemplate(ct);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
// disable the drawing of values
|
||||
mChart.setDrawYValues(false);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// disable 3D
|
||||
mChart.set3DEnabled(false);
|
||||
mChart.setYLegendCount(5);
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// scaling can now only be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
xVals.add((i) + "");
|
||||
}
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.bar, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress() / 3; i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float) ((mult * 0.1) / 10);
|
||||
yVals1.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
for (int i = mSeekBarX.getProgress() / 3; i < mSeekBarX.getProgress() / 3 * 2; i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float) ((mult * 0.1) / 10);
|
||||
@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.actionTogglePinch: {
|
||||
if (mChart.isPinchZoomEnabled())
|
||||
mChart.setPinchZoom(false);
|
||||
else
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggle3D: {
|
||||
if (mChart.is3DEnabled())
|
||||
mChart.set3DEnabled(false);
|
||||
else
|
||||
mChart.set3DEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlight: {
|
||||
if (mChart.isHighlightEnabled())
|
||||
mChart.setHighlightEnabled(false);
|
||||
else
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlightArrow: {
|
||||
if (mChart.isDrawHighlightArrowEnabled())
|
||||
mChart.setDrawHighlightArrow(false);
|
||||
else
|
||||
mChart.setDrawHighlightArrow(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("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()));
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
xVals.add((i) + "");
|
||||
}
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress() / 3; i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals1.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
for (int i = mSeekBarX.getProgress() / 3; i < mSeekBarX.getProgress() / 3 * 2; i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals2.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
for (int i = mSeekBarX.getProgress() / 3 * 2; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float) ((mult * 0.1) / 10);
|
||||
|
||||
for (int i = mSeekBarX.getProgress() / 3 * 2; i < mSeekBarX.getProgress(); i++) {
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals3.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress() / 10));
|
||||
|
||||
// create 3 datasets with different types
|
||||
DataSet set1 = new DataSet(yVals1, 0);
|
||||
DataSet set2 = new DataSet(yVals2, 1);
|
||||
DataSet set3 = new DataSet(yVals3, 2);
|
||||
// create 3 datasets with different types
|
||||
DataSet set1 = new DataSet(yVals1, 0);
|
||||
DataSet set2 = new DataSet(yVals2, 1);
|
||||
DataSet set3 = new DataSet(yVals3, 2);
|
||||
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
dataSets.add(set1);
|
||||
dataSets.add(set2);
|
||||
|
@ -180,19 +191,19 @@ public class BarChartActivityMultiDataset extends Activity implements OnSeekBarC
|
|||
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
|
||||
package com.example.mpchartexample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
|
@ -21,166 +17,179 @@ import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener;
|
|||
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.Utils;
|
||||
|
||||
public class DrawChartActivity extends Activity implements OnChartValueSelectedListener, OnDrawListener {
|
||||
import java.util.ArrayList;
|
||||
|
||||
private LineChart mChart;
|
||||
/**
|
||||
* 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 Activity implements OnChartValueSelectedListener,
|
||||
OnDrawListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_draw_chart);
|
||||
private LineChart mChart;
|
||||
|
||||
// create a color template for one dataset with only one color
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
ct.addColorsForDataSets(ColorTemplate.COLORFUL_COLORS, this);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_draw_chart);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setColorTemplate(ct);
|
||||
mChart.setDrawingEnabled(true);
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
|
||||
// create a color template, one color per dataset
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
ct.addColorsForDataSets(ColorTemplate.COLORFUL_COLORS, this);
|
||||
mChart.setColorTemplate(ct);
|
||||
|
||||
// listener for selecting and drawing
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setOnDrawListener(this);
|
||||
|
||||
// enable drawing with the finger
|
||||
mChart.setDrawingEnabled(true);
|
||||
|
||||
// enable dragging and scaling
|
||||
mChart.setDragEnabled(true);
|
||||
|
||||
mChart.setOnDrawListener(this);
|
||||
// mChart.setDrawFilled(true);
|
||||
// mChart.setRoundedYLegend(false);
|
||||
// mChart.setStartAtZero(true);
|
||||
mChart.setDrawYValues(false);
|
||||
mChart.setLineWidth(5f);
|
||||
mChart.setCircleSize(5f);
|
||||
// mChart.setSpacePercent(20, 10);
|
||||
mChart.setYLegendCount(6);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.setDrawYValues(false);
|
||||
mChart.setLineWidth(5f);
|
||||
mChart.setCircleSize(5f);
|
||||
mChart.setYLegendCount(6);
|
||||
mChart.setHighlightEnabled(true);
|
||||
|
||||
// if disabled, drawn datasets with the finger will not be automatically finished
|
||||
mChart.setAutoFinish(false);
|
||||
|
||||
// highlight index 2 and 6 in dataset 0
|
||||
// mChart.highlightValues(new Highlight[] {new Highlight(2, 0), new
|
||||
// Highlight(6, 0)});
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
// add data to the chart
|
||||
initWithDummyData();
|
||||
|
||||
mChart.setYRangeFixed(true);
|
||||
mChart.setYRange(-40f, 40f);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
TextView textView = new TextView(this);
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
textView.setBackgroundColor(Color.WHITE);
|
||||
textView.setPadding(15, 15, 15, 15);
|
||||
textView.setText("Marker View");
|
||||
private void initWithDummyData() {
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
xVals.add((i) + "h");
|
||||
}
|
||||
|
||||
mChart.setDrawMarkerView(true);
|
||||
mChart.setMarkerView(textView);
|
||||
ArrayList<Entry> yVals = new ArrayList<Entry>();
|
||||
|
||||
initWithDummyData();
|
||||
}
|
||||
// create a dataset and give it a type (0)
|
||||
DataSet set1 = new DataSet(yVals, 0);
|
||||
|
||||
private void initWithDummyData() {
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < 148; i++) {
|
||||
xVals.add((i) + "h");
|
||||
}
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
dataSets.add(set1); // add the datasets
|
||||
|
||||
ArrayList<Entry> yVals = new ArrayList<Entry>();
|
||||
// create a data object with the datasets
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
|
||||
// create a dataset and give it a type (0)
|
||||
DataSet set1 = new DataSet(yVals, 0);
|
||||
mChart.setData(data);
|
||||
}
|
||||
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
dataSets.add(set1); // add the datasets
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.draw, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
// create a data object with the datasets
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
mChart.setData(data);
|
||||
mChart.setYRangeFixed(false);
|
||||
mChart.setYRange(-40f, 40f);
|
||||
mChart.invalidate();
|
||||
}
|
||||
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: {
|
||||
if (mChart.isDrawFilledEnabled())
|
||||
mChart.setDrawFilled(false);
|
||||
else
|
||||
mChart.setDrawFilled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleCircles: {
|
||||
if (mChart.isDrawCirclesEnabled())
|
||||
mChart.setDrawCircles(false);
|
||||
else
|
||||
mChart.setDrawCircles(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.line, menu);
|
||||
return true;
|
||||
}
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionTogglePinch: {
|
||||
if (mChart.isPinchZoomEnabled())
|
||||
mChart.setPinchZoom(false);
|
||||
else
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
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: {
|
||||
if (mChart.isDrawFilledEnabled())
|
||||
mChart.setDrawFilled(false);
|
||||
else
|
||||
mChart.setDrawFilled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleCircles: {
|
||||
if (mChart.isDrawCirclesEnabled())
|
||||
mChart.setDrawCircles(false);
|
||||
else
|
||||
mChart.setDrawCircles(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
@Override
|
||||
public void onValuesSelected(Entry[] values, Highlight[] highlights) {
|
||||
Log.i("VALS SELECTED",
|
||||
"Value: " + values[0].getVal() + ", xIndex: " + highlights[0].getXIndex()
|
||||
+ ", DataSet index: " + highlights[0].getDataSetIndex());
|
||||
}
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValuesSelected(Entry[] values, Highlight[] highlights) {
|
||||
Log.i("VALS SELECTED", "Value: " + values[0].getVal() + ", xIndex: " + highlights[0].getXIndex()
|
||||
+ ", DataSet index: " + highlights[0].getDataSetIndex());
|
||||
}
|
||||
/** callback for each new entry drawn with the finger */
|
||||
@Override
|
||||
public void onEntryAdded(Entry entry) {
|
||||
Log.i(Chart.LOG_TAG, entry.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntryAdded(Entry entry) {
|
||||
Log.i(Chart.LOG_TAG, entry.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawFinished(DataSet dataSet) {
|
||||
Log.i(Chart.LOG_TAG, dataSet.toString());
|
||||
}
|
||||
/** callback when a DataSet has been drawn (when lifting the finger) */
|
||||
@Override
|
||||
public void onDrawFinished(DataSet dataSet) {
|
||||
Log.i(Chart.LOG_TAG, "DataSet drawn.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,28 +49,29 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setColorTemplate(ct);
|
||||
|
||||
// mChart.setDrawFilled(true);
|
||||
// mChart.setRoundedYLegend(false);
|
||||
// mChart.setStartAtZero(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.setLineWidth(5f);
|
||||
mChart.setCircleSize(5f);
|
||||
// mChart.setSpacePercent(20, 10);
|
||||
mChart.setYLegendCount(6);
|
||||
|
||||
// enable value highlighting
|
||||
mChart.setHighlightEnabled(true);
|
||||
|
||||
// enable touch gestures
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setHighlightEnabled(true);
|
||||
|
||||
// enable scaling and dragging
|
||||
mChart.setDragEnabled(true);
|
||||
|
||||
// if disabled, scaling can be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
// highlight index 2 and 6 in dataset 0
|
||||
// mChart.highlightValues(new Highlight[] {new Highlight(2, 0), new
|
||||
// Highlight(6, 0)});
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
|
||||
|
||||
// mChart.setOffsets(60, 25, 15, 15);
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
|
@ -126,6 +127,15 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionTogglePinch: {
|
||||
if (mChart.isPinchZoomEnabled())
|
||||
mChart.setPinchZoom(false);
|
||||
else
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
|
@ -139,7 +149,7 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
if (mChart.isFilterSet()) {
|
||||
mChart.setFilter(ApproximatorType.NONE, 0);
|
||||
} else {
|
||||
mChart.setFilter(ApproximatorType.DOUGLAS_PEUCKER, 2);
|
||||
mChart.setFilter(ApproximatorType.DOUGLAS_PEUCKER, 5);
|
||||
}
|
||||
mChart.invalidate();
|
||||
break;
|
||||
|
@ -154,6 +164,9 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
|
@ -170,10 +183,7 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
yVals.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress() / 10));
|
||||
|
||||
// create a dataset and give it a type (0)
|
||||
// create a dataset and give it a type
|
||||
DataSet set1 = new DataSet(yVals, 0);
|
||||
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
|
@ -182,11 +192,11 @@ public class LineChartActivity extends Activity implements OnSeekBarChangeListen
|
|||
// create a data object with the datasets
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
|
||||
// redraw
|
||||
mChart.invalidate();
|
||||
|
||||
// Log.i("pixel for value", mChart.getPixelsForValues(10, 10).toString());
|
||||
// Log.i("value for touch", mChart.getValuesByTouchPoint(300, 300).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,8 +24,6 @@ public class MainActivity extends Activity implements OnClickListener {
|
|||
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);
|
||||
Button btn9 = (Button) findViewById(R.id.button9);
|
||||
btn1.setOnClickListener(this);
|
||||
btn2.setOnClickListener(this);
|
||||
btn3.setOnClickListener(this);
|
||||
|
@ -33,8 +31,6 @@ public class MainActivity extends Activity implements OnClickListener {
|
|||
btn5.setOnClickListener(this);
|
||||
btn6.setOnClickListener(this);
|
||||
btn7.setOnClickListener(this);
|
||||
btn8.setOnClickListener(this);
|
||||
btn9.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,21 +60,13 @@ public class MainActivity extends Activity implements OnClickListener {
|
|||
startActivity(i);
|
||||
break;
|
||||
case R.id.button6:
|
||||
i = new Intent(this, MultipleChartsActivity.class);
|
||||
startActivity(i);
|
||||
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(Intent.ACTION_VIEW, Uri.parse("https://github.com/PhilJay/MPAndroidChart"));
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.button9:
|
||||
i = new Intent(this, ScatterChartActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
|
||||
package com.example.mpchartexample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
@ -22,196 +19,198 @@ import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener;
|
|||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Highlight;
|
||||
|
||||
public class MultiLineChartActivity extends Activity implements OnSeekBarChangeListener, OnChartValueSelectedListener {
|
||||
import java.util.ArrayList;
|
||||
|
||||
private LineChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
private TextView tvX, tvY;
|
||||
public class MultiLineChartActivity extends Activity implements OnSeekBarChangeListener,
|
||||
OnChartValueSelectedListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_linechart);
|
||||
private LineChart mChart;
|
||||
private SeekBar mSeekBarX, mSeekBarY;
|
||||
private TextView tvX, tvY;
|
||||
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_linechart);
|
||||
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
tvX = (TextView) findViewById(R.id.tvXMax);
|
||||
tvY = (TextView) findViewById(R.id.tvYMax);
|
||||
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
|
||||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
|
||||
// COLOR VARIATIONS
|
||||
// ct.addDataSetColors(ColorTemplate.COLORFUL_COLORS, this);
|
||||
// ct.addDataSetColors(ColorTemplate.JOYFUL_COLORS, this);
|
||||
// ct.addDataSetColors(ColorTemplate.GREEN_COLORS, this);
|
||||
|
||||
// ONE COLOR PER DATASET
|
||||
ct.addColorsForDataSets(ColorTemplate.COLORFUL_COLORS, this);
|
||||
|
||||
mChart.setColorTemplate(ct);
|
||||
// mChart.setDrawTopYLegendEntry(false);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
|
||||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
// mChart.setDrawFilled(true);
|
||||
// mChart.setRoundedYLegend(false);
|
||||
// mChart.setStartAtZero(true);
|
||||
mChart.setDrawYValues(false);
|
||||
mChart.setLineWidth(5f);
|
||||
mChart.setCircleSize(5f);
|
||||
// mChart.setSpacePercent(20, 10);
|
||||
mChart.setYLegendCount(6);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setHighlightEnabled(true);
|
||||
// mChart.highlightValues(new int[] {2, 6});
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
// create a color template for one dataset with only one color
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
ct.addColorsForDataSets(ColorTemplate.COLORFUL_COLORS, this);
|
||||
|
||||
TextView textView = new TextView(this);
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
textView.setBackgroundColor(Color.WHITE);
|
||||
textView.setPadding(15, 15, 15, 15);
|
||||
textView.setText("Marker View");
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setColorTemplate(ct);
|
||||
|
||||
mChart.setDrawMarkerView(true);
|
||||
mChart.setMarkerView(textView);
|
||||
// mChart.setStartAtZero(true);
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
// disable the drawing of values into the chart
|
||||
mChart.setDrawYValues(false);
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.line, menu);
|
||||
return true;
|
||||
}
|
||||
mChart.setLineWidth(5f);
|
||||
mChart.setCircleSize(5f);
|
||||
mChart.setYLegendCount(6);
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// enable value highlighting
|
||||
mChart.setHighlightEnabled(true);
|
||||
|
||||
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: {
|
||||
if (mChart.isDrawFilledEnabled())
|
||||
mChart.setDrawFilled(false);
|
||||
else
|
||||
mChart.setDrawFilled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleCircles: {
|
||||
if (mChart.isDrawCirclesEnabled())
|
||||
mChart.setDrawCircles(false);
|
||||
else
|
||||
mChart.setDrawCircles(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
// enable touch gestures
|
||||
mChart.setTouchEnabled(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
// enable scaling and dragging
|
||||
mChart.setDragEnabled(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("title" + System.currentTimeMillis(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// if disabled, scaling can be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
}
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
xVals.add((i) + "");
|
||||
}
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.line, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<Double[]> values = new ArrayList<Double[]>();
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
for (int z = 0; z < 3; z++) {
|
||||
|
||||
Double[] vals = new Double[mSeekBarX.getProgress()];
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
double val = (Math.random() * mult * 0.1) + 3;// + (float) ((mult * 0.1) / 10);
|
||||
vals[i] = val;
|
||||
}
|
||||
|
||||
values.add(vals);
|
||||
}
|
||||
switch (item.getItemId()) {
|
||||
case R.id.actionToggleValues: {
|
||||
if (mChart.isDrawYValuesEnabled())
|
||||
mChart.setDrawYValues(false);
|
||||
else
|
||||
mChart.setDrawYValues(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionTogglePinch: {
|
||||
if (mChart.isPinchZoomEnabled())
|
||||
mChart.setPinchZoom(false);
|
||||
else
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
// ArrayList<Entry> filtered = approximator.filter(yVals1);
|
||||
//
|
||||
// for (int i = 0; i < filtered.size(); i++) {
|
||||
// filtered.get(i).setType(1);
|
||||
// }
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleHighlight: {
|
||||
if (mChart.isHighlightEnabled())
|
||||
mChart.setHighlightEnabled(false);
|
||||
else
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleFilled: {
|
||||
if (mChart.isDrawFilledEnabled())
|
||||
mChart.setDrawFilled(false);
|
||||
else
|
||||
mChart.setDrawFilled(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleCircles: {
|
||||
if (mChart.isDrawCirclesEnabled())
|
||||
mChart.setDrawCircles(false);
|
||||
else
|
||||
mChart.setDrawCircles(true);
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
else
|
||||
mChart.setStartAtZero(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleAdjustXLegend: {
|
||||
if (mChart.isAdjustXLegendEnabled())
|
||||
mChart.setAdjustXLegend(false);
|
||||
else
|
||||
mChart.setAdjustXLegend(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionSave: {
|
||||
// mChart.saveToGallery("title"+System.currentTimeMillis());
|
||||
mChart.saveToPath("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()));
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
xVals.add((i) + "");
|
||||
}
|
||||
|
||||
ArrayList<Double[]> values = new ArrayList<Double[]>();
|
||||
|
||||
for (int z = 0; z < 3; z++) {
|
||||
|
||||
Double[] vals = new Double[mSeekBarX.getProgress()];
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
double val = (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
vals[i] = val;
|
||||
}
|
||||
|
||||
values.add(vals);
|
||||
}
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress() / 10));
|
||||
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
|
||||
// create DataSets from values
|
||||
// NOTE: DataSet.makeDataSets(...) is just a convenience method. Of
|
||||
// course, three different DataSets could be created separately as well.
|
||||
dataSets.addAll(DataSet.makeDataSets(values));
|
||||
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValuesSelected(Entry[] values, Highlight[] highlights) {
|
||||
Log.i("VALS SELECTED", "Value: " + values[0].getVal() + ", xIndex: " + highlights[0].getXIndex() + ", DataSet index: " + highlights[0].getDataSetIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
mChart.setData(data);
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
@Override
|
||||
public void onValuesSelected(Entry[] values, Highlight[] highlights) {
|
||||
Log.i("VALS SELECTED",
|
||||
"Value: " + values[0].getVal() + ", xIndex: " + highlights[0].getXIndex()
|
||||
+ ", DataSet index: " + highlights[0].getDataSetIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
package com.example.mpchartexample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.charts.BarChart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.charts.PieChart;
|
||||
|
||||
public class MultipleChartsActivity extends Activity {
|
||||
|
||||
private LineChart mLineChart;
|
||||
private BarChart mBarChart, mBarChart3D;
|
||||
private PieChart mPieChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_multiplecharts);
|
||||
|
||||
// mLineChart = (LineChart) findViewById(R.id.barChart1);
|
||||
// mBarChart = (BarChart) findViewById(R.id.barChart2);
|
||||
// mPieChart = (PieChart) findViewById(R.id.pieChart1);
|
||||
// mBarChart3D = (BarChart) findViewById(R.id.barChart4);
|
||||
//
|
||||
// ArrayList<String> xvalsSmall = new ArrayList<String>();
|
||||
// ArrayList<String> xvalsLarge = new ArrayList<String>();
|
||||
//
|
||||
// ArrayList<Float> small = new ArrayList<Float>();
|
||||
// small.add(3f);
|
||||
// small.add(7f);
|
||||
// small.add(17f);
|
||||
// small.add(4f);
|
||||
// small.add(6f);
|
||||
//
|
||||
// for(int i = 0; i < small.size(); i++) {
|
||||
// xvalsSmall.add("Val"+i);
|
||||
// }
|
||||
//
|
||||
// ArrayList<Float> large = new ArrayList<Float>();
|
||||
//
|
||||
// for(int i = 0; i < 1000; i++) {
|
||||
// large.add((float) (Math.random() * 50));
|
||||
// xvalsLarge.add("Val"+i);
|
||||
// }
|
||||
//
|
||||
// mLineChart.setData(xvalsLarge, large);
|
||||
// mLineChart.setColorTemplate(new ColorTemplate(ColorTemplate.getColors(this, ColorTemplate.FRESH_COLORS)));
|
||||
// mLineChart.setDrawFilled(false);
|
||||
// mLineChart.setStartAtZero(false);
|
||||
//// mLineChart.setRoundedYLegend(true);
|
||||
// mLineChart.setYRange(-10f, 60f);
|
||||
//
|
||||
// mBarChart.setData(xvalsLarge, large);
|
||||
// mBarChart.setColorTemplate(new ColorTemplate(ColorTemplate.getColors(this, ColorTemplate.FRESH_COLORS)));
|
||||
// mBarChart.set3DEnabled(false);
|
||||
// mBarChart.setMaxVisibleValueCount(10);
|
||||
// mBarChart.setRoundedYLegend(true);
|
||||
// mBarChart.setDescription("");
|
||||
//
|
||||
// mPieChart.setData(xvalsSmall, small);
|
||||
// mPieChart.setColorTemplate(new ColorTemplate(ColorTemplate.getColors(this, ColorTemplate.FRESH_COLORS)));
|
||||
//// mChart3.highlightValues(new int[] {0, 1, 2, 3, 4} );
|
||||
// mPieChart.setDrawYValues(true);
|
||||
// mPieChart.setDrawXValues(false);
|
||||
//
|
||||
// mBarChart3D.setData(xvalsLarge, large);
|
||||
// mBarChart3D.setColorTemplate(new ColorTemplate(ColorTemplate.getColors(this, ColorTemplate.LIBERTY_COLORS)));
|
||||
// mBarChart3D.setRoundedYLegend(true);
|
||||
// mBarChart3D.setDescription("Description.");
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ public class PieChartActivity extends Activity implements OnSeekBarChangeListene
|
|||
mChart = (PieChart) findViewById(R.id.chart1);
|
||||
|
||||
ColorTemplate ct = new ColorTemplate();
|
||||
ct.addDataSetColors(ColorTemplate.GREEN_COLORS, this);
|
||||
|
||||
ct.addDataSetColors(ColorTemplate.COLORFUL_COLORS, this);
|
||||
|
||||
mChart.setColorTemplate(ct);
|
||||
|
@ -54,18 +54,19 @@ public class PieChartActivity extends Activity implements OnSeekBarChangeListene
|
|||
|
||||
mChart.setDescription("This is a description.");
|
||||
mChart.setDrawHoleEnabled(true);
|
||||
|
||||
// draws the corresponding description value into the slice
|
||||
mChart.setDrawXValues(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setUsePercentValues(false);
|
||||
|
||||
// display percentage values
|
||||
mChart.setUsePercentValues(true);
|
||||
|
||||
// add a selection listener
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
mSeekBarX.setProgress(10);
|
||||
mSeekBarX.setProgress(5);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
// float diameter = mChart.getDiameter();
|
||||
// float radius = mChart.getRadius();
|
||||
//
|
||||
// Log.i("Piechart", "diameter: " + diameter + ", radius: " + radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,26 +129,19 @@ public class PieChartActivity extends Activity implements OnSeekBarChangeListene
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress()));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
|
||||
|
||||
// IMPORTANT: In a PieChart, no values (Entry) should have the same xIndex, since no values can be drawn above each other.
|
||||
for (int i = 0; i < mSeekBarX.getProgress() / 2; i++) {
|
||||
|
||||
// IMPORTANT: In a PieChart, no values (Entry) should have the same xIndex (even if from different DataSets), since no values can be drawn above each other.
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress());
|
||||
float val = (float) (Math.random() * mult) + mult / 5;// + (float) ((mult * 0.1) / 10);
|
||||
yVals1.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
for (int i = mSeekBarX.getProgress() / 2; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress());
|
||||
float val = (float) (Math.random() * mult) + mult / 5;// + (float) ((mult * 0.1) / 10);
|
||||
yVals2.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress()));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
|
||||
|
@ -155,15 +149,17 @@ public class PieChartActivity extends Activity implements OnSeekBarChangeListene
|
|||
xVals.add("Text" + (i + 1));
|
||||
|
||||
DataSet set1 = new DataSet(yVals1, 0);
|
||||
DataSet set2 = new DataSet(yVals2, 1);
|
||||
|
||||
ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
|
||||
dataSets.add(set1);
|
||||
dataSets.add(set2);
|
||||
|
||||
ChartData data = new ChartData(xVals, dataSets);
|
||||
mChart.setData(data);
|
||||
|
||||
// undo all highlights
|
||||
mChart.highlightValues(null);
|
||||
|
||||
// set a text for the chart center
|
||||
mChart.setCenterText("Total Value\n" + (int) mChart.getYValueSum() + "\n(all slices)");
|
||||
mChart.invalidate();
|
||||
}
|
||||
|
|
|
@ -53,27 +53,22 @@ public class ScatterChartActivity extends Activity implements OnSeekBarChangeLis
|
|||
}, this);
|
||||
|
||||
mChart = (ScatterChart) findViewById(R.id.chart1);
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
mChart.setColorTemplate(ct);
|
||||
|
||||
// one shape per dataset
|
||||
// specify the shapes for the datasets, one shape per dataset
|
||||
mChart.setScatterShapes(new ScatterShape[] { ScatterShape.SQUARE, ScatterShape.TRIANGLE, ScatterShape.CIRCLE });
|
||||
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
// mChart.setDrawFilled(true);
|
||||
// mChart.setRoundedYLegend(false);
|
||||
// mChart.setStartAtZero(true);
|
||||
// mChart.setSpacePercent(20, 10);
|
||||
mChart.setYLegendCount(6);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setHighlightEnabled(true);
|
||||
mChart.setDrawYValues(false);
|
||||
|
||||
// highlight index 2 and 6 in dataset 0
|
||||
// mChart.highlightValues(new Highlight[] {new Highlight(2, 0), new
|
||||
// Highlight(6, 0)});
|
||||
mChart.setDragEnabled(true);
|
||||
|
||||
mChart.setMaxVisibleValueCount(300);
|
||||
mChart.setMaxVisibleValueCount(200);
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mSeekBarX.setProgress(45);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
@ -105,6 +100,15 @@ public class ScatterChartActivity extends Activity implements OnSeekBarChangeLis
|
|||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionTogglePinch: {
|
||||
if (mChart.isPinchZoomEnabled())
|
||||
mChart.setPinchZoom(false);
|
||||
else
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionToggleStartzero: {
|
||||
if (mChart.isStartAtZeroEnabled())
|
||||
mChart.setStartAtZero(false);
|
||||
|
@ -142,6 +146,9 @@ public class ScatterChartActivity extends Activity implements OnSeekBarChangeLis
|
|||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress()));
|
||||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
|
@ -153,33 +160,21 @@ public class ScatterChartActivity extends Activity implements OnSeekBarChangeLis
|
|||
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float)
|
||||
// ((mult *
|
||||
// 0.1) / 10);
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals1.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float)
|
||||
// ((mult *
|
||||
// 0.1) / 10);
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals2.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
|
||||
float mult = (mSeekBarY.getProgress() + 1);
|
||||
float val = (float) (Math.random() * mult * 0.1) + 3;// + (float)
|
||||
// ((mult *
|
||||
// 0.1) / 10);
|
||||
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
|
||||
yVals3.add(new Entry(val, i));
|
||||
}
|
||||
|
||||
tvX.setText("" + (mSeekBarX.getProgress() + 1));
|
||||
tvY.setText("" + (mSeekBarY.getProgress() / 10));
|
||||
|
||||
// create a dataset and give it a type (0)
|
||||
// create a dataset and give it a type
|
||||
DataSet set1 = new DataSet(yVals1, 0);
|
||||
DataSet set2 = new DataSet(yVals2, 1);
|
||||
DataSet set3 = new DataSet(yVals3, 2);
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,14 +1,13 @@
|
|||
package com.github.mikephil.charting.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
package com.github.mikephil.charting.data;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
import com.github.mikephil.charting.data.filter.Approximator;
|
||||
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
|
||||
import com.github.mikephil.charting.exception.DrawingDataSetNotCreatedException;
|
||||
import com.github.mikephil.charting.interfaces.OnDrawListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Class that holds all relevant data that represents the chart
|
||||
|
@ -17,371 +16,381 @@ import com.github.mikephil.charting.interfaces.OnDrawListener;
|
|||
*/
|
||||
public class ChartData {
|
||||
|
||||
/** maximum y-value in the y-value array */
|
||||
private float mYMax = 0.0f;
|
||||
/** maximum y-value in the y-value array */
|
||||
private float mYMax = 0.0f;
|
||||
|
||||
/** the minimum y-value in the y-value array */
|
||||
private float mYMin = 0.0f;
|
||||
/** the minimum y-value in the y-value array */
|
||||
private float mYMin = 0.0f;
|
||||
|
||||
/** the total sum of all y-values */
|
||||
private float mYValueSum = 0f;
|
||||
/** the total sum of all y-values */
|
||||
private float mYValueSum = 0f;
|
||||
|
||||
/** holds all x-values the chart represents */
|
||||
private ArrayList<String> mXVals;
|
||||
/** holds all x-values the chart represents */
|
||||
private ArrayList<String> mXVals;
|
||||
|
||||
/** holds all the datasets (e.g. different lines) the chart represents */
|
||||
private ArrayList<DataSet> mDataSets;
|
||||
/** holds all the datasets (e.g. different lines) the chart represents */
|
||||
private ArrayList<DataSet> mDataSets;
|
||||
|
||||
/** if true, there are approximated DataSets */
|
||||
private boolean mApproximatedData = false;
|
||||
/** if true, there are approximated DataSets */
|
||||
private boolean mApproximatedData = false;
|
||||
|
||||
/** the approximator, used to filter values */
|
||||
private Approximator mApproximator;
|
||||
/** the approximator, used to filter values */
|
||||
private Approximator mApproximator;
|
||||
|
||||
/** the filtered values, stored separately to not change the data set by the user */
|
||||
private ArrayList<DataSet> mApproximatedDataSets;
|
||||
/**
|
||||
* the filtered values, stored separately to not change the data set by the
|
||||
* user
|
||||
*/
|
||||
private ArrayList<DataSet> mApproximatedDataSets;
|
||||
|
||||
/** array that holds all the different type ids that are in the series array */
|
||||
private ArrayList<Integer> mDiffTypes;
|
||||
/** array that holds all the different type ids that are in the series array */
|
||||
private ArrayList<Integer> mDiffTypes;
|
||||
|
||||
/**
|
||||
* constructor for chart data
|
||||
*
|
||||
* @param xVals
|
||||
* must be at least as long as the highest xIndex in the Series objects across all DataSets
|
||||
* @param dataSets
|
||||
* all DataSet objects the chart needs to represent
|
||||
*/
|
||||
public ChartData(ArrayList<String> xVals, ArrayList<DataSet> dataSets) {
|
||||
init(xVals, dataSets);
|
||||
}
|
||||
/**
|
||||
* constructor for chart data
|
||||
*
|
||||
* @param xVals The values describing the x-axis. Must be at least as long
|
||||
* as the highest xIndex in the Entry objects across all
|
||||
* DataSets.
|
||||
* @param dataSets all DataSet objects the chart needs to represent
|
||||
*/
|
||||
public ChartData(ArrayList<String> xVals, ArrayList<DataSet> dataSets) {
|
||||
init(xVals, dataSets);
|
||||
}
|
||||
|
||||
public ChartData(String[] xVals, ArrayList<DataSet> dataSets) {
|
||||
ArrayList<String> newXVals = new ArrayList<String>();
|
||||
for (int i = 0; i < xVals.length; i++) {
|
||||
newXVals.add(xVals[i]);
|
||||
}
|
||||
init(newXVals, dataSets);
|
||||
}
|
||||
public ChartData(String[] xVals, ArrayList<DataSet> dataSets) {
|
||||
ArrayList<String> newXVals = new ArrayList<String>();
|
||||
for (int i = 0; i < xVals.length; i++) {
|
||||
newXVals.add(xVals[i]);
|
||||
}
|
||||
init(newXVals, dataSets);
|
||||
}
|
||||
|
||||
private void init(ArrayList<String> xVals, ArrayList<DataSet> dataSets) {
|
||||
this.mXVals = xVals;
|
||||
this.mDataSets = dataSets;
|
||||
mApproximator = new Approximator();
|
||||
private void init(ArrayList<String> xVals, ArrayList<DataSet> dataSets) {
|
||||
this.mXVals = xVals;
|
||||
this.mDataSets = dataSets;
|
||||
mApproximator = new Approximator();
|
||||
|
||||
calcTypes();
|
||||
calcMinMax();
|
||||
calcYValueSum();
|
||||
calcTypes();
|
||||
calcMinMax();
|
||||
calcYValueSum();
|
||||
|
||||
for (int i = 0; i < mDataSets.size(); i++) {
|
||||
if (mDataSets.get(i).getYVals().size() > xVals.size()) {
|
||||
throw new IllegalArgumentException("x values are smaller than the largest y series array of one type");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mDataSets.size(); i++) {
|
||||
if (mDataSets.get(i).getYVals().size() > xVals.size()) {
|
||||
throw new IllegalArgumentException(
|
||||
"x values are smaller than the largest y series array of one type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method to let the CartData know that the underlying data has changed.
|
||||
*/
|
||||
public void notifyDataChanged() {
|
||||
if (mApproximatedData) {
|
||||
filter();
|
||||
} else {
|
||||
doCalculations();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Call this method to let the CartData know that the underlying data has
|
||||
* changed.
|
||||
*/
|
||||
public void notifyDataChanged() {
|
||||
if (mApproximatedData) {
|
||||
filter();
|
||||
} else {
|
||||
doCalculations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does all necessary calculations, if the underlying data has changed
|
||||
*/
|
||||
private void doCalculations() {
|
||||
calcTypes();
|
||||
calcMinMax();
|
||||
calcYValueSum();
|
||||
}
|
||||
/**
|
||||
* Does all necessary calculations, if the underlying data has changed
|
||||
*/
|
||||
private void doCalculations() {
|
||||
calcTypes();
|
||||
calcMinMax();
|
||||
calcYValueSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates all different types that occur in the datasets and stores them for fast access
|
||||
*/
|
||||
private void calcTypes() {
|
||||
mDiffTypes = new ArrayList<Integer>();
|
||||
/**
|
||||
* calculates all different types that occur in the datasets and stores them
|
||||
* for fast access
|
||||
*/
|
||||
private void calcTypes() {
|
||||
mDiffTypes = new ArrayList<Integer>();
|
||||
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
|
||||
int type = dataSets.get(i).getType();
|
||||
int type = dataSets.get(i).getType();
|
||||
|
||||
if (!alreadyCounted(mDiffTypes, type)) {
|
||||
mDiffTypes.add(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!alreadyCounted(mDiffTypes, type)) {
|
||||
mDiffTypes.add(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calc minimum and maximum y value over all datasets
|
||||
*/
|
||||
private void calcMinMax() {
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
/**
|
||||
* calc minimum and maximum y value over all datasets
|
||||
*/
|
||||
private void calcMinMax() {
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
|
||||
mYMin = dataSets.get(0).getYMin();
|
||||
mYMax = dataSets.get(0).getYMax();
|
||||
mYMin = dataSets.get(0).getYMin();
|
||||
mYMax = dataSets.get(0).getYMax();
|
||||
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
if (dataSets.get(i).getYMin() < mYMin)
|
||||
mYMin = dataSets.get(i).getYMin();
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
if (dataSets.get(i).getYMin() < mYMin)
|
||||
mYMin = dataSets.get(i).getYMin();
|
||||
|
||||
if (dataSets.get(i).getYMax() > mYMax)
|
||||
mYMax = dataSets.get(i).getYMax();
|
||||
}
|
||||
}
|
||||
if (dataSets.get(i).getYMax() > mYMax)
|
||||
mYMax = dataSets.get(i).getYMax();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates the sum of all y-values in all datasets
|
||||
*/
|
||||
private void calcYValueSum() {
|
||||
/**
|
||||
* calculates the sum of all y-values in all datasets
|
||||
*/
|
||||
private void calcYValueSum() {
|
||||
|
||||
mYValueSum = 0;
|
||||
mYValueSum = 0;
|
||||
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
mYValueSum += Math.abs(dataSets.get(i).getYValueSum());
|
||||
}
|
||||
}
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
mYValueSum += Math.abs(dataSets.get(i).getYValueSum());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean alreadyCounted(ArrayList<Integer> countedTypes, int type) {
|
||||
for (int i = 0; i < countedTypes.size(); i++) {
|
||||
if (countedTypes.get(i) == type)
|
||||
return true;
|
||||
}
|
||||
private boolean alreadyCounted(ArrayList<Integer> countedTypes, int type) {
|
||||
for (int i = 0; i < countedTypes.size(); i++) {
|
||||
if (countedTypes.get(i) == type)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Corrects all values that are kept as member variables after a new entry was added. This saves recalculating all
|
||||
* values.
|
||||
*
|
||||
* @param entry
|
||||
* the new entry
|
||||
*/
|
||||
public void notifyDataForNewEntry(Entry entry) {
|
||||
mYValueSum += Math.abs(entry.getVal());
|
||||
if (mYMin > entry.getVal()) {
|
||||
mYMin = entry.getVal();
|
||||
}
|
||||
if (mYMax < entry.getVal()) {
|
||||
mYMax = entry.getVal();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Corrects all values that are kept as member variables after a new entry
|
||||
* was added. This saves recalculating all values.
|
||||
*
|
||||
* @param entry the new entry
|
||||
*/
|
||||
public void notifyDataForNewEntry(Entry entry) {
|
||||
mYValueSum += Math.abs(entry.getVal());
|
||||
if (mYMin > entry.getVal()) {
|
||||
mYMin = entry.getVal();
|
||||
}
|
||||
if (mYMax < entry.getVal()) {
|
||||
mYMax = entry.getVal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the whole ChartData. If the type is NONE, the filtering is reset. Be aware that the original
|
||||
* DataSets are not modified. Instead there are modified copies of the data. All methods return the filtered values
|
||||
* if a filter is set. To receive the original values despite a set filter, call getOriginalDataSets().
|
||||
*
|
||||
* @param type
|
||||
* the filter type. NONE to reset filtering
|
||||
* @param tolerance
|
||||
* the tolerance
|
||||
*/
|
||||
public void setFilter(ApproximatorType type, double tolerance) {
|
||||
mApproximator.setTypeAndTolerance(type, tolerance);
|
||||
/**
|
||||
* Sets a filter on the whole ChartData. If the type is NONE, the filtering
|
||||
* is reset. Be aware that the original DataSets are not modified. Instead
|
||||
* there are modified copies of the data. All methods return the filtered
|
||||
* values if a filter is set. To receive the original values despite a set
|
||||
* filter, call getOriginalDataSets().
|
||||
*
|
||||
* @param type the filter type. NONE to reset filtering
|
||||
* @param tolerance the tolerance
|
||||
*/
|
||||
public void setFilter(ApproximatorType type, double tolerance) {
|
||||
mApproximator.setTypeAndTolerance(type, tolerance);
|
||||
|
||||
if (type != ApproximatorType.NONE) {
|
||||
mApproximatedData = true;
|
||||
// filter values
|
||||
filter();
|
||||
} else {
|
||||
mApproximatedData = false;
|
||||
// do calculations, because original values are used now
|
||||
doCalculations();
|
||||
}
|
||||
}
|
||||
if (type != ApproximatorType.NONE) {
|
||||
mApproximatedData = true;
|
||||
// filter values
|
||||
filter();
|
||||
} else {
|
||||
mApproximatedData = false;
|
||||
// do calculations, because original values are used now
|
||||
doCalculations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method to filter the data. This is private, because if a user of this library wants to filter again, he
|
||||
* should use notifyDataSetChanged() or setFilter() instead.
|
||||
*/
|
||||
private void filter() {
|
||||
if (mApproximatedData) {
|
||||
mApproximatedDataSets = new ArrayList<DataSet>();
|
||||
for (int i = 0; i < mDataSets.size(); i++) {
|
||||
DataSet dataSet = mDataSets.get(i);
|
||||
ArrayList<Entry> filteredEntries = mApproximator.filter(dataSet.getYVals());
|
||||
if (filteredEntries != null) {
|
||||
DataSet approximatedDataSet = new DataSet(filteredEntries, dataSet.getType());
|
||||
mApproximatedDataSets.add(approximatedDataSet);
|
||||
} else {
|
||||
// if filtering failed, copy data set
|
||||
DataSet approximatedDataSet = dataSet.cloneDataSet();
|
||||
mApproximatedDataSets.add(approximatedDataSet);
|
||||
}
|
||||
}
|
||||
doCalculations();
|
||||
} else {
|
||||
Log.e(Chart.LOG_TAG, "No filter set. Call setFilter() first");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Call this method to filter the data. This is private, because if a user
|
||||
* of this library wants to filter again, he should use
|
||||
* notifyDataSetChanged() or setFilter() instead.
|
||||
*/
|
||||
private void filter() {
|
||||
if (mApproximatedData) {
|
||||
mApproximatedDataSets = new ArrayList<DataSet>();
|
||||
for (int i = 0; i < mDataSets.size(); i++) {
|
||||
DataSet dataSet = mDataSets.get(i);
|
||||
ArrayList<Entry> filteredEntries = mApproximator.filter(dataSet.getYVals());
|
||||
if (filteredEntries != null) {
|
||||
DataSet approximatedDataSet = new DataSet(filteredEntries, dataSet.getType());
|
||||
mApproximatedDataSets.add(approximatedDataSet);
|
||||
} else {
|
||||
// if filtering failed, copy data set
|
||||
DataSet approximatedDataSet = dataSet.cloneDataSet();
|
||||
mApproximatedDataSets.add(approximatedDataSet);
|
||||
}
|
||||
}
|
||||
doCalculations();
|
||||
} else {
|
||||
Log.e(Chart.LOG_TAG, "No filter set. Call setFilter() first");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if true, the DataSets are approximated. Use getOriginalDataSet() to receive original values, even if filter
|
||||
* apply.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isApproximatedData() {
|
||||
return mApproximatedData;
|
||||
}
|
||||
/**
|
||||
* if true, the DataSets are approximated. Use getOriginalDataSet() to
|
||||
* receive original values, even if filter apply.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isApproximatedData() {
|
||||
return mApproximatedData;
|
||||
}
|
||||
|
||||
public int getDataSetCount() {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets.size();
|
||||
}
|
||||
return mDataSets.size();
|
||||
}
|
||||
public int getDataSetCount() {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets.size();
|
||||
}
|
||||
return mDataSets.size();
|
||||
}
|
||||
|
||||
public float getYMin() {
|
||||
return mYMin;
|
||||
}
|
||||
public float getYMin() {
|
||||
return mYMin;
|
||||
}
|
||||
|
||||
public float getYMax() {
|
||||
return mYMax;
|
||||
}
|
||||
public float getYMax() {
|
||||
return mYMax;
|
||||
}
|
||||
|
||||
public float getYValueSum() {
|
||||
return mYValueSum;
|
||||
}
|
||||
public float getYValueSum() {
|
||||
return mYValueSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the ChartData object contains valid data
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isValid() {
|
||||
if (mXVals == null || mXVals.size() <= 1)
|
||||
return false;
|
||||
/**
|
||||
* Checks if the ChartData object contains valid data
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isValid() {
|
||||
if (mXVals == null || mXVals.size() <= 1)
|
||||
return false;
|
||||
|
||||
if (mApproximatedData) {
|
||||
if (mApproximatedDataSets == null || mApproximatedDataSets.size() < 1)
|
||||
return false;
|
||||
} else {
|
||||
if (mDataSets == null || mDataSets.size() < 1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (mApproximatedData) {
|
||||
if (mApproximatedDataSets == null || mApproximatedDataSets.size() < 1)
|
||||
return false;
|
||||
} else {
|
||||
if (mDataSets == null || mDataSets.size() < 1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the x-values the chart represents
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getXVals() {
|
||||
return mXVals;
|
||||
}
|
||||
/**
|
||||
* returns the x-values the chart represents
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getXVals() {
|
||||
return mXVals;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the Entries array from the DataSet at the given index. If a filter is set, the filtered Entries are
|
||||
* returned
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Entry> getYVals(int index) {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets.get(index).getYVals();
|
||||
}
|
||||
return mDataSets.get(index).getYVals();
|
||||
}
|
||||
/**
|
||||
* returns the Entries array from the DataSet at the given index. If a
|
||||
* filter is set, the filtered Entries are returned
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Entry> getYVals(int index) {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets.get(index).getYVals();
|
||||
}
|
||||
return mDataSets.get(index).getYVals();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the dataset at the given index. If a filter is set, the filtered DataSet is returned.
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDataSetByIndex(int index) {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets.get(index);
|
||||
}
|
||||
return mDataSets.get(index);
|
||||
}
|
||||
/**
|
||||
* returns the dataset at the given index. If a filter is set, the filtered
|
||||
* DataSet is returned.
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDataSetByIndex(int index) {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets.get(index);
|
||||
}
|
||||
return mDataSets.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a dataset with a specific type from the chartdata. If a filter is set, the filtered DataSet is returned.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDataSetByType(int type) {
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
/**
|
||||
* retrieve a dataset with a specific type from the chartdata. If a filter
|
||||
* is set, the filtered DataSet is returned.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDataSetByType(int type) {
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
|
||||
for (int i = 0; i < dataSets.size(); i++)
|
||||
if (type == dataSets.get(i).getType())
|
||||
return dataSets.get(i);
|
||||
for (int i = 0; i < dataSets.size(); i++)
|
||||
if (type == dataSets.get(i).getType())
|
||||
return dataSets.get(i);
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns all DataSet objects the ChartData represents. If a filter is set, the filtered DataSets are returned
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<DataSet> getDataSets() {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets;
|
||||
}
|
||||
return mDataSets;
|
||||
}
|
||||
/**
|
||||
* returns all DataSet objects the ChartData represents. If a filter is set,
|
||||
* the filtered DataSets are returned
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<DataSet> getDataSets() {
|
||||
if (mApproximatedData) {
|
||||
return mApproximatedDataSets;
|
||||
}
|
||||
return mDataSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the original data set, regardless of any filter options.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<DataSet> getOriginalDataSets() {
|
||||
return mDataSets;
|
||||
}
|
||||
/**
|
||||
* This returns the original data set, regardless of any filter options.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<DataSet> getOriginalDataSets() {
|
||||
return mDataSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns all the different DataSet types the chartdata represents
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Integer> getTypes() {
|
||||
return mDiffTypes;
|
||||
}
|
||||
/**
|
||||
* returns all the different DataSet types the chartdata represents
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Integer> getTypes() {
|
||||
return mDiffTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the total number of x-values this chartdata represents (the size of the xvals array)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getXValCount() {
|
||||
return mXVals.size();
|
||||
}
|
||||
/**
|
||||
* returns the total number of x-values this chartdata represents (the size
|
||||
* of the xvals array)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getXValCount() {
|
||||
return mXVals.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the total number of y-values across all DataSets the chartdata represents. If a filter is set, the
|
||||
* filtered count is returned
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getYValCount() {
|
||||
int count = 0;
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
/**
|
||||
* returns the total number of y-values across all DataSets the chartdata
|
||||
* represents. If a filter is set, the filtered count is returned
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getYValCount() {
|
||||
int count = 0;
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mApproximatedData ? mApproximatedDataSets : mDataSets;
|
||||
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
count += dataSets.get(i).getEntryCount();
|
||||
}
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
count += dataSets.get(i).getEntryCount();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ public class DataSet {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("DataSet " + mType + "\n");
|
||||
buffer.append("DataSet, type: " + mType + ", entries: + " + mYVals.size() + "\n");
|
||||
for (int i = 0; i < mYVals.size(); i++) {
|
||||
buffer.append(mYVals.get(i).toString() + " ");
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ public class BarLineChartTouchListener extends SimpleOnGestureListener implement
|
|||
|
||||
mDrawingContext.init(mChart.getDrawListener(), mChart.isAutoFinishEnabled());
|
||||
ChartData data = mChart.getData();
|
||||
|
||||
// Handle touch events here...
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
|
|
Loading…
Add table
Reference in a new issue