Fix merge conflicts

This commit is contained in:
Philipp Jahoda 2015-12-17 20:33:35 +01:00
commit 3f79bb538b
147 changed files with 5258 additions and 1720 deletions

View file

@ -26,7 +26,6 @@
</activity>
<activity android:name="LineChartActivity1"></activity> <!-- android:configChanges="keyboardHidden|orientation|screenSize" -->
<activity android:name="LineChartActivity2"></activity>
<activity android:screenOrientation="landscape" android:name="MultipleChartsActivity"></activity>
<activity android:name="BarChartActivity"></activity>
<activity android:name="HorizontalBarChartActivity"></activity>
<activity android:name="PieChartActivity"></activity>
@ -46,6 +45,15 @@
<activity android:name="RadarChartActivitry"></activity>
<activity android:name="LineChartActivityColored"></activity>
<activity android:name="DynamicalAddingActivity"></activity>
<activity android:name=".realm.RealmDatabaseActivityLine"></activity>
<activity android:name=".realm.RealmDatabaseActivityBar"></activity>
<activity android:name=".realm.RealmDatabaseActivityHorizontalBar"></activity>
<activity android:name=".realm.RealmDatabaseActivityScatter"></activity>
<activity android:name=".realm.RealmDatabaseActivityCandle"></activity>
<activity android:name=".realm.RealmDatabaseActivityBubble"></activity>
<activity android:name=".realm.RealmDatabaseActivityPie"></activity>
<activity android:name=".realm.RealmDatabaseActivityRadar"></activity>
<activity android:name=".realm.RealmMainActivity"></activity>
<activity android:name="RealtimeLineChartActivity"></activity>
<activity android:name="CombinedChartActivity"></activity>
<activity android:name="PerformanceLineChart"></activity>

View file

@ -39,7 +39,6 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
@ -47,11 +46,15 @@ buildscript {
repositories {
maven { url "https://jitpack.io" }
maven { // this is for realm-db
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':MPChartLib') // remove this if you only imported the example project
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'io.realm:realm-android:0.84.0-SNAPSHOT' // dependency for realm-database API (http://realm.io)
//compile 'com.github.PhilJay:MPAndroidChart:v2.1.1'
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.BubbleChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.CandleStickChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.RadarChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.github.mikephil.charting.charts.ScatterChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View file

@ -22,6 +22,22 @@
android:layout_below="@+id/tvName"
android:layout_marginTop="3dp"
android:text="Small Text"
android:textSize="12dp" />
android:textSize="12dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/tvNew"
android:layout_toStartOf="@+id/tvNew" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="NEW"
android:textColor="#FA6185"
android:id="@+id/tvNew"
android:textSize="12dp"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/viewRealm"
android:title="realm.io website">
</item>
</menu>

View file

@ -16,9 +16,10 @@ import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -97,7 +98,7 @@ public class AnotherBarActivity extends DemoBase implements OnSeekBarChangeListe
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
@ -201,7 +202,7 @@ public class AnotherBarActivity extends DemoBase implements OnSeekBarChangeListe
set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
set1.setDrawValues(false);
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);

View file

@ -27,13 +27,14 @@ import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.formatter.YAxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.xxmassdeveloper.mpchartexample.custom.MyYAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -137,7 +138,7 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
@ -257,7 +258,7 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
set1.setBarSpacePercent(35f);
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);

View file

@ -20,11 +20,11 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.formatter.LargeValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -114,7 +114,7 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IBarDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
@ -219,7 +219,7 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
BarDataSet set3 = new BarDataSet(yVals3, "Company C");
set3.setColor(Color.rgb(242, 247, 158));
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
dataSets.add(set2);
dataSets.add(set3);

View file

@ -22,9 +22,9 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.FileUtils;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -123,7 +123,7 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IBarDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();

View file

@ -20,13 +20,14 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.BubbleDataSet;
import com.github.mikephil.charting.data.BubbleEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
@ -108,7 +109,7 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
@ -225,7 +226,7 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
set3.setDrawValues(true);
ArrayList<BubbleDataSet> dataSets = new ArrayList<BubbleDataSet>();
ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
dataSets.add(set1); // add the datasets
dataSets.add(set2);
dataSets.add(set3);

View file

@ -20,6 +20,7 @@ import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleDataSet;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
@ -122,9 +123,8 @@ public class CandleStickChartActivity extends DemoBase implements OnSeekBarChang
break;
}
case R.id.actionToggleMakeShadowSameColorAsCandle: {
for (CandleDataSet set : mChart.getData().getDataSets())
{
set.setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
for (ICandleDataSet set : mChart.getData().getDataSets()) {
//TODO: set.setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle());
}
mChart.invalidate();

View file

@ -22,12 +22,12 @@ import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleDataSet;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.data.ScatterDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -198,7 +198,7 @@ public class CombinedChartActivity extends DemoBase {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionToggleLineValues: {
for (DataSet<?> set : mChart.getData().getDataSets()) {
for (IDataSet set : mChart.getData().getDataSets()) {
if (set instanceof LineDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}
@ -207,7 +207,7 @@ public class CombinedChartActivity extends DemoBase {
break;
}
case R.id.actionToggleBarValues: {
for (DataSet<?> set : mChart.getData().getDataSets()) {
for (IDataSet set : mChart.getData().getDataSets()) {
if (set instanceof BarDataSet)
set.setDrawValues(!set.isDrawValuesEnabled());
}

View file

@ -15,18 +15,19 @@ import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.formatter.FillFormatter;
import com.github.mikephil.charting.interfaces.LineDataProvider;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeListener {
@ -112,7 +113,7 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IDataSet set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
@ -127,10 +128,13 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
}
case R.id.actionToggleFilled: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
@ -140,10 +144,12 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
break;
}
case R.id.actionToggleCircles: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCirclesEnabled())
set.setDrawCircles(false);
else
@ -153,10 +159,12 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
break;
}
case R.id.actionToggleCubic: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCubicEnabled())
set.setDrawCubic(false);
else
@ -282,7 +290,7 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
set1.setDrawHorizontalHighlightIndicator(false);
set1.setFillFormatter(new FillFormatter() {
@Override
public float getFillLinePosition(LineDataSet dataSet, LineDataProvider dataProvider) {
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return -10;
}
});

View file

@ -16,12 +16,14 @@ import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.listener.OnDrawListener;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
/**
* This Activity demonstrates drawing into the Chart with the finger. Both line,
@ -84,7 +86,7 @@ public class DrawChartActivity extends DemoBase implements OnChartValueSelectedL
set1.setLineWidth(3f);
set1.setCircleSize(5f);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
@ -104,8 +106,14 @@ public class DrawChartActivity extends DemoBase implements OnChartValueSelectedL
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;

View file

@ -13,6 +13,7 @@ import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
@ -52,7 +53,7 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
if(data != null) {
LineDataSet set = data.getDataSetByIndex(0);
ILineDataSet set = data.getDataSetByIndex(0);
// set.addEntry(...); // can be called as well
if (set == null) {
@ -85,7 +86,7 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
if(data != null) {
LineDataSet set = data.getDataSetByIndex(0);
ILineDataSet set = data.getDataSetByIndex(0);
if (set != null) {

View file

@ -24,16 +24,16 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
@ -134,8 +134,14 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<IBarDataSet> sets = mChart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
IBarDataSet set = (BarDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -247,7 +253,7 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
BarDataSet set1 = new BarDataSet(yVals1, "DataSet 1");
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);

View file

@ -16,18 +16,19 @@ import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
@ -122,8 +123,14 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -137,10 +144,12 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
}
case R.id.actionToggleFilled: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
@ -150,10 +159,12 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
break;
}
case R.id.actionToggleCircles: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCirclesEnabled())
set.setDrawCircles(false);
else

View file

@ -22,13 +22,13 @@ import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.LimitLine.LimitLabelPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
@ -36,6 +36,7 @@ import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListener,
OnChartGestureListener, OnChartValueSelectedListener {
@ -176,8 +177,14 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -191,10 +198,12 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
}
case R.id.actionToggleFilled: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
@ -204,10 +213,12 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
break;
}
case R.id.actionToggleCircles: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCirclesEnabled())
set.setDrawCircles(false);
else
@ -217,10 +228,12 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
break;
}
case R.id.actionToggleCubic: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCubicEnabled())
set.setDrawCubic(false);
else
@ -351,7 +364,7 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
// Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets

View file

@ -20,19 +20,19 @@ import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.custom.MyFillFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
@ -136,8 +136,14 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -151,10 +157,12 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
}
case R.id.actionToggleFilled: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
@ -164,10 +172,12 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
break;
}
case R.id.actionToggleCircles: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCirclesEnabled())
set.setDrawCircles(false);
else
@ -177,10 +187,12 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
break;
}
case R.id.actionToggleCubic: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCubicEnabled())
set.setDrawCubic(false);
else
@ -317,7 +329,7 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
set2.setHighLightColor(Color.rgb(244, 117, 117));
//set2.setFillFormatter(new MyFillFormatter(900f));
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set2);
dataSets.add(set1); // add the datasets

View file

@ -11,6 +11,7 @@ import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
@ -118,7 +119,7 @@ public class LineChartActivityColored extends DemoBase {
set1.setHighLightColor(Color.WHITE);
set1.setDrawValues(false);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets

View file

@ -20,6 +20,7 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -140,7 +141,7 @@ public class ListViewBarChartActivity extends DemoBase {
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setBarShadowColor(Color.rgb(203, 203, 203));
ArrayList<BarDataSet> sets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
sets.add(d);
BarData cd = new BarData(getMonths(), sets);

View file

@ -18,6 +18,7 @@ import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.listviewitems.BarChartItem;
import com.xxmassdeveloper.mpchartexample.listviewitems.ChartItem;
@ -120,7 +121,7 @@ public class ListViewMultiChartActivity extends DemoBase {
d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
d2.setDrawValues(false);
ArrayList<LineDataSet> sets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
sets.add(d1);
sets.add(d2);

View file

@ -13,18 +13,19 @@ import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
@ -91,8 +92,14 @@ public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeL
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -119,10 +126,12 @@ public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeL
break;
}
case R.id.actionToggleFilled: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
@ -132,10 +141,12 @@ public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeL
break;
}
case R.id.actionToggleCircles: {
ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
List<ILineDataSet> sets = mChart.getData()
.getDataSets();
for (LineDataSet set : sets) {
for (ILineDataSet iSet : sets) {
LineDataSet set = (LineDataSet) iSet;
if (set.isDrawCirclesEnabled())
set.setDrawCircles(false);
else
@ -204,7 +215,7 @@ public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeL
xVals.add((i) + "");
}
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
for (int z = 0; z < 3; z++) {
@ -226,9 +237,9 @@ public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeL
}
// make the first DataSet dashed
dataSets.get(0).enableDashedLine(10, 10, 0);
dataSets.get(0).setColors(ColorTemplate.VORDIPLOM_COLORS);
dataSets.get(0).setCircleColors(ColorTemplate.VORDIPLOM_COLORS);
((LineDataSet) dataSets.get(0)).enableDashedLine(10, 10, 0);
((LineDataSet) dataSets.get(0)).setColors(ColorTemplate.VORDIPLOM_COLORS);
((LineDataSet) dataSets.get(0)).setCircleColors(ColorTemplate.VORDIPLOM_COLORS);
LineData data = new LineData(xVals, dataSets);
mChart.setData(data);

View file

@ -20,10 +20,10 @@ import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
@ -116,7 +116,7 @@ public class PieChartActivity extends DemoBase implements OnSeekBarChangeListene
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IDataSet<?> set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();

View file

@ -14,10 +14,11 @@ import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -83,14 +84,14 @@ public class RadarChartActivitry extends DemoBase {
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
for (IDataSet<?> set : mChart.getData().getDataSets())
set.setDrawValues(!set.isDrawValuesEnabled());
mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
if (mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
@ -106,10 +107,10 @@ public class RadarChartActivitry extends DemoBase {
}
case R.id.actionToggleFilled: {
ArrayList<RadarDataSet> sets = (ArrayList<RadarDataSet>) mChart.getData()
ArrayList<IRadarDataSet> sets = (ArrayList<IRadarDataSet>) mChart.getData()
.getDataSets();
for (RadarDataSet set : sets) {
for (IRadarDataSet set : sets) {
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
@ -147,7 +148,7 @@ public class RadarChartActivitry extends DemoBase {
return true;
}
private String[] mParties = new String[] {
private String[] mParties = new String[]{
"Party A", "Party B", "Party C", "Party D", "Party E", "Party F", "Party G", "Party H",
"Party I"
};
@ -186,7 +187,7 @@ public class RadarChartActivitry extends DemoBase {
set2.setDrawFilled(true);
set2.setLineWidth(2f);
ArrayList<RadarDataSet> sets = new ArrayList<RadarDataSet>();
ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>();
sets.add(set1);
sets.add(set2);

View file

@ -19,6 +19,7 @@ import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
@ -130,7 +131,7 @@ public class RealtimeLineChartActivity extends DemoBase implements
if (data != null) {
LineDataSet set = data.getDataSetByIndex(0);
ILineDataSet set = data.getDataSetByIndex(0);
// set.addEntry(...); // can be called as well
if (set == null) {

View file

@ -17,18 +17,19 @@ import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.data.ScatterDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {
@ -101,8 +102,14 @@ public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeLis
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<IScatterDataSet> sets = mChart.getData()
.getDataSets();
for (IScatterDataSet iSet : sets) {
ScatterDataSet set = (ScatterDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -213,7 +220,7 @@ public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeLis
set2.setScatterShapeSize(8f);
set3.setScatterShapeSize(8f);
ArrayList<ScatterDataSet> dataSets = new ArrayList<ScatterDataSet>();
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
dataSets.add(set1); // add the datasets
dataSets.add(set2);
dataSets.add(set3);

View file

@ -1,7 +1,5 @@
package com.xxmassdeveloper.mpchartexample;
import java.util.ArrayList;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
@ -21,17 +19,20 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyYAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
import java.util.List;
public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListener, OnChartValueSelectedListener {
private BarChart mChart;
@ -105,8 +106,14 @@ public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListe
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<IBarDataSet> sets = mChart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
BarDataSet set = (BarDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;
@ -208,7 +215,7 @@ public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListe
set1.setColors(getColors());
set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);

View file

@ -18,10 +18,10 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.formatter.ValueFormatter;
@ -31,6 +31,7 @@ import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class StackedBarActivityNegative extends DemoBase implements
OnChartValueSelectedListener {
@ -119,8 +120,14 @@ public class StackedBarActivityNegative extends DemoBase implements
switch (item.getItemId()) {
case R.id.actionToggleValues: {
for (DataSet<?> set : mChart.getData().getDataSets())
List<IBarDataSet> sets = mChart.getData()
.getDataSets();
for (IBarDataSet iSet : sets) {
BarDataSet set = (BarDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}
mChart.invalidate();
break;

View file

@ -1,8 +1,8 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.LineDataProvider;
import com.github.mikephil.charting.formatter.FillFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
/**
* Created by Philipp Jahoda on 12/09/15.
@ -16,7 +16,7 @@ public class MyFillFormatter implements FillFormatter {
}
@Override
public float getFillLinePosition(LineDataSet dataSet, LineDataProvider dataProvider) {
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
// your logic could be here
return mFillPos;
}

View file

@ -0,0 +1,169 @@
package com.xxmassdeveloper.mpchartexample.custom;
import io.realm.RealmList;
import io.realm.RealmObject;
/**
* Demo class that encapsulates data stored in realm.io database.
* This class represents data suitable for all chart-types.
*/
public class RealmDemoData extends RealmObject {
private float value;
private float open, close, high, low;
private float bubbleSize;
private RealmList<RealmFloat> stackValues;
private int xIndex;
private String xValue;
private String someStringField;
// ofc there could me more fields here...
public RealmDemoData() {
}
public RealmDemoData(float value, int xIndex, String xValue) {
this.value = value;
this.xIndex = xIndex;
this.xValue = xValue;
}
/**
* Constructor for stacked bars.
*
* @param stackValues
* @param xIndex
* @param xValue
*/
public RealmDemoData(float[] stackValues, int xIndex, String xValue) {
this.xIndex = xIndex;
this.xValue = xValue;
this.stackValues = new RealmList<>();
for (float val : stackValues) {
this.stackValues.add(new RealmFloat(val));
}
}
/**
* Constructor for candles.
*
* @param high
* @param low
* @param open
* @param close
* @param xIndex
*/
public RealmDemoData(float high, float low, float open, float close, int xIndex, String xValue) {
this.value = (high + low) / 2f;
this.high = high;
this.low = low;
this.open = open;
this.close = close;
this.xIndex = xIndex;
this.xValue = xValue;
}
/**
* Constructor for bubbles.
*
* @param value
* @param xIndex
* @param bubbleSize
* @param xValue
*/
public RealmDemoData(float value, int xIndex, float bubbleSize, String xValue) {
this.value = value;
this.xIndex = xIndex;
this.bubbleSize = bubbleSize;
this.xValue = xValue;
}
public float getValue() {
return value;
}
public void setValue(float value) {
this.value = value;
}
public RealmList<RealmFloat> getStackValues() {
return stackValues;
}
public void setStackValues(RealmList<RealmFloat> stackValues) {
this.stackValues = stackValues;
}
public int getxIndex() {
return xIndex;
}
public void setxIndex(int xIndex) {
this.xIndex = xIndex;
}
public String getxValue() {
return xValue;
}
public void setxValue(String xValue) {
this.xValue = xValue;
}
public float getOpen() {
return open;
}
public void setOpen(float open) {
this.open = open;
}
public float getClose() {
return close;
}
public void setClose(float close) {
this.close = close;
}
public float getHigh() {
return high;
}
public void setHigh(float high) {
this.high = high;
}
public float getLow() {
return low;
}
public void setLow(float low) {
this.low = low;
}
public float getBubbleSize() {
return bubbleSize;
}
public void setBubbleSize(float bubbleSize) {
this.bubbleSize = bubbleSize;
}
public String getSomeStringField() {
return someStringField;
}
public void setSomeStringField(String someStringField) {
this.someStringField = someStringField;
}
}

View file

@ -0,0 +1,27 @@
package com.xxmassdeveloper.mpchartexample.custom;
import io.realm.RealmObject;
/**
* Created by Philipp Jahoda on 09/11/15.
*/
public class RealmFloat extends RealmObject {
private float floatValue;
public RealmFloat() {
}
public RealmFloat(float floatValue) {
this.floatValue = floatValue;
}
public float getFloatValue() {
return floatValue;
}
public void setFloatValue(float value) {
this.floatValue = value;
}
}

View file

@ -21,6 +21,9 @@ import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.data.ScatterDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.FileUtils;
@ -42,7 +45,7 @@ public abstract class SimpleFragment extends Fragment {
protected BarData generateBarData(int dataSets, float range, int count) {
ArrayList<BarDataSet> sets = new ArrayList<BarDataSet>();
ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
for(int i = 0; i < dataSets; i++) {
@ -66,7 +69,7 @@ public abstract class SimpleFragment extends Fragment {
protected ScatterData generateScatterData(int dataSets, float range, int count) {
ArrayList<ScatterDataSet> sets = new ArrayList<ScatterDataSet>();
ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
@ -132,7 +135,7 @@ public abstract class SimpleFragment extends Fragment {
// DataSet ds3 = new DataSet(nsquare, "O(n\u00B2)");
// DataSet ds4 = new DataSet(nthree, "O(n\u00B3)");
ArrayList<LineDataSet> sets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "sine.txt"), "Sine function");
LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "cosine.txt"), "Cosine function");
@ -164,7 +167,7 @@ public abstract class SimpleFragment extends Fragment {
protected LineData getComplexity() {
ArrayList<LineDataSet> sets = new ArrayList<LineDataSet>();
ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "n.txt"), "O(n)");
LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "nlogn.txt"), "O(nlogn)");

View file

@ -0,0 +1,16 @@
package com.xxmassdeveloper.mpchartexample.notimportant;
/**
* Created by Philipp Jahoda on 07/12/15.
*/
public class ContentItem {
String name;
String desc;
boolean isNew = false;
public ContentItem(String n, String d) {
name = n;
desc = d;
}
}

View file

@ -2,22 +2,16 @@
package com.xxmassdeveloper.mpchartexample.notimportant;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.github.mikephil.charting.utils.Utils;
import com.xxmassdeveloper.mpchartexample.AnotherBarActivity;
@ -47,9 +41,11 @@ import com.xxmassdeveloper.mpchartexample.ScrollViewActivity;
import com.xxmassdeveloper.mpchartexample.StackedBarActivity;
import com.xxmassdeveloper.mpchartexample.StackedBarActivityNegative;
import com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo;
import com.xxmassdeveloper.mpchartexample.realm.RealmDatabaseActivityBar;
import com.xxmassdeveloper.mpchartexample.realm.RealmDatabaseActivityLine;
import com.xxmassdeveloper.mpchartexample.realm.RealmMainActivity;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity implements OnItemClickListener {
@ -126,6 +122,12 @@ public class MainActivity extends Activity implements OnItemClickListener {
"Chart in ScrollView",
"This demonstrates how to use a chart inside a ScrollView."));
ContentItem realm = new ContentItem(
"Realm.io Database",
"This demonstrates how to use this library with Realm.io mobile database.");
realm.isNew = true;
objects.add(realm);
MyAdapter adapter = new MyAdapter(this, objects);
ListView lv = (ListView) findViewById(R.id.listView1);
@ -244,6 +246,10 @@ public class MainActivity extends Activity implements OnItemClickListener {
i = new Intent(this, ScrollViewActivity.class);
startActivity(i);
break;
case 26:
i = new Intent(this, RealmMainActivity.class);
startActivity(i);
break;
}
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
@ -287,53 +293,4 @@ public class MainActivity extends Activity implements OnItemClickListener {
return true;
}
private class ContentItem {
String name;
String desc;
public ContentItem(String n, String d) {
name = n;
desc = d;
}
}
private class MyAdapter extends ArrayAdapter<ContentItem> {
public MyAdapter(Context context, List<ContentItem> objects) {
super(context, 0, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ContentItem c = getItem(position);
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setText(c.name);
holder.tvDesc.setText(c.desc);
return convertView;
}
private class ViewHolder {
TextView tvName, tvDesc;
}
}
}

View file

@ -0,0 +1,61 @@
package com.xxmassdeveloper.mpchartexample.notimportant;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.xxmassdeveloper.mpchartexample.R;
import java.util.List;
/**
* Created by philipp on 07/12/15.
*/
public class MyAdapter extends ArrayAdapter<ContentItem> {
public MyAdapter(Context context, List<ContentItem> objects) {
super(context, 0, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ContentItem c = getItem(position);
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
holder.tvNew = (TextView) convertView.findViewById(R.id.tvNew);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setText(c.name);
holder.tvDesc.setText(c.desc);
if(c.isNew)
holder.tvNew.setVisibility(View.VISIBLE);
else
holder.tvNew.setVisibility(View.GONE);
return convertView;
}
private class ViewHolder {
TextView tvName, tvDesc;
TextView tvNew;
}
}

View file

@ -0,0 +1,204 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.graphics.Typeface;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.formatter.DefaultYAxisValueFormatter;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyYAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import io.realm.Realm;
import io.realm.RealmConfiguration;
/**
* Created by Philipp Jahoda on 05/11/15.
*/
public abstract class RealmBaseActivity extends DemoBase {
protected Realm mRealm;
protected Typeface mTf;
protected void setup(Chart<?> chart) {
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
// no description text
chart.setDescription("");
chart.setNoDataTextDescription("You need to provide data for the chart.");
// enable touch gestures
chart.setTouchEnabled(true);
if (chart instanceof BarLineChartBase) {
BarLineChartBase mChart = (BarLineChartBase) chart;
mChart.setDrawGridBackground(false);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.setStartAtZero(false);
leftAxis.setTypeface(mTf);
leftAxis.setTextSize(8f);
leftAxis.setTextColor(Color.DKGRAY);
leftAxis.setValueFormatter(new PercentFormatter());
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(mTf);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(8f);
xAxis.setTextColor(Color.DKGRAY);
mChart.getAxisRight().setEnabled(false);
}
}
protected void styleData(ChartData data) {
data.setValueTypeface(mTf);
data.setValueTextSize(8f);
data.setValueTextColor(Color.DKGRAY);
data.setValueFormatter(new PercentFormatter());
}
@Override
protected void onResume() {
super.onResume();
RealmConfiguration config = new RealmConfiguration.Builder(this)
.name("myrealm.realm")
.build();
Realm.deleteRealm(config);
Realm.setDefaultConfiguration(config);
mRealm = Realm.getInstance(config);
}
@Override
protected void onPause() {
super.onPause();
mRealm.close();
}
protected void writeToDB(int objectCount) {
mRealm.beginTransaction();
mRealm.clear(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float value = 40f + (float) (Math.random() * 60f);
RealmDemoData d = new RealmDemoData(value, i, "" + i);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBStack(int objectCount) {
mRealm.beginTransaction();
mRealm.clear(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float val1 = 34f + (float) (Math.random() * 12.0f);
float val2 = 34f + (float) (Math.random() * 12.0f);
float[] stack = new float[]{val1, val2, 100 - val1 - val2};
RealmDemoData d = new RealmDemoData(stack, i, "" + i);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBCandle(int objectCount) {
mRealm.beginTransaction();
mRealm.clear(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float mult = 50;
float val = (float) (Math.random() * 40) + mult;
float high = (float) (Math.random() * 9) + 8f;
float low = (float) (Math.random() * 9) + 8f;
float open = (float) (Math.random() * 6) + 1f;
float close = (float) (Math.random() * 6) + 1f;
boolean even = i % 2 == 0;
RealmDemoData d = new RealmDemoData(val + high, val - low, even ? val + open : val - open,
even ? val - close : val + close, i, i + "");
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBBubble(int objectCount) {
mRealm.beginTransaction();
mRealm.clear(RealmDemoData.class);
for (int i = 0; i < objectCount; i++) {
float value = 30f + (float) (Math.random() * 100.0);
float size = 15f + (float) (Math.random() * 20.0);
RealmDemoData d = new RealmDemoData(value, i, size, "" + i);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
protected void writeToDBPie() {
mRealm.beginTransaction();
mRealm.clear(RealmDemoData.class);
float value1 = 15f + (float) (Math.random() * 8f);
float value2 = 15f + (float) (Math.random() * 8f);
float value3 = 15f + (float) (Math.random() * 8f);
float value4 = 15f + (float) (Math.random() * 8f);
float value5 = 100f - value1 - value2 - value3 - value4;
float[] values = new float[] { value1, value2, value3, value4, value5 };
String[] xValues = new String[]{ "iOS", "Android", "WP 10", "BlackBerry", "Other"};
for (int i = 0; i < values.length; i++) {
RealmDemoData d = new RealmDemoData(values[i], i, xValues[i]);
mRealm.copyToRealm(d);
}
mRealm.commitTransaction();
}
}

View file

@ -0,0 +1,68 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityBar extends RealmBaseActivity {
private BarChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_noseekbar);
mChart = (BarChart) findViewById(R.id.chart1);
setup(mChart);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDB(20);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries
set.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
set.setLabel("Realm BarDataSet");
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
BarData data = new BarData(result, "xValue", dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
}

View file

@ -0,0 +1,71 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BubbleChart;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityBubble extends RealmBaseActivity {
private BubbleChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_bubblechart_noseekbar);
mChart = (BubbleChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getXAxis().setDrawGridLines(false);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.setPinchZoom(true);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDBBubble(10);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
RealmBubbleDataSet<RealmDemoData> set = new RealmBubbleDataSet<RealmDemoData>(result, "value", "xIndex", "bubbleSize");
set.setLabel("Realm BubbleDataSet");
set.setColors(ColorTemplate.COLORFUL_COLORS, 110);
ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
BubbleData data = new BubbleData(result, "xValue", dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
}

View file

@ -0,0 +1,76 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityCandle extends RealmBaseActivity {
private CandleStickChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_candlechart_noseekbar);
mChart = (CandleStickChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDBCandle(50);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(result, "high", "low", "open", "close", "xIndex");
set.setLabel("Realm Realm CandleDataSet");
set.setShadowColor(Color.DKGRAY);
set.setShadowWidth(0.7f);
set.setDecreasingColor(Color.RED);
set.setDecreasingPaintStyle(Paint.Style.STROKE);
set.setIncreasingColor(Color.rgb(122, 242, 84));
set.setIncreasingPaintStyle(Paint.Style.FILL);
ArrayList<ICandleDataSet> dataSets = new ArrayList<ICandleDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
CandleData data = new CandleData(result, "xValue", dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
}

View file

@ -0,0 +1,75 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityHorizontalBar extends RealmBaseActivity {
private HorizontalBarChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_horizontalbarchart_noseekbar);
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getAxisLeft().setStartAtZero(true);
mChart.setDrawValueAboveBar(false);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDBStack(50);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex", "floatValue"); // stacked entries
set.setColors(new int[]{ColorTemplate.rgb("#8BC34A"), ColorTemplate.rgb("#FFC107"), ColorTemplate.rgb("#9E9E9E")});
set.setLabel("Mobile OS distribution");
set.setStackLabels(new String[]{"iOS", "Android", "Other"});
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
BarData data = new BarData(result, "xValue", dataSets);
styleData(data);
data.setValueTextColor(Color.WHITE);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
}

View file

@ -0,0 +1,77 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityLine extends RealmBaseActivity {
private LineChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
mChart = (LineChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getAxisLeft().setAxisMaxValue(150f);
mChart.getAxisLeft().setAxisMinValue(0f);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDB(40);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "value", "xIndex");
set.setDrawCubic(false);
set.setLabel("Realm LineDataSet");
set.setDrawCircleHole(false);
set.setColor(ColorTemplate.rgb("#FF5722"));
set.setCircleColor(ColorTemplate.rgb("#FF5722"));
set.setLineWidth(1.8f);
set.setCircleSize(3.6f);
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
LineData data = new LineData(result, "xValue", dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
}

View file

@ -0,0 +1,89 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityPie extends RealmBaseActivity {
private PieChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_piechart_noseekbar);
mChart = (PieChart) findViewById(R.id.chart1);
setup(mChart);
mChart.setCenterText(generateCenterSpannableText());
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDBPie();
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries
set.setColors(ColorTemplate.VORDIPLOM_COLORS);
set.setLabel("Example market share");
set.setSliceSpace(2);
ArrayList<IPieDataSet> dataSets = new ArrayList<IPieDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
PieData data = new PieData(result, "xValue", dataSets);
styleData(data);
data.setValueTextColor(Color.WHITE);
data.setValueTextSize(12f);
// set data
mChart.setData(data);
mChart.animateY(1400);
}
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("Realm.io\nmobile database");
s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
return s;
}
}

View file

@ -0,0 +1,77 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.graphics.Color;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.realm.implementation.RealmRadarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityRadar extends RealmBaseActivity {
private RadarChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_radarchart_noseekbar);
mChart = (RadarChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getYAxis().setEnabled(false);
mChart.setWebAlpha(180);
mChart.setWebColorInner(Color.DKGRAY);
mChart.setWebColor(Color.GRAY);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDB(7);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries
set.setLabel("Realm RadarDataSet");
set.setDrawFilled(true);
set.setColor(ColorTemplate.rgb("#009688"));
set.setFillColor(ColorTemplate.rgb("#009688"));
set.setFillAlpha(130);
set.setLineWidth(2f);
ArrayList<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
RadarData data = new RadarData(new String[] {"2013", "2014", "2015", "2016", "2017", "2018", "2019"}, dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400);
}
}

View file

@ -0,0 +1,73 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.ScatterChart;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
import java.util.ArrayList;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivityScatter extends RealmBaseActivity {
private ScatterChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_scatterchart_noseekbar);
mChart = (ScatterChart) findViewById(R.id.chart1);
setup(mChart);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);
mChart.setPinchZoom(true);
}
@Override
protected void onResume() {
super.onResume(); // setup realm
// write some demo-data into the realm.io database
writeToDB(45);
// add data to the chart
setData();
}
private void setData() {
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "value", "xIndex");
set.setLabel("Realm ScatterDataSet");
set.setScatterShapeSize(9f);
set.setColor(ColorTemplate.rgb("#CDDC39"));
set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
dataSets.add(set); // add the dataset
// create a data object with the dataset list
ScatterData data = new ScatterData(result, "xValue", dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
}

View file

@ -0,0 +1,110 @@
package com.xxmassdeveloper.mpchartexample.realm;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.notimportant.ContentItem;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import com.xxmassdeveloper.mpchartexample.notimportant.MyAdapter;
import java.util.ArrayList;
/**
* Created by Philipp Jahoda on 07/12/15.
*/
public class RealmMainActivity extends DemoBase implements AdapterView.OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
ArrayList<ContentItem> objects = new ArrayList<ContentItem>();
objects.add(new ContentItem("Line Chart", "Creating a LineChart with Realm.io database"));
objects.add(new ContentItem("Bar Chart",
"Creating a BarChart with Realm.io database"));
objects.add(new ContentItem("Horizontal Bar Chart",
"Creating a HorizontalBarChart with Realm.io database"));
objects.add(new ContentItem("Scatter Chart",
"Creating a ScatterChart with Realm.io database"));
objects.add(new ContentItem("Candle Stick Chart", "Creating a CandleStickChart with Realm.io database"));
objects.add(new ContentItem("Bubble Chart", "Creating a BubbleChart with Realm.io database"));
objects.add(new ContentItem("Pie Chart", "Creating a PieChart with Realm.io database"));
objects.add(new ContentItem("Radar Chart", "Creating a RadarChart with Realm.io database"));
MyAdapter adapter = new MyAdapter(this, objects);
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
Intent i;
switch (pos) {
case 0:
i = new Intent(this, RealmDatabaseActivityLine.class);
startActivity(i);
break;
case 1:
i = new Intent(this, RealmDatabaseActivityBar.class);
startActivity(i);
break;
case 2:
i = new Intent(this, RealmDatabaseActivityHorizontalBar.class);
startActivity(i);
break;
case 3:
i = new Intent(this, RealmDatabaseActivityScatter.class);
startActivity(i);
break;
case 4:
i = new Intent(this, RealmDatabaseActivityCandle.class);
startActivity(i);
break;
case 5:
i = new Intent(this, RealmDatabaseActivityBubble.class);
startActivity(i);
break;
case 6:
i = new Intent(this, RealmDatabaseActivityPie.class);
startActivity(i);
break;
case 7:
i = new Intent(this, RealmDatabaseActivityRadar.class);
startActivity(i);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.realm, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://realm.io"));
startActivity(i);
return super.onOptionsItemSelected(item);
}
}

View file

@ -32,10 +32,16 @@ android {
}
}
repositories {
maven {
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:support-v4:19.+'
//compile 'com.nineoldandroids:library:2.4.+'
provided 'io.realm:realm-android:0.84.1-SNAPSHOT' // "optional" dependency to realm-database API
}
android.libraryVariants.all { variant ->

View file

@ -85,7 +85,7 @@ public abstract class AbstractBuffer<T> {
* Builds up the buffer with the provided data and resets the buffer-index
* after feed-completion. This needs to run FAST.
*
* @param entries
* @param data
*/
public abstract void feed(List<T> entries);
public abstract void feed(T data);
}

View file

@ -2,10 +2,9 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import java.util.List;
public class BarBuffer extends AbstractBuffer<BarEntry> {
public class BarBuffer extends AbstractBuffer<IBarDataSet> {
protected float mBarSpace = 0f;
protected float mGroupSpace = 0f;
@ -42,9 +41,9 @@ public class BarBuffer extends AbstractBuffer<BarEntry> {
}
@Override
public void feed(List<BarEntry> entries) {
public void feed(IBarDataSet data) {
float size = entries.size() * phaseX;
float size = data.getEntryCount() * phaseX;
int dataSetOffset = (mDataSetCount - 1);
float barSpaceHalf = mBarSpace / 2f;
@ -53,7 +52,7 @@ public class BarBuffer extends AbstractBuffer<BarEntry> {
for (int i = 0; i < size; i++) {
BarEntry e = entries.get(i);
BarEntry e = data.getEntryForIndex(i);
// calculate the x-position, depending on datasetcount
float x = e.getXIndex() + e.getXIndex() * dataSetOffset + mDataSetIndex

View file

@ -2,10 +2,9 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import java.util.List;
public class CandleBodyBuffer extends AbstractBuffer<CandleEntry> {
public class CandleBodyBuffer extends AbstractBuffer<ICandleDataSet> {
private float mBodySpace = 0f;
@ -26,13 +25,13 @@ public class CandleBodyBuffer extends AbstractBuffer<CandleEntry> {
}
@Override
public void feed(List<CandleEntry> entries) {
public void feed(ICandleDataSet data) {
int size = (int)Math.ceil((mTo - mFrom) * phaseX + mFrom);
for (int i = mFrom; i < size; i++) {
CandleEntry e = entries.get(i);
CandleEntry e = data.getEntryForIndex(i);
addBody(e.getXIndex() - 0.5f + mBodySpace, e.getClose() * phaseY, e.getXIndex() + 0.5f - mBodySpace, e.getOpen() * phaseY);
}

View file

@ -2,10 +2,9 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import java.util.List;
public class CandleShadowBuffer extends AbstractBuffer<CandleEntry> {
public class CandleShadowBuffer extends AbstractBuffer<ICandleDataSet> {
public CandleShadowBuffer(int size) {
super(size);
@ -20,13 +19,13 @@ public class CandleShadowBuffer extends AbstractBuffer<CandleEntry> {
}
@Override
public void feed(List<CandleEntry> entries) {
public void feed(ICandleDataSet data) {
int size = (int)Math.ceil((mTo - mFrom) * phaseX + mFrom);
for (int i = mFrom; i < size; i++) {
CandleEntry e = entries.get(i);
CandleEntry e = data.getEntryForIndex(i);
addShadow(e.getXIndex(), e.getHigh() * phaseY, e.getXIndex(), e.getLow() * phaseY);
}

View file

@ -2,10 +2,9 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.List;
public class CircleBuffer extends AbstractBuffer<Entry> {
public class CircleBuffer extends AbstractBuffer<ILineDataSet> {
public CircleBuffer(int size) {
super(size);
@ -17,13 +16,13 @@ public class CircleBuffer extends AbstractBuffer<Entry> {
}
@Override
public void feed(List<Entry> entries) {
public void feed(ILineDataSet data) {
int size = (int)Math.ceil((mTo - mFrom) * phaseX + mFrom);
for (int i = mFrom; i < size; i++) {
Entry e = entries.get(i);
Entry e = data.getEntryForIndex(i);
addCircle(e.getXIndex(), e.getVal() * phaseY);
}

View file

@ -2,8 +2,7 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.BarEntry;
import java.util.List;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
public class HorizontalBarBuffer extends BarBuffer {
@ -12,9 +11,9 @@ public class HorizontalBarBuffer extends BarBuffer {
}
@Override
public void feed(List<BarEntry> entries) {
public void feed(IBarDataSet data) {
float size = entries.size() * phaseX;
float size = data.getEntryCount() * phaseX;
int dataSetOffset = (mDataSetCount - 1);
float barSpaceHalf = mBarSpace / 2f;
@ -23,7 +22,7 @@ public class HorizontalBarBuffer extends BarBuffer {
for (int i = 0; i < size; i++) {
BarEntry e = entries.get(i);
BarEntry e = data.getEntryForIndex(i);
// calculate the x-position, depending on datasetcount
float x = e.getXIndex() + e.getXIndex() * dataSetOffset + mDataSetIndex
@ -63,7 +62,7 @@ public class HorizontalBarBuffer extends BarBuffer {
float value = vals[k];
if(value >= 0f) {
if (value >= 0f) {
y = posY;
yStart = posY + value;
posY = yStart;

View file

@ -2,10 +2,9 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.List;
public class LineBuffer extends AbstractBuffer<Entry> {
public class LineBuffer extends AbstractBuffer<ILineDataSet> {
public LineBuffer(int size) {
super((size < 4) ? 4 : size);
@ -41,15 +40,15 @@ public class LineBuffer extends AbstractBuffer<Entry> {
}
@Override
public void feed(List<Entry> entries) {
moveTo(entries.get(mFrom).getXIndex(), entries.get(mFrom).getVal() * phaseY);
public void feed(ILineDataSet data) {
moveTo(data.getEntryForIndex(mFrom).getXIndex(), data.getEntryForIndex(mFrom).getVal() * phaseY);
int size = (int) Math.ceil((mTo - mFrom) * phaseX + mFrom);
int from = mFrom + 1;
for (int i = from; i < size; i++) {
Entry e = entries.get(i);
Entry e = data.getEntryForIndex(i);
lineTo(e.getXIndex(), e.getVal() * phaseY);
}

View file

@ -2,10 +2,9 @@
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import java.util.List;
public class ScatterBuffer extends AbstractBuffer<Entry> {
public class ScatterBuffer extends AbstractBuffer<IScatterDataSet> {
public ScatterBuffer(int size) {
super(size);
@ -17,13 +16,13 @@ public class ScatterBuffer extends AbstractBuffer<Entry> {
}
@Override
public void feed(List<Entry> entries) {
public void feed(IScatterDataSet data) {
float size = entries.size() * phaseX;
float size = data.getEntryCount() * phaseX;
for (int i = 0; i < size; i++) {
Entry e = entries.get(i);
Entry e = data.getEntryForIndex(i);
addForm(e.getXIndex(), e.getVal() * phaseY);
}

View file

@ -7,13 +7,11 @@ import android.util.Log;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.BarHighlighter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.BarDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.renderer.BarChartRenderer;
import com.github.mikephil.charting.renderer.XAxisRendererBarChart;
@ -108,7 +106,7 @@ public class BarChart extends BarLineChartBase<BarData> implements BarDataProvid
*/
public RectF getBarBounds(BarEntry e) {
BarDataSet set = mData.getDataSetForEntry(e);
IBarDataSet set = mData.getDataSetForEntry(e);
if (set == null)
return null;

View file

@ -21,11 +21,11 @@ import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.highlight.ChartHighlighter;
import com.github.mikephil.charting.interfaces.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.jobs.MoveViewJob;
import com.github.mikephil.charting.listener.BarLineChartTouchListener;
import com.github.mikephil.charting.listener.OnDrawListener;
@ -42,7 +42,7 @@ import com.github.mikephil.charting.utils.Utils;
* @author Philipp Jahoda
*/
@SuppressLint("RtlHardcoded")
public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<? extends BarLineScatterCandleBubbleDataSet<? extends Entry>>>
public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<? extends IBarLineScatterCandleBubbleDataSet<? extends Entry>>>
extends Chart<T> implements BarLineScatterCandleBubbleDataProvider {
/**
@ -1239,7 +1239,7 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
* @param y
* @return
*/
public BarLineScatterCandleBubbleDataSet<? extends Entry> getDataSetByTouchPoint(float x, float y) {
public IBarLineScatterCandleBubbleDataSet getDataSetByTouchPoint(float x, float y) {
Highlight h = getHighlightByTouchPoint(x, y);
if (h != null) {
return mData.getDataSetByIndex(h.getDataSetIndex());
@ -1259,7 +1259,7 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom()
};
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
return (pts[0] <= 0) ? 0 : (int) Math.round(pts[0] + 1.0f);
return (pts[0] <= 0) ? 0 : (int) (pts[0] + 1.0f);
}
/**
@ -1274,9 +1274,7 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
mViewPortHandler.contentRight(), mViewPortHandler.contentBottom()
};
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
return (Math.round(pts[0]) >= mData.getXValCount()) ?
mData.getXValCount() - 1 :
(int) Math.round(pts[0]);
return (pts[0] >= mData.getXValCount()) ? mData.getXValCount() - 1 : (int) pts[0];
}
/**

View file

@ -5,8 +5,8 @@ import android.content.Context;
import android.util.AttributeSet;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.BubbleDataSet;
import com.github.mikephil.charting.interfaces.BubbleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider;
import com.github.mikephil.charting.renderer.BubbleChartRenderer;
/**
@ -49,7 +49,7 @@ public class BubbleChart extends BarLineChartBase<BubbleData> implements BubbleD
mXChartMax = (float) mData.getXValCount() - 0.5f;
if (mRenderer != null) {
for (BubbleDataSet set : mData.getDataSets()) {
for (IBubbleDataSet set : mData.getDataSets()) {
final float xmin = set.getXMin();
final float xmax = set.getXMax();

View file

@ -5,7 +5,7 @@ import android.content.Context;
import android.util.AttributeSet;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.interfaces.CandleDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider;
import com.github.mikephil.charting.renderer.CandleStickChartRenderer;
/**

View file

@ -31,10 +31,10 @@ import com.github.mikephil.charting.animation.EasingFunction;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.ChartHighlighter;
import com.github.mikephil.charting.interfaces.ChartInterface;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
@ -59,7 +59,7 @@ import java.util.List;
* @author Philipp Jahoda
*/
@SuppressLint("NewApi")
public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entry>>> extends
public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Entry>>> extends
ViewGroup
implements ChartInterface {
@ -310,8 +310,8 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
// calculate how many digits are needed
calculateFormatter(data.getYMin(), data.getYMax());
for (DataSet<?> set : mData.getDataSets()) {
if (set.needsDefaultFormatter())
for (IDataSet set : mData.getDataSets()) {
if (Utils.needsDefaultFormatter(set.getValueFormatter()))
set.setValueFormatter(mDefaultFormatter);
}
@ -1394,7 +1394,7 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
for (int i = 0; i < mData.getDataSetCount(); i++) {
DataSet<? extends Entry> set = mData.getDataSetByIndex(i);
IDataSet set = mData.getDataSetByIndex(i);
Entry e = set.getEntryForXIndex(xIndex);
@ -1415,16 +1415,6 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
return mData;
}
/**
* returns the percentage the given value has of the total y-value sum
*
* @param val
* @return
*/
public float getPercentOfTotal(float val) {
return val / mData.getYValueSum() * 100f;
}
/**
* Returns the ViewPortHandler of the chart that is responsible for the
* content area of the chart and its offsets and dimensions.

View file

@ -6,29 +6,31 @@ import android.util.AttributeSet;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.BubbleDataSet;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.highlight.CombinedHighlighter;
import com.github.mikephil.charting.interfaces.BarDataProvider;
import com.github.mikephil.charting.interfaces.BubbleDataProvider;
import com.github.mikephil.charting.interfaces.CandleDataProvider;
import com.github.mikephil.charting.interfaces.LineDataProvider;
import com.github.mikephil.charting.interfaces.ScatterDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
import com.github.mikephil.charting.renderer.CombinedChartRenderer;
/**
* This chart class allows the combination of lines, bars, scatter and candle
* data all displayed in one chart area.
*
*
* @author Philipp Jahoda
*/
public class CombinedChart extends BarLineChartBase<CombinedData> implements LineDataProvider,
BarDataProvider, ScatterDataProvider, CandleDataProvider, BubbleDataProvider {
/** flag that enables or disables the highlighting arrow */
/**
* flag that enables or disables the highlighting arrow
*/
private boolean mDrawHighlightArrow = false;
/**
@ -43,7 +45,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
*/
private boolean mDrawBarShadow = false;
protected DrawOrder[] mDrawOrder = new DrawOrder[] {
protected DrawOrder[] mDrawOrder = new DrawOrder[]{
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.LINE, DrawOrder.CANDLE, DrawOrder.SCATTER
};
@ -80,14 +82,14 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
@Override
protected void calcMinMax() {
super.calcMinMax();
if (getBarData() != null || getCandleData() != null || getBubbleData() != null) {
mXChartMin = -0.5f;
mXChartMax = mData.getXVals().size() - 0.5f;
if (getBubbleData() != null) {
for (BubbleDataSet set : getBubbleData().getDataSets()) {
for (IBubbleDataSet set : getBubbleData().getDataSets()) {
final float xmin = set.getXMin();
final float xmax = set.getXMax();
@ -169,7 +171,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
/**
* set this to true to draw the highlightning arrow
*
*
* @param enabled
*/
public void setDrawHighlightArrow(boolean enabled) {
@ -179,7 +181,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
/**
* If set to true, all values are drawn above their bars, instead of below
* their top.
*
*
* @param enabled
*/
public void setDrawValueAboveBar(boolean enabled) {
@ -190,7 +192,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
/**
* If set to true, a grey area is drawn behind each bar that indicates the
* maximum value. Enabling his will reduce performance by about 50%.
*
*
* @param enabled
*/
public void setDrawBarShadow(boolean enabled) {
@ -199,7 +201,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
/**
* Returns the currently set draw order.
*
*
* @return
*/
public DrawOrder[] getDrawOrder() {
@ -211,7 +213,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
* earlier you place them in the provided array, the further they will be in
* the background. e.g. if you provide new DrawOrer[] { DrawOrder.BAR,
* DrawOrder.LINE }, the bars will be drawn behind the lines.
*
*
* @param order
*/
public void setDrawOrder(DrawOrder[] order) {

View file

@ -10,11 +10,11 @@ import android.util.Log;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.highlight.HorizontalBarHighlighter;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer;
import com.github.mikephil.charting.renderer.XAxisRendererHorizontalBarChart;
import com.github.mikephil.charting.renderer.YAxisRendererHorizontalBarChart;
@ -173,7 +173,7 @@ public class HorizontalBarChart extends BarChart {
@Override
public RectF getBarBounds(BarEntry e) {
BarDataSet set = mData.getDataSetForEntry(e);
IBarDataSet set = mData.getDataSetForEntry(e);
if (set == null)
return null;

View file

@ -5,7 +5,7 @@ import android.content.Context;
import android.util.AttributeSet;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.interfaces.LineDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.renderer.LineChartRenderer;
/**

View file

@ -12,11 +12,10 @@ import android.graphics.Typeface;
import android.text.SpannableString;
import android.util.AttributeSet;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.renderer.PieChartRenderer;
import com.github.mikephil.charting.utils.Utils;
@ -202,18 +201,17 @@ public class PieChart extends PieRadarChartBase<PieData> {
mDrawAngles = new float[mData.getYValCount()];
mAbsoluteAngles = new float[mData.getYValCount()];
List<PieDataSet> dataSets = mData.getDataSets();
List<IPieDataSet> dataSets = mData.getDataSets();
int cnt = 0;
for (int i = 0; i < mData.getDataSetCount(); i++) {
PieDataSet set = dataSets.get(i);
List<Entry> entries = set.getYVals();
IPieDataSet set = dataSets.get(i);
for (int j = 0; j < entries.size(); j++) {
for (int j = 0; j < set.getEntryCount(); j++) {
mDrawAngles[cnt] = calcAngle(Math.abs(entries.get(j).getVal()));
mDrawAngles[cnt] = calcAngle(Math.abs(set.getEntryForIndex(j).getVal()));
if (cnt == 0) {
mAbsoluteAngles[cnt] = mDrawAngles[cnt];
@ -283,7 +281,7 @@ public class PieChart extends PieRadarChartBase<PieData> {
*/
public int getDataSetIndexForIndex(int xIndex) {
List<? extends DataSet<? extends Entry>> dataSets = mData.getDataSets();
List<IPieDataSet> dataSets = mData.getDataSets();
for (int i = 0; i < dataSets.size(); i++) {
if (dataSets.get(i).getEntryForXIndex(xIndex) != null)

View file

@ -16,8 +16,8 @@ import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.PieRadarChartTouchListener;
import com.github.mikephil.charting.utils.SelectionDetail;
import com.github.mikephil.charting.utils.Utils;
@ -30,7 +30,7 @@ import java.util.List;
*
* @author Philipp Jahoda
*/
public abstract class PieRadarChartBase<T extends ChartData<? extends DataSet<? extends Entry>>>
public abstract class PieRadarChartBase<T extends ChartData<? extends IDataSet<? extends Entry>>>
extends Chart<T> {
/** holds the normalized version of the current rotation angle of the chart */
@ -451,7 +451,7 @@ public abstract class PieRadarChartBase<T extends ChartData<? extends DataSet<?
for (int i = 0; i < mData.getDataSetCount(); i++) {
DataSet<?> dataSet = mData.getDataSetByIndex(i);
IDataSet<?> dataSet = mData.getDataSetByIndex(i);
// extract all y-values from all DataSets at the given x-index
final float yVal = dataSet.getYValForXIndex(xIndex);

View file

@ -5,7 +5,7 @@ import android.content.Context;
import android.util.AttributeSet;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.interfaces.ScatterDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
import com.github.mikephil.charting.renderer.ScatterChartRenderer;
/**

View file

@ -1,15 +1,21 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.ArrayList;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Data object that represents all data for the BarChart.
*
* @author Philipp Jahoda
*/
public class BarData extends BarLineScatterCandleBubbleData<BarDataSet> {
public class BarData extends BarLineScatterCandleBubbleData<IBarDataSet> {
/** the space that is left between groups of bars */
private float mGroupSpace = 0.8f;
@ -19,6 +25,10 @@ public class BarData extends BarLineScatterCandleBubbleData<BarDataSet> {
// */
// private float mMaximumBarWidth = 100f;
public BarData(RealmResults<? extends RealmObject> result, String xValuesField, List<IBarDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public BarData() {
super();
}
@ -31,24 +41,24 @@ public class BarData extends BarLineScatterCandleBubbleData<BarDataSet> {
super(xVals);
}
public BarData(List<String> xVals, List<BarDataSet> dataSets) {
public BarData(List<String> xVals, List<IBarDataSet> dataSets) {
super(xVals, dataSets);
}
public BarData(String[] xVals, List<BarDataSet> dataSets) {
public BarData(String[] xVals, List<IBarDataSet> dataSets) {
super(xVals, dataSets);
}
public BarData(List<String> xVals, BarDataSet dataSet) {
public BarData(List<String> xVals, IBarDataSet dataSet) {
super(xVals, toList(dataSet));
}
public BarData(String[] xVals, BarDataSet dataSet) {
public BarData(String[] xVals, IBarDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<BarDataSet> toList(BarDataSet dataSet) {
List<BarDataSet> sets = new ArrayList<BarDataSet>();
private static List<IBarDataSet> toList(IBarDataSet dataSet) {
List<IBarDataSet> sets = new ArrayList<IBarDataSet>();
sets.add(dataSet);
return sets;
}

View file

@ -3,12 +3,16 @@ package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import java.util.ArrayList;
import java.util.List;
public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> implements IBarDataSet {
/** space indicator between the bars 0.1f == 10 % */
/**
* space indicator between the bars 0.1f == 10 %
*/
private float mBarSpace = 0.15f;
/**
@ -17,10 +21,14 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
*/
private int mStackSize = 1;
/** the color used for drawing the bar shadows */
/**
* the color used for drawing the bar shadows
*/
private int mBarShadowColor = Color.rgb(215, 215, 215);
/** the alpha value used to draw the highlight indicator bar */
/**
* the alpha value used to draw the highlight indicator bar
*/
private int mHighLightAlpha = 120;
/**
@ -31,7 +39,7 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
/**
* array of labels used to describe the different values of the stacked bars
*/
private String[] mStackLabels = new String[] {
private String[] mStackLabels = new String[]{
"Stack"
};
@ -100,7 +108,11 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
}
@Override
protected void calcMinMax(int start, int end) {
public void calcMinMax(int start, int end) {
if (mYVals == null)
return;
final int yValCount = mYVals.size();
if (yValCount == 0)
@ -113,9 +125,6 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
else
endValue = end;
mLastStart = start;
mLastEnd = endValue;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
@ -125,7 +134,7 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
if (e != null && !Float.isNaN(e.getVal())) {
if(e.getVals() == null) {
if (e.getVals() == null) {
if (e.getVal() < mYMin)
mYMin = e.getVal();
@ -149,21 +158,12 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
}
}
/**
* Returns the maximum number of bars that can be stacked upon another in
* this DataSet.
*
* @return
*/
@Override
public int getStackSize() {
return mStackSize;
}
/**
* Returns true if this DataSet is stacked (stacksize > 1) or not.
*
* @return
*/
@Override
public boolean isStacked() {
return mStackSize > 1 ? true : false;
}
@ -171,7 +171,7 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
/**
* returns the overall entry count, including counting each stack-value
* individually
*
*
* @return
*/
public int getEntryCountStacks() {
@ -180,25 +180,21 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
/**
* returns the space between bars in percent of the whole width of one value
*
*
* @return
*/
public float getBarSpacePercent() {
return mBarSpace * 100f;
}
/**
* returns the space between bars as the actual value (0 - 1.0f)
*
* @return
*/
@Override
public float getBarSpace() {
return mBarSpace;
}
/**
* sets the space between the bars in percent (0-100) of the total bar width
*
*
* @param percent
*/
public void setBarSpacePercent(float percent) {
@ -209,19 +205,14 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
* Sets the color used for drawing the bar-shadows. The bar shadows is a
* surface behind the bar that indicates the maximum value. Don't for get to
* use getResources().getColor(...) to set this. Or Color.rgb(...).
*
*
* @param color
*/
public void setBarShadowColor(int color) {
mBarShadowColor = color;
}
/**
* Returns the color used for drawing the bar-shadows. The bar shadows is a
* surface behind the bar that indicates the maximum value.
*
* @return
*/
@Override
public int getBarShadowColor() {
return mBarShadowColor;
}
@ -229,37 +220,28 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> {
/**
* Set the alpha value (transparency) that is used for drawing the highlight
* indicator bar. min = 0 (fully transparent), max = 255 (fully opaque)
*
*
* @param alpha
*/
public void setHighLightAlpha(int alpha) {
mHighLightAlpha = alpha;
}
/**
* Returns the alpha value (transparency) that is used for drawing the
* highlight indicator.
*
* @return
*/
@Override
public int getHighLightAlpha() {
return mHighLightAlpha;
}
/**
* Sets labels for different values of bar-stacks, in case there are one.
*
*
* @param labels
*/
public void setStackLabels(String[] labels) {
mStackLabels = labels;
}
/**
* returns the labels used for the different value-stacks
*
* @return
*/
@Override
public String[] getStackLabels() {
return mStackLabels;
}

View file

@ -1,6 +1,8 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.List;
/**
@ -8,7 +10,7 @@ import java.util.List;
*
* @author Philipp Jahoda
*/
public abstract class BarLineScatterCandleBubbleData<T extends BarLineScatterCandleBubbleDataSet<? extends Entry>>
public abstract class BarLineScatterCandleBubbleData<T extends IBarLineScatterCandleBubbleDataSet<? extends Entry>>
extends ChartData<T> {
public BarLineScatterCandleBubbleData() {

View file

@ -3,6 +3,8 @@ package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.List;
/**
@ -10,7 +12,7 @@ import java.util.List;
*
* @author Philipp Jahoda
*/
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry> extends DataSet<T> {
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry> extends DataSet<T> implements IBarLineScatterCandleBubbleDataSet<T> {
/** default highlight color */
protected int mHighLightColor = Color.rgb(255, 187, 115);
@ -30,11 +32,7 @@ public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry> extends
mHighLightColor = color;
}
/**
* Returns the color that is used for drawing the highlight indicators.
*
* @return
*/
@Override
public int getHighLightColor() {
return mHighLightColor;
}

View file

@ -0,0 +1,320 @@
package com.github.mikephil.charting.data;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Philipp Jahoda on 21/10/15.
* This is the base dataset of all DataSets. It's purpose is to implement critical methods
* provided by the IDataSet interface.
*/
public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
/**
* List representing all colors that are used for this DataSet
*/
protected List<Integer> mColors = null;
/**
* label that describes the DataSet or the data the DataSet represents
*/
private String mLabel = "DataSet";
/**
* this specifies which axis this DataSet should be plotted against
*/
protected YAxis.AxisDependency mAxisDependency = YAxis.AxisDependency.LEFT;
/**
* if true, value highlightning is enabled
*/
protected boolean mHighlightEnabled = true;
/**
* custom formatter that is used instead of the auto-formatter if set
*/
protected transient ValueFormatter mValueFormatter;
/**
* the color used for the value-text
*/
protected int mValueColor = Color.BLACK;
/**
* the typeface used for the value text
*/
protected Typeface mValueTypeface;
/**
* if true, y-values are drawn on the chart
*/
protected boolean mDrawValues = true;
/**
* the size of the value-text labels
*/
protected float mValueTextSize = 17f;
/**
* flag that indicates if the DataSet is visible or not
*/
protected boolean mVisible = true;
/**
* Default constructor.
*/
public BaseDataSet() {
mColors = new ArrayList<>();
// default color
mColors.add(Color.rgb(140, 234, 255));
}
/**
* Constructor with label.
*
* @param label
*/
public BaseDataSet(String label) {
this();
this.mLabel = label;
}
/**
* Use this method to tell the data set that the underlying data has changed.
*/
public void notifyDataSetChanged() {
calcMinMax(0, getEntryCount() - 1);
}
/**
* ###### ###### COLOR GETTING RELATED METHODS ##### ######
*/
@Override
public List<Integer> getColors() {
return mColors;
}
@Override
public int getColor() {
return mColors.get(0);
}
@Override
public int getColor(int index) {
return mColors.get(index % mColors.size());
}
/**
* ###### ###### COLOR SETTING RELATED METHODS ##### ######
*/
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. If you are using colors from the resources,
* make sure that the colors are already prepared (by calling
* getResources().getColor(...)) before adding them to the DataSet.
*
* @param colors
*/
public void setColors(List<Integer> colors) {
this.mColors = colors;
}
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. If you are using colors from the resources,
* make sure that the colors are already prepared (by calling
* getResources().getColor(...)) before adding them to the DataSet.
*
* @param colors
*/
public void setColors(int[] colors) {
this.mColors = ColorTemplate.createColors(colors);
}
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. You can use
* "new int[] { R.color.red, R.color.green, ... }" to provide colors for
* this method. Internally, the colors are resolved using
* getResources().getColor(...)
*
* @param colors
*/
public void setColors(int[] colors, Context c) {
List<Integer> clrs = new ArrayList<Integer>();
for (int color : colors) {
clrs.add(c.getResources().getColor(color));
}
mColors = clrs;
}
/**
* Adds a new color to the colors array of the DataSet.
*
* @param color
*/
public void addColor(int color) {
if (mColors == null)
mColors = new ArrayList<Integer>();
mColors.add(color);
}
/**
* Sets the one and ONLY color that should be used for this DataSet.
* Internally, this recreates the colors array and adds the specified color.
*
* @param color
*/
public void setColor(int color) {
resetColors();
mColors.add(color);
}
/**
* Sets a color with a specific alpha value.
*
* @param color
* @param alpha from 0-255
*/
public void setColor(int color, int alpha) {
setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}
/**
* Sets colors with a specific alpha value.
*
* @param colors
* @param alpha
*/
public void setColors(int[] colors, int alpha) {
for (int color : colors) {
addColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}
}
/**
* Resets all colors of this DataSet and recreates the colors array.
*/
public void resetColors() {
mColors = new ArrayList<Integer>();
}
/** ###### ###### OTHER STYLING RELATED METHODS ##### ###### */
@Override
public void setLabel(String label) {
mLabel = label;
}
@Override
public String getLabel() {
return mLabel;
}
@Override
public void setHighlightEnabled(boolean enabled) {
mHighlightEnabled = enabled;
}
@Override
public boolean isHighlightEnabled() {
return mHighlightEnabled;
}
@Override
public void setValueFormatter(ValueFormatter f) {
if (f == null)
return;
else
mValueFormatter = f;
}
@Override
public ValueFormatter getValueFormatter() {
if (mValueFormatter == null)
return new DefaultValueFormatter(1);
return mValueFormatter;
}
@Override
public void setValueTextColor(int color) {
mValueColor = color;
}
@Override
public void setValueTypeface(Typeface tf) {
mValueTypeface = tf;
}
@Override
public void setValueTextSize(float size) {
mValueTextSize = Utils.convertDpToPixel(size);
}
@Override
public int getValueTextColor() {
return mValueColor;
}
@Override
public Typeface getValueTypeface() {
return mValueTypeface;
}
@Override
public float getValueTextSize() {
return mValueTextSize;
}
@Override
public void setDrawValues(boolean enabled) {
this.mDrawValues = enabled;
}
@Override
public boolean isDrawValuesEnabled() {
return mDrawValues;
}
@Override
public void setVisible(boolean visible) {
mVisible = visible;
}
@Override
public boolean isVisible() {
return mVisible;
}
@Override
public YAxis.AxisDependency getAxisDependency() {
return mAxisDependency;
}
@Override
public void setAxisDependency(YAxis.AxisDependency dependency) {
mAxisDependency = dependency;
}
}

View file

@ -1,10 +1,19 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import java.util.ArrayList;
import java.util.List;
public class BubbleData extends BarLineScatterCandleBubbleData<BubbleDataSet> {
import io.realm.RealmObject;
import io.realm.RealmResults;
public class BubbleData extends BarLineScatterCandleBubbleData<IBubbleDataSet> {
public BubbleData(RealmResults<? extends RealmObject> result, String xValuesField, List<IBubbleDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public BubbleData() {
super();
@ -18,24 +27,24 @@ public class BubbleData extends BarLineScatterCandleBubbleData<BubbleDataSet> {
super(xVals);
}
public BubbleData(List<String> xVals, List<BubbleDataSet> dataSets) {
public BubbleData(List<String> xVals, List<IBubbleDataSet> dataSets) {
super(xVals, dataSets);
}
public BubbleData(String[] xVals, List<BubbleDataSet> dataSets) {
public BubbleData(String[] xVals, List<IBubbleDataSet> dataSets) {
super(xVals, dataSets);
}
public BubbleData(List<String> xVals, BubbleDataSet dataSet) {
public BubbleData(List<String> xVals, IBubbleDataSet dataSet) {
super(xVals, toList(dataSet));
}
public BubbleData(String[] xVals, BubbleDataSet dataSet) {
public BubbleData(String[] xVals, IBubbleDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<BubbleDataSet> toList(BubbleDataSet dataSet) {
List<BubbleDataSet> sets = new ArrayList<BubbleDataSet>();
private static List<IBubbleDataSet> toList(IBubbleDataSet dataSet) {
List<IBubbleDataSet> sets = new ArrayList<IBubbleDataSet>();
sets.add(dataSet);
return sets;
}
@ -47,7 +56,7 @@ public class BubbleData extends BarLineScatterCandleBubbleData<BubbleDataSet> {
* @param width
*/
public void setHighlightCircleWidth(float width) {
for (BubbleDataSet set : mDataSets) {
for (IBubbleDataSet set : mDataSets) {
set.setHighlightCircleWidth(width);
}
}

View file

@ -3,12 +3,13 @@ package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry> {
public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry> implements IBubbleDataSet {
// NOTE: Do not initialize these, as the calcMinMax is called by the super,
// and the initializers are called after that and can reset the values
@ -22,85 +23,66 @@ public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry
super(yVals, label);
}
/**
* Sets the width of the circle that surrounds the bubble when highlighted,
* in dp.
*
* @param width
*/
@Override
public void setHighlightCircleWidth(float width) {
mHighlightCircleWidth = Utils.convertDpToPixel(width);
}
@Override
public float getHighlightCircleWidth() {
return mHighlightCircleWidth;
}
/**
* Sets a color with a specific alpha value.
* @param color
* @param alpha from 0-255
*/
public void setColor(int color, int alpha) {
super.setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}
@Override
protected void calcMinMax(int start, int end) {
public void calcMinMax(int start, int end) {
if (mYVals == null)
return;
if (mYVals.size() == 0)
return;
final List<BubbleEntry> entries = getYVals();
int endValue;
if (end == 0)
if (end == 0 || end >= mYVals.size())
endValue = mYVals.size() - 1;
else
endValue = end;
mLastStart = start;
mLastEnd = endValue;
mYMin = yMin(entries.get(start));
mYMax = yMax(entries.get(start));
mYMin = yMin(mYVals.get(start));
mYMax = yMax(mYVals.get(start));
// need chart width to guess this properly
for (int i = start; i <= endValue; i++) {
for (int i = start; i < endValue; i++) {
final BubbleEntry entry = mYVals.get(i);
final BubbleEntry entry = entries.get(i);
final float ymin = yMin(entry);
final float ymax = yMax(entry);
if (ymin < mYMin)
{
if (ymin < mYMin) {
mYMin = ymin;
}
if (ymax > mYMax)
{
if (ymax > mYMax) {
mYMax = ymax;
}
final float xmin = xMin(entry);
final float xmax = xMax(entry);
if (xmin < mXMin)
{
if (xmin < mXMin) {
mXMin = xmin;
}
if (xmax > mXMax)
{
if (xmax > mXMax) {
mXMax = xmax;
}
final float size = largestSize(entry);
if (size > mMaxSize)
{
if (size > mMaxSize) {
mMaxSize = size;
}
}
@ -122,14 +104,17 @@ public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry
return copied;
}
@Override
public float getXMax() {
return mXMax;
}
@Override
public float getXMin() {
return mXMin;
}
@Override
public float getMaxSize() {
return mMaxSize;
}

View file

@ -1,9 +1,18 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import java.util.ArrayList;
import java.util.List;
public class CandleData extends BarLineScatterCandleBubbleData<CandleDataSet> {
import io.realm.RealmObject;
import io.realm.RealmResults;
public class CandleData extends BarLineScatterCandleBubbleData<ICandleDataSet> {
public CandleData(RealmResults<? extends RealmObject> result, String xValuesField, List<ICandleDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public CandleData() {
super();
@ -17,24 +26,24 @@ public class CandleData extends BarLineScatterCandleBubbleData<CandleDataSet> {
super(xVals);
}
public CandleData(List<String> xVals, List<CandleDataSet> dataSets) {
public CandleData(List<String> xVals, List<ICandleDataSet> dataSets) {
super(xVals, dataSets);
}
public CandleData(String[] xVals, List<CandleDataSet> dataSets) {
public CandleData(String[] xVals, List<ICandleDataSet> dataSets) {
super(xVals, dataSets);
}
public CandleData(List<String> xVals, CandleDataSet dataSet) {
public CandleData(List<String> xVals, ICandleDataSet dataSet) {
super(xVals, toList(dataSet));
}
public CandleData(String[] xVals, CandleDataSet dataSet) {
public CandleData(String[] xVals, ICandleDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<CandleDataSet> toList(CandleDataSet dataSet) {
List<CandleDataSet> sets = new ArrayList<CandleDataSet>();
private static List<ICandleDataSet> toList(ICandleDataSet dataSet) {
List<ICandleDataSet> sets = new ArrayList<ICandleDataSet>();
sets.add(dataSet);
return sets;
}

View file

@ -3,6 +3,7 @@ package com.github.mikephil.charting.data;
import android.graphics.Paint;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
@ -11,30 +12,44 @@ import java.util.List;
/**
* DataSet for the CandleStickChart.
*
*
* @author Philipp Jahoda
*/
public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> implements ICandleDataSet {
/** the width of the shadow of the candle */
/**
* the width of the shadow of the candle
*/
private float mShadowWidth = 3f;
/** the space between the candle entries, default 0.1f (10%) */
/**
* the space between the candle entries, default 0.1f (10%)
*/
private float mBodySpace = 0.1f;
/** use candle color for the shadow */
/**
* use candle color for the shadow
*/
private boolean mShadowColorSameAsCandle = false;
/** paint style when open <= close */
/**
* paint style when open <= close
*/
protected Paint.Style mIncreasingPaintStyle = Paint.Style.FILL;
/** paint style when open > close */
/**
* paint style when open > close
*/
protected Paint.Style mDecreasingPaintStyle = Paint.Style.STROKE;
/** color for open <= close */
/**
* color for open <= close
*/
protected int mIncreasingColor = ColorTemplate.COLOR_NONE;
/** color for open > close */
/**
* color for open > close
*/
protected int mDecreasingColor = ColorTemplate.COLOR_NONE;
/**
@ -69,14 +84,15 @@ public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
}
@Override
protected void calcMinMax(int start, int end) {
public void calcMinMax(int start, int end) {
// super.calcMinMax();
if (mYVals == null)
return;
if (mYVals.size() == 0)
return;
List<CandleEntry> entries = mYVals;
int endValue;
if (end == 0 || end >= mYVals.size())
@ -84,15 +100,12 @@ public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
else
endValue = end;
mLastStart = start;
mLastEnd = endValue;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
CandleEntry e = entries.get(i);
CandleEntry e = mYVals.get(i);
if (e.getLow() < mYMin)
mYMin = e.getLow();
@ -105,7 +118,7 @@ public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
/**
* Sets the space that is left out on the left and right side of each
* candle, default 0.1f (10%), max 0.45f, min 0f
*
*
* @param space
*/
public void setBodySpace(float space) {
@ -118,30 +131,21 @@ public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
mBodySpace = space;
}
/**
* Returns the space that is left out on the left and right side of each
* candle.
*
* @return
*/
@Override
public float getBodySpace() {
return mBodySpace;
}
/**
* Sets the width of the candle-shadow-line in pixels. Default 3f.
*
*
* @param width
*/
public void setShadowWidth(float width) {
mShadowWidth = Utils.convertDpToPixel(width);
}
/**
* Returns the width of the candle-shadow-line in pixels.
*
* @return
*/
@Override
public float getShadowWidth() {
return mShadowWidth;
}
@ -152,7 +156,7 @@ public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
* colors list functionality, because It's wrong to copy paste setColor,
* addColor, ... resetColors for each time when we want to add a coloring
* options for one of objects
*
*
* @author Mesrop
*/
@ -160,101 +164,77 @@ public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> {
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open > close.
* open > close.
*
* @param color
*/
public void setDecreasingColor(int color) {
mDecreasingColor = color;
}
/**
* Returns the decreasing color.
*
* @return
*/
@Override
public int getDecreasingColor() {
return mDecreasingColor;
}
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open <= close.
* open <= close.
*
* @param color
*/
public void setIncreasingColor(int color) {
mIncreasingColor = color;
}
/**
* Returns the increasing color.
*
* @return
*/
@Override
public int getIncreasingColor() {
return mIncreasingColor;
}
/**
* Returns paint style when open > close
*
* @return
*/
@Override
public Paint.Style getDecreasingPaintStyle() {
return mDecreasingPaintStyle;
}
/**
* Sets paint style when open > close
*
*
* @param decreasingPaintStyle
*/
public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) {
this.mDecreasingPaintStyle = decreasingPaintStyle;
}
/**
* Returns paint style when open <= close
*
* @return
*/
@Override
public Paint.Style getIncreasingPaintStyle() {
return mIncreasingPaintStyle;
}
/**
* Sets paint style when open <= close
*
*
* @param paintStyle
*/
public void setIncreasingPaintStyle(Paint.Style paintStyle) {
this.mIncreasingPaintStyle = paintStyle;
}
/**
* Returns shadow color for all entries
*
* @return
*/
@Override
public int getShadowColor() {
return mShadowColor;
}
/**
* Sets shadow color for all entries
*
*
* @param shadowColor
*/
public void setShadowColor(int shadowColor) {
this.mShadowColor = shadowColor;
}
/**
* Is the shadow color same as the candle color?
*
* @return
*/
@Override
public boolean getShadowColorSameAsCandle() {
return mShadowColorSameAsCandle;
}

View file

@ -5,20 +5,25 @@ import android.graphics.Typeface;
import android.util.Log;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.dynamic.DynamicRealmObject;
/**
* Class that holds all relevant data that represents the chart. That involves
* at least one (or more) DataSets, and an array of x-values.
*
* @author Philipp Jahoda
*/
public abstract class ChartData<T extends DataSet<? extends Entry>> {
public abstract class ChartData<T extends IDataSet<? extends Entry>> {
/**
* maximum y-value in the y-value array across all axes
@ -43,16 +48,6 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
*/
private int mYValCount = 0;
/**
* the last start value used for calcMinMax
*/
protected int mLastStart = 0;
/**
* the last end value used for calcMinMax
*/
protected int mLastEnd = 0;
/**
* contains the average length (in characters) an entry in the x-vals array
* has
@ -145,9 +140,8 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
protected void init() {
checkLegal();
calcMinMax(mLastStart, mLastEnd);
calcYValueCount();
calcMinMax(0, mYValCount);
calcXValAverageLength();
}
@ -180,13 +174,11 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
if (mDataSets == null)
return;
if(this instanceof ScatterData)
if (this instanceof ScatterData)
return;
for (int i = 0; i < mDataSets.size(); i++) {
if (mDataSets.get(i)
.getYVals()
.size() > mXVals.size()) {
if (mDataSets.get(i).getEntryCount() > mXVals.size()) {
throw new IllegalArgumentException(
"One or more of the DataSet Entry arrays are longer than the x-values array of this ChartData object.");
}
@ -212,21 +204,19 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
mYMin = 0f;
} else {
mLastStart = start;
mLastEnd = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = 0; i < mDataSets.size(); i++) {
mDataSets.get(i).calcMinMax(start, end);
IDataSet set = mDataSets.get(i);
set.calcMinMax(start, end);
if (mDataSets.get(i).getYMin() < mYMin)
mYMin = mDataSets.get(i).getYMin();
if (set.getYMin() < mYMin)
mYMin = set.getYMin();
if (mDataSets.get(i).getYMax() > mYMax)
mYMax = mDataSets.get(i).getYMax();
if (set.getYMax() > mYMax)
mYMax = set.getYMax();
}
if (mYMin == Float.MAX_VALUE) {
@ -242,7 +232,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
mLeftAxisMax = firstLeft.getYMax();
mLeftAxisMin = firstLeft.getYMin();
for (DataSet<?> dataSet : mDataSets) {
for (IDataSet dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.LEFT) {
if (dataSet.getYMin() < mLeftAxisMin)
mLeftAxisMin = dataSet.getYMin();
@ -261,7 +251,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
mRightAxisMax = firstRight.getYMax();
mRightAxisMin = firstRight.getYMin();
for (DataSet<?> dataSet : mDataSets) {
for (IDataSet dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.RIGHT) {
if (dataSet.getYMin() < mRightAxisMin)
mRightAxisMin = dataSet.getYMin();
@ -405,11 +395,6 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
mXVals.remove(index);
}
/**
* Returns an the array of DataSets this object holds.
*
* @return
*/
public List<T> getDataSets() {
return mDataSets;
}
@ -500,12 +485,6 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
return mDataSets.get(index);
}
/**
* Returns the DataSet object at the given index.
*
* @param index
* @return
*/
public T getDataSetByIndex(int index) {
if (mDataSets == null || index < 0 || index >= mDataSets.size())
@ -602,7 +581,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
mYValCount -= d.getEntryCount();
calcMinMax(mLastStart, mLastEnd);
calcMinMax(0, mYValCount);
}
return removed;
@ -635,8 +614,12 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) {
IDataSet set = mDataSets.get(dataSetIndex);
// add the entry to the dataset
if (!set.addEntry(e))
return;
float val = e.getVal();
T set = mDataSets.get(dataSetIndex);
if (mYValCount == 0) {
mYMin = val;
@ -675,8 +658,6 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
handleEmptyAxis(getFirstLeft(), getFirstRight());
// add the entry to the dataset
set.addEntry(e);
} else {
Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low.");
}
@ -694,19 +675,21 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
if (e == null || dataSetIndex >= mDataSets.size())
return false;
// remove the entry from the dataset
boolean removed = mDataSets.get(dataSetIndex).removeEntry(e.getXIndex());
IDataSet set = mDataSets.get(dataSetIndex);
if (removed) {
if (set != null) {
// remove the entry from the dataset
boolean removed = set.removeEntry(e);
float val = e.getVal();
if (removed) {
mYValCount -= 1;
mYValCount -= 1;
calcMinMax(0, mYValCount);
}
calcMinMax(mLastStart, mLastEnd);
}
return removed;
return removed;
} else
return false;
}
/**
@ -723,7 +706,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
if (dataSetIndex >= mDataSets.size())
return false;
T dataSet = mDataSets.get(dataSetIndex);
IDataSet dataSet = mDataSets.get(dataSetIndex);
Entry e = dataSet.getEntryForXIndex(xIndex);
if (e == null || e.getXIndex() != xIndex)
@ -790,15 +773,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
return colors;
}
/**
* Returns the index of the provided DataSet inside the DataSets array of
* this data object. Returns -1 if the DataSet was not found.
*
* @param dataSet
* @return
*/
public int getIndexOfDataSet(T dataSet) {
for (int i = 0; i < mDataSets.size(); i++) {
if (mDataSets.get(i) == dataSet)
return i;
@ -863,7 +838,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
if (f == null)
return;
else {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
set.setValueFormatter(f);
}
}
@ -876,7 +851,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
* @param color
*/
public void setValueTextColor(int color) {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
set.setValueTextColor(color);
}
}
@ -888,7 +863,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
* @param tf
*/
public void setValueTypeface(Typeface tf) {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
set.setValueTypeface(tf);
}
}
@ -900,7 +875,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
* @param size
*/
public void setValueTextSize(float size) {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
set.setValueTextSize(size);
}
}
@ -912,7 +887,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
* @param enabled
*/
public void setDrawValues(boolean enabled) {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
set.setDrawValues(enabled);
}
}
@ -923,7 +898,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
* be highlighted programmatically or by touch gesture.
*/
public void setHighlightEnabled(boolean enabled) {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
set.setHighlightEnabled(enabled);
}
}
@ -935,7 +910,7 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
* @return
*/
public boolean isHighlightEnabled() {
for (DataSet<?> set : mDataSets) {
for (IDataSet set : mDataSets) {
if (!set.isHighlightEnabled())
return false;
}
@ -951,23 +926,23 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
notifyDataChanged();
}
/**
* Checks if this data object contains the specified Entry. Returns true if
* so, false if not. NOTE: Performance is pretty bad on this one, do not
* over-use in performance critical situations.
*
* @param e
* @return
*/
public boolean contains(Entry e) {
for (T set : mDataSets) {
if (set.contains(e))
return true;
}
return false;
}
// /**
// * Checks if this data object contains the specified Entry. Returns true if
// * so, false if not. NOTE: Performance is pretty bad on this one, do not
// * over-use in performance critical situations.
// *
// * @param e
// * @return
// */
// public boolean contains(Entry e) {
//
// for (T set : mDataSets) {
// if (set.contains(e))
// return true;
// }
//
// return false;
// }
/**
* Checks if this data object contains the specified DataSet. Returns true
@ -985,4 +960,24 @@ public abstract class ChartData<T extends DataSet<? extends Entry>> {
return false;
}
/**
* Transforms the given Realm-ResultSet into a String array by using the provided xValuesField.
*
* @param result
* @param xValuesField
* @return
*/
protected static List<String> toXVals(RealmResults<? extends RealmObject> result, String xValuesField) {
List<String> xVals = new ArrayList<>();
for (RealmObject object : result) {
DynamicRealmObject dynamicObject = new DynamicRealmObject(object);
xVals.add(dynamicObject.getString(xValuesField));
}
return xVals;
}
}

View file

@ -1,6 +1,8 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.ArrayList;
import java.util.List;
@ -10,7 +12,7 @@ import java.util.List;
*
* @author Philipp Jahoda
*/
public class CombinedData extends BarLineScatterCandleBubbleData<BarLineScatterCandleBubbleDataSet<?>> {
public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatterCandleBubbleDataSet<?>> {
private LineData mLineData;
private BarData mBarData;

View file

@ -1,16 +1,6 @@
package com.github.mikephil.charting.data;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.formatter.ValueFormatter;
import java.util.ArrayList;
import java.util.List;
@ -22,12 +12,7 @@ import java.util.List;
*
* @author Philipp Jahoda
*/
public abstract class DataSet<T extends Entry> {
/**
* List representing all colors that are used for this DataSet
*/
protected List<Integer> mColors = null;
public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
/**
* the entries that this dataset represents / holds together
@ -44,60 +29,6 @@ public abstract class DataSet<T extends Entry> {
*/
protected float mYMin = 0.0f;
/**
* the last start value used for calcMinMax
*/
protected int mLastStart = 0;
/**
* the last end value used for calcMinMax
*/
protected int mLastEnd = 0;
/**
* label that describes the DataSet or the data the DataSet represents
*/
private String mLabel = "DataSet";
/**
* flag that indicates if the DataSet is visible or not
*/
private boolean mVisible = true;
/**
* if true, y-values are drawn on the chart
*/
protected boolean mDrawValues = true;
/**
* the color used for the value-text
*/
private int mValueColor = Color.BLACK;
/**
* the size of the value-text labels
*/
private float mValueTextSize = 17f;
/**
* the typeface used for the value text
*/
private Typeface mValueTypeface;
/**
* custom formatter that is used instead of the auto-formatter if set
*/
protected transient ValueFormatter mValueFormatter;
/**
* this specifies which axis this DataSet should be plotted against
*/
protected AxisDependency mAxisDependency = AxisDependency.LEFT;
/**
* if true, value highlightning is enabled
*/
protected boolean mHighlightEnabled = true;
/**
* Creates a new DataSet object with the given values it represents. Also, a
@ -108,32 +39,21 @@ public abstract class DataSet<T extends Entry> {
* @param label
*/
public DataSet(List<T> yVals, String label) {
this.mLabel = label;
super(label);
this.mYVals = yVals;
if (mYVals == null)
mYVals = new ArrayList<T>();
mColors = new ArrayList<Integer>();
// default color
mColors.add(Color.rgb(140, 234, 255));
calcMinMax(mLastStart, mLastEnd);
calcMinMax(0, mYVals.size());
}
/**
* Use this method to tell the data set that the underlying data has changed
*/
public void notifyDataSetChanged() {
calcMinMax(mLastStart, mLastEnd);
}
@Override
public void calcMinMax(int start, int end) {
if (mYVals == null)
return;
/**
* calc minimum and maximum y value
*/
protected void calcMinMax(int start, int end) {
final int yValCount = mYVals.size();
if (yValCount == 0)
@ -146,15 +66,12 @@ public abstract class DataSet<T extends Entry> {
else
endValue = end;
mLastStart = start;
mLastEnd = endValue;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
Entry e = mYVals.get(i);
T e = mYVals.get(i);
if (e != null && !Float.isNaN(e.getVal())) {
@ -172,117 +89,11 @@ public abstract class DataSet<T extends Entry> {
}
}
/**
* returns the number of y-values this DataSet represents
*
* @return
*/
@Override
public int getEntryCount() {
return mYVals.size();
}
/**
* Returns the value of the Entry object at the given xIndex. Returns
* Float.NaN if no value is at the given x-index. INFORMATION: This method
* does calculations at runtime. Do not over-use in performance critical
* situations.
*
* @param xIndex
* @return
*/
public float getYValForXIndex(int xIndex) {
Entry e = getEntryForXIndex(xIndex);
if (e != null && e.getXIndex() == xIndex)
return e.getVal();
else
return Float.NaN;
}
/**
* Returns the first Entry object found at the given xIndex with binary
* search. If the no Entry at the specified x-index is found, this method
* returns the index at the closest x-index. Returns null if no Entry object
* at that index. INFORMATION: This method does calculations at runtime. Do
* not over-use in performance critical situations.
*
* @param x
* @return
*/
public T getEntryForXIndex(int x) {
return getEntryForXIndex(x, Rounding.CLOSEST);
}
/**
* Returns the first Entry object found at the given xIndex with binary
* search. If the no Entry at the specified x-index is found, this method
* returns the index as determined by the given rounding mode. Returns null
* if no Entry object at that index. INFORMATION: This method does
* calculations at runtime. Do not over-use in performance critical
* situations.
*
* @param x
* @return
*/
public T getEntryForXIndex(int x, Rounding rounding) {
int index = getEntryIndex(x, rounding);
if (index > -1)
return mYVals.get(index);
return null;
}
/**
* Returns the first Entry index found at the given xIndex with binary
* search. If the no Entry at the specified x-index is found, this method
* returns the index as determined by the given rounding mode. Returns -1 if
* no Entry object at that index. INFORMATION: This method does calculations
* at runtime. Do not over-use in performance critical situations.
*
* @param x
* @return
*/
public int getEntryIndex(int x, Rounding rounding) {
int low = 0;
int high = mYVals.size() - 1;
int closest = -1;
while (low <= high) {
int m = (high + low) / 2;
if (x == mYVals.get(m).getXIndex()) {
while (m > 0 && mYVals.get(m - 1).getXIndex() == x)
m--;
return m;
}
if (x > mYVals.get(m).getXIndex())
low = m + 1;
else
high = m - 1;
closest = m;
}
if (closest != -1) {
int closestXIndex = mYVals.get(closest).getXIndex();
if (rounding == Rounding.UP) {
if (closestXIndex < x && closest < mYVals.size() - 1) {
++closest;
}
} else if (rounding == Rounding.DOWN) {
if (closestXIndex > x && closest > 0) {
--closest;
}
}
}
return closest;
}
/**
* Returns all Entry objects at the given xIndex. INFORMATION: This method
* does calculations at runtime. Do not over-use in performance critical
@ -327,7 +138,7 @@ public abstract class DataSet<T extends Entry> {
}
/**
* returns the DataSets Entry array
* Returns the array of y-values that this DataSet represents.
*
* @return
*/
@ -335,33 +146,6 @@ public abstract class DataSet<T extends Entry> {
return mYVals;
}
/**
* returns the minimum y-value this DataSet holds
*
* @return
*/
public float getYMin() {
return mYMin;
}
/**
* returns the maximum y-value this DataSet holds
*
* @return
*/
public float getYMax() {
return mYMax;
}
/**
* Returns the number of entries this DataSet holds.
*
* @return
*/
public int getValueCount() {
return mYVals.size();
}
/**
* The xIndex of an Entry object is provided. This method returns the actual
* index in the Entry array of the DataSet. IMPORTANT: This method does
@ -406,119 +190,18 @@ public abstract class DataSet<T extends Entry> {
*/
public String toSimpleString() {
StringBuffer buffer = new StringBuffer();
buffer.append("DataSet, label: " + (mLabel == null ? "" : mLabel) + ", entries: " + mYVals.size() + "\n");
buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mYVals.size() + "\n");
return buffer.toString();
}
/**
* Sets the label string that describes the DataSet.
*
* @return
*/
public void setLabel(String label) {
mLabel = label;
@Override
public float getYMin() {
return mYMin;
}
/**
* Returns the label string that describes the DataSet.
*
* @return
*/
public String getLabel() {
return mLabel;
}
/**
* Set the visibility of this DataSet. If not visible, the DataSet will not
* be drawn to the chart upon refreshing it.
*
* @param visible
*/
public void setVisible(boolean visible) {
mVisible = visible;
}
/**
* Returns true if this DataSet is visible inside the chart, or false if it
* is currently hidden.
*
* @return
*/
public boolean isVisible() {
return mVisible;
}
/**
* Returns the axis this DataSet should be plotted against.
*
* @return
*/
public AxisDependency getAxisDependency() {
return mAxisDependency;
}
/**
* Set the y-axis this DataSet should be plotted against (either LEFT or
* RIGHT). Default: LEFT
*
* @param dependency
*/
public void setAxisDependency(AxisDependency dependency) {
mAxisDependency = dependency;
}
/**
* set this to true to draw y-values on the chart NOTE (for bar and
* linechart): if "maxvisiblecount" is reached, no values will be drawn even
* if this is enabled
*
* @param enabled
*/
public void setDrawValues(boolean enabled) {
this.mDrawValues = enabled;
}
/**
* returns true if y-value drawing is enabled, false if not
*
* @return
*/
public boolean isDrawValuesEnabled() {
return mDrawValues;
}
/**
* Adds an Entry to the DataSet dynamically.
* Entries are added to the end of the list.
* This will also recalculate the current minimum and maximum
* values of the DataSet and the value-sum.
*
* @param e
*/
@SuppressWarnings("unchecked")
public void addEntry(Entry e) {
if (e == null)
return;
float val = e.getVal();
if (mYVals == null) {
mYVals = new ArrayList<T>();
}
if (mYVals.size() == 0) {
mYMax = val;
mYMin = val;
} else {
if (mYMax < val)
mYMax = val;
if (mYMin > val)
mYMin = val;
}
// add the entry
mYVals.add((T) e);
@Override
public float getYMax() {
return mYMax;
}
/**
@ -560,44 +243,6 @@ public abstract class DataSet<T extends Entry> {
mYVals.add((T) e);
}
/**
* Removes an Entry from the DataSets entries array. This will also
* recalculate the current minimum and maximum values of the DataSet and the
* value-sum. Returns true if an Entry was removed, false if no Entry could
* be removed.
*
* @param e
*/
public boolean removeEntry(T e) {
if (e == null)
return false;
// remove the entry
boolean removed = mYVals.remove(e);
if (removed) {
float val = e.getVal();
calcMinMax(mLastStart, mLastEnd);
}
return removed;
}
/**
* Removes the Entry object that has the given xIndex from the DataSet.
* Returns true if an Entry was removed, false if no Entry could be removed.
*
* @param xIndex
*/
public boolean removeEntry(int xIndex) {
T e = getEntryForXIndex(xIndex);
return removeEntry(e);
}
/**
* Removes the first Entry (at index 0) of this DataSet from the entries array.
* Returns true if successful, false if not.
@ -611,10 +256,7 @@ public abstract class DataSet<T extends Entry> {
boolean removed = entry != null;
if (removed) {
float val = entry.getVal();
calcMinMax(mLastStart, mLastEnd);
calcMinMax(0, mYVals.size());
}
return removed;
@ -636,244 +278,77 @@ public abstract class DataSet<T extends Entry> {
boolean removed = entry != null;
if (removed) {
float val = entry.getVal();
calcMinMax(mLastStart, mLastEnd);
calcMinMax(0, mYVals.size());
}
return removed;
}
/** BELOW THIS COLOR HANDLING */
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. If you are using colors from the resources,
* make sure that the colors are already prepared (by calling
* getResources().getColor(...)) before adding them to the DataSet.
*
* @param colors
* Removes all values from this DataSet and recalculates min and max value.
*/
public void setColors(List<Integer> colors) {
this.mColors = colors;
public void clear() {
mYVals.clear();
notifyDataSetChanged();
}
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. If you are using colors from the resources,
* make sure that the colors are already prepared (by calling
* getResources().getColor(...)) before adding them to the DataSet.
*
* @param colors
*/
public void setColors(int[] colors) {
this.mColors = ColorTemplate.createColors(colors);
}
@Override
public boolean addEntry(T e) {
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. You can use
* "new int[] { R.color.red, R.color.green, ... }" to provide colors for
* this method. Internally, the colors are resolved using
* getResources().getColor(...)
*
* @param colors
*/
public void setColors(int[] colors, Context c) {
if (e == null)
return false;
List<Integer> clrs = new ArrayList<Integer>();
float val = e.getVal();
for (int color : colors) {
clrs.add(c.getResources().getColor(color));
List<T> yVals = getYVals();
if (yVals == null) {
yVals = new ArrayList<T>();
}
mColors = clrs;
}
/**
* Adds a new color to the colors array of the DataSet.
*
* @param color
*/
public void addColor(int color) {
if (mColors == null)
mColors = new ArrayList<Integer>();
mColors.add(color);
}
/**
* Sets the one and ONLY color that should be used for this DataSet.
* Internally, this recreates the colors array and adds the specified color.
*
* @param color
*/
public void setColor(int color) {
resetColors();
mColors.add(color);
}
/**
* returns all the colors that are set for this DataSet
*
* @return
*/
public List<Integer> getColors() {
return mColors;
}
/**
* Returns the color at the given index of the DataSet's color array.
* Performs a IndexOutOfBounds check by modulus.
*
* @param index
* @return
*/
public int getColor(int index) {
return mColors.get(index % mColors.size());
}
/**
* Returns the first color (index 0) of the colors-array this DataSet
* contains.
*
* @return
*/
public int getColor() {
return mColors.get(0);
}
/**
* Resets all colors of this DataSet and recreates the colors array.
*/
public void resetColors() {
mColors = new ArrayList<Integer>();
}
/**
* If set to true, value highlighting is enabled which means that values can
* be highlighted programmatically or by touch gesture.
*
* @param enabled
*/
public void setHighlightEnabled(boolean enabled) {
mHighlightEnabled = enabled;
}
/**
* returns true if highlighting of values is enabled, false if not
*
* @return
*/
public boolean isHighlightEnabled() {
return mHighlightEnabled;
}
/**
* Returns the position of the provided entry in the DataSets Entry array.
* Returns -1 if doesn't exist.
*
* @param e
* @return
*/
public int getEntryPosition(Entry e) {
for (int i = 0; i < mYVals.size(); i++) {
if (e.equalTo(mYVals.get(i)))
return i;
if (yVals.size() == 0) {
mYMax = val;
mYMin = val;
} else {
if (mYMax < val)
mYMax = val;
if (mYMin > val)
mYMin = val;
}
return -1;
// add the entry
yVals.add(e);
return true;
}
@Override
public boolean removeEntry(T e) {
if (e == null)
return false;
if (mYVals == null)
return false;
// remove the entry
boolean removed = mYVals.remove(e);
if (removed) {
calcMinMax(0, mYVals.size());
}
return removed;
}
/**
* Sets the formatter to be used for drawing the values inside the chart. If
* no formatter is set, the chart will automatically determine a reasonable
* formatting (concerning decimals) for all the values that are drawn inside
* the chart. Use chart.getDefaultValueFormatter() to use the formatter
* calculated by the chart.
* Removes the Entry object that has the given xIndex from the DataSet.
* Returns true if an Entry was removed, false if no Entry could be removed.
*
* @param f
* @param xIndex
*/
public void setValueFormatter(ValueFormatter f) {
public boolean removeEntry(int xIndex) {
if (f == null)
return;
else
mValueFormatter = f;
}
/**
* Returns the formatter used for drawing the values inside the chart.
*
* @return
*/
public ValueFormatter getValueFormatter() {
if (mValueFormatter == null)
return new DefaultValueFormatter(1);
return mValueFormatter;
}
/**
* If this component has no ValueFormatter or is only equipped with the
* default one (no custom set), return true.
*
* @return
*/
public boolean needsDefaultFormatter() {
if (mValueFormatter == null)
return true;
if (mValueFormatter instanceof DefaultValueFormatter)
return true;
return false;
}
/**
* Sets the color the value-labels of this DataSet should have.
*
* @param color
*/
public void setValueTextColor(int color) {
mValueColor = color;
}
public int getValueTextColor() {
return mValueColor;
}
/**
* Sets a Typeface for the value-labels of this DataSet.
*
* @param tf
*/
public void setValueTypeface(Typeface tf) {
mValueTypeface = tf;
}
public Typeface getValueTypeface() {
return mValueTypeface;
}
/**
* Sets the text-size of the value-labels of this DataSet in dp.
*
* @param size
*/
public void setValueTextSize(float size) {
mValueTextSize = Utils.convertDpToPixel(size);
}
/**
* Returns the text-size of the labels that are displayed above the values.
*
* @return
*/
public float getValueTextSize() {
return mValueTextSize;
T e = getEntryForXIndex(xIndex);
return removeEntry(e);
}
/**
@ -886,7 +361,9 @@ public abstract class DataSet<T extends Entry> {
*/
public boolean contains(Entry e) {
for (Entry entry : mYVals) {
List<T> values = getYVals();
for (Entry entry : values) {
if (entry.equals(e))
return true;
}
@ -894,14 +371,87 @@ public abstract class DataSet<T extends Entry> {
return false;
}
/**
* Removes all values from this DataSet and recalculates min and max value.
*/
public void clear() {
mYVals.clear();
mLastStart = 0;
mLastEnd = 0;
notifyDataSetChanged();
@Override
public int getEntryIndex(Entry e) {
return mYVals.indexOf(e);
//
// for (int i = 0; i < mYVals.size(); i++) {
// if (e.equalTo(mYVals.get(i)))
// return i;
// }
//
// return -1;
}
@Override
public T getEntryForXIndex(int xIndex, Rounding rounding) {
int index = getEntryIndex(xIndex, rounding);
if (index > -1)
return mYVals.get(index);
return null;
}
@Override
public T getEntryForXIndex(int xIndex) {
return getEntryForXIndex(xIndex, Rounding.CLOSEST);
}
@Override
public T getEntryForIndex(int index) {
return mYVals.get(index);
}
@Override
public int getEntryIndex(int xIndex, Rounding rounding) {
int low = 0;
int high = mYVals.size() - 1;
int closest = -1;
while (low <= high) {
int m = (high + low) / 2;
if (xIndex == mYVals.get(m).getXIndex()) {
while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex)
m--;
return m;
}
if (xIndex > mYVals.get(m).getXIndex())
low = m + 1;
else
high = m - 1;
closest = m;
}
if (closest != -1) {
int closestXIndex = mYVals.get(closest).getXIndex();
if (rounding == Rounding.UP) {
if (closestXIndex < xIndex && closest < mYVals.size() - 1) {
++closest;
}
} else if (rounding == Rounding.DOWN) {
if (closestXIndex > xIndex && closest > 0) {
--closest;
}
}
}
return closest;
}
@Override
public float getYValForXIndex(int xIndex) {
Entry e = getEntryForXIndex(xIndex);
if (e != null && e.getXIndex() == xIndex)
return e.getVal();
else
return Float.NaN;
}
/**
@ -914,4 +464,4 @@ public abstract class DataSet<T extends Entry> {
DOWN,
CLOSEST,
}
}
}

View file

@ -1,15 +1,24 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.ArrayList;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Data object that encapsulates all data associated with a LineChart.
*
* @author Philipp Jahoda
*/
public class LineData extends BarLineScatterCandleBubbleData<LineDataSet> {
public class LineData extends BarLineScatterCandleBubbleData<ILineDataSet> {
public LineData(RealmResults<? extends RealmObject> result, String xValuesField, List<ILineDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public LineData() {
super();
@ -23,24 +32,24 @@ public class LineData extends BarLineScatterCandleBubbleData<LineDataSet> {
super(xVals);
}
public LineData(List<String> xVals, List<LineDataSet> dataSets) {
public LineData(List<String> xVals, List<ILineDataSet> dataSets) {
super(xVals, dataSets);
}
public LineData(String[] xVals, List<LineDataSet> dataSets) {
public LineData(String[] xVals, List<ILineDataSet> dataSets) {
super(xVals, dataSets);
}
public LineData(List<String> xVals, LineDataSet dataSet) {
public LineData(List<String> xVals, ILineDataSet dataSet) {
super(xVals, toList(dataSet));
}
public LineData(String[] xVals, LineDataSet dataSet) {
public LineData(String[] xVals, ILineDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<LineDataSet> toList(LineDataSet dataSet) {
List<LineDataSet> sets = new ArrayList<LineDataSet>();
private static List<ILineDataSet> toList(ILineDataSet dataSet) {
List<ILineDataSet> sets = new ArrayList<ILineDataSet>();
sets.add(dataSet);
return sets;
}

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
import com.github.mikephil.charting.formatter.FillFormatter;
@ -13,7 +14,7 @@ import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class LineDataSet extends LineRadarDataSet<Entry> {
public class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet {
/** List representing all colors that are used for the circles */
private List<Integer> mCircleColors = null;
@ -92,11 +93,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mCubicIntensity = intensity;
}
/**
* Returns the intensity of the cubic lines (the effect intensity).
*
* @return
*/
@Override
public float getCubicIntensity() {
return mCubicIntensity;
}
@ -111,9 +108,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mCircleSize = Utils.convertDpToPixel(size);
}
/**
* returns the circlesize
*/
@Override
public float getCircleSize() {
return mCircleSize;
}
@ -140,20 +135,12 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mDashPathEffect = null;
}
/**
* Returns true if the dashed-line effect is enabled, false if not.
*
* @return
*/
@Override
public boolean isDashedLineEnabled() {
return mDashPathEffect == null ? false : true;
}
/**
* returns the DashPathEffect that is set for this DataSet
*
* @return
*/
@Override
public DashPathEffect getDashPathEffect() {
return mDashPathEffect;
}
@ -168,11 +155,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
this.mDrawCircles = enabled;
}
/**
* returns true if drawing circles for this DataSet is enabled, false if not
*
* @return
*/
@Override
public boolean isDrawCirclesEnabled() {
return mDrawCircles;
}
@ -187,11 +170,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mDrawCubic = enabled;
}
/**
* returns true if drawing cubic lines is enabled, false if not.
*
* @return
*/
@Override
public boolean isDrawCubicEnabled() {
return mDrawCubic;
}
@ -207,13 +186,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
return mCircleColors;
}
/**
* Returns the color at the given index of the DataSet's circle-color array.
* Performs a IndexOutOfBounds check by modulus.
*
* @param index
* @return
*/
@Override
public int getCircleColor(int index) {
return mCircleColors.get(index % mCircleColors.size());
}
@ -292,11 +265,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mCircleColorHole = color;
}
/**
* Returns the color of the inner circle.
*
* @return
*/
@Override
public int getCircleHoleColor() {
return mCircleColorHole;
}
@ -310,6 +279,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mDrawCircleHole = enabled;
}
@Override
public boolean isDrawCircleHoleEnabled() {
return mDrawCircleHole;
}
@ -328,10 +298,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
mFillFormatter = formatter;
}
/**
* Returns the FillFormatter that is set for this DataSet.
* @return
*/
@Override
public FillFormatter getFillFormatter() {
return mFillFormatter;
}

View file

@ -3,6 +3,7 @@ package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.List;
@ -12,7 +13,7 @@ import java.util.List;
*
* @author Philipp Jahoda
*/
public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandleRadarDataSet<T> {
public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandleRadarDataSet<T> implements ILineRadarDataSet<T> {
/** the color that is used for filling the line surface */
private int mFillColor = Color.rgb(140, 234, 255);
@ -31,11 +32,7 @@ public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
super(yVals, label);
}
/**
* returns the color that is used for filling the line surface
*
* @return
*/
@Override
public int getFillColor() {
return mFillColor;
}
@ -49,12 +46,7 @@ public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
mFillColor = color;
}
/**
* returns the alpha value that is used for filling the line surface,
* default: 85
*
* @return
*/
@Override
public int getFillAlpha() {
return mFillAlpha;
}
@ -84,31 +76,17 @@ public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
mLineWidth = Utils.convertDpToPixel(width);
}
/**
* returns the width of the drawn chart line
*
* @return
*/
@Override
public float getLineWidth() {
return mLineWidth;
}
/**
* Set to true if the DataSet should be drawn filled (surface), and not just
* as a line, disabling this will give great performance boost! default:
* false
*
* @param filled
*/
@Override
public void setDrawFilled(boolean filled) {
mDrawFilled = filled;
}
/**
* returns true if filled drawing is enabled, false if not
*
* @return
*/
@Override
public boolean isDrawFilledEnabled() {
return mDrawFilled;
}

View file

@ -2,6 +2,7 @@ package com.github.mikephil.charting.data;
import android.graphics.DashPathEffect;
import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.List;
@ -9,7 +10,7 @@ import java.util.List;
/**
* Created by Philipp Jahoda on 11/07/15.
*/
public abstract class LineScatterCandleRadarDataSet<T extends Entry> extends BarLineScatterCandleBubbleDataSet<T> {
public abstract class LineScatterCandleRadarDataSet<T extends Entry> extends BarLineScatterCandleBubbleDataSet<T> implements ILineScatterCandleRadarDataSet<T> {
protected boolean mDrawVerticalHighlightIndicator = true;
protected boolean mDrawHorizontalHighlightIndicator = true;
@ -51,10 +52,12 @@ public abstract class LineScatterCandleRadarDataSet<T extends Entry> extends Bar
setDrawHorizontalHighlightIndicator(enabled);
}
@Override
public boolean isVerticalHighlightIndicatorEnabled() {
return mDrawVerticalHighlightIndicator;
}
@Override
public boolean isHorizontalHighlightIndicatorEnabled() {
return mDrawHorizontalHighlightIndicator;
}
@ -67,10 +70,7 @@ public abstract class LineScatterCandleRadarDataSet<T extends Entry> extends Bar
mHighlightLineWidth = Utils.convertDpToPixel(width);
}
/**
* Returns the line-width in which highlight lines are to be drawn.
* @return
*/
@Override
public float getHighlightLineWidth() {
return mHighlightLineWidth;
}
@ -105,6 +105,7 @@ public abstract class LineScatterCandleRadarDataSet<T extends Entry> extends Bar
return mHighlightDashPathEffect == null ? false : true;
}
@Override
public DashPathEffect getDashPathEffectHighlight() {
return mHighlightDashPathEffect;
}

View file

@ -1,18 +1,27 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import java.util.ArrayList;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* A PieData object can only represent one DataSet. Unlike all other charts, the
* legend labels of the PieChart are created from the x-values array, and not
* from the DataSet labels. Each PieData object can only represent one
* PieDataSet (multiple PieDataSets inside a single PieChart are not possible).
*
*
* @author Philipp Jahoda
*/
public class PieData extends ChartData<PieDataSet> {
public class PieData extends ChartData<IPieDataSet> {
public PieData(RealmResults<? extends RealmObject> result, String xValuesField, List<IPieDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public PieData() {
super();
@ -26,26 +35,26 @@ public class PieData extends ChartData<PieDataSet> {
super(xVals);
}
public PieData(List<String> xVals, PieDataSet dataSet) {
public PieData(List<String> xVals, IPieDataSet dataSet) {
super(xVals, toList(dataSet));
}
public PieData(String[] xVals, PieDataSet dataSet) {
public PieData(String[] xVals, IPieDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<PieDataSet> toList(PieDataSet dataSet) {
List<PieDataSet> sets = new ArrayList<PieDataSet>();
private static List<IPieDataSet> toList(IPieDataSet dataSet) {
List<IPieDataSet> sets = new ArrayList<IPieDataSet>();
sets.add(dataSet);
return sets;
}
/**
* Sets the PieDataSet this data object should represent.
*
*
* @param dataSet
*/
public void setDataSet(PieDataSet dataSet) {
public void setDataSet(IPieDataSet dataSet) {
mDataSets.clear();
mDataSets.add(dataSet);
init();
@ -54,21 +63,37 @@ public class PieData extends ChartData<PieDataSet> {
/**
* Returns the DataSet this PieData object represents. A PieData object can
* only contain one DataSet.
*
*
* @return
*/
public PieDataSet getDataSet() {
public IPieDataSet getDataSet() {
return mDataSets.get(0);
}
@Override
public PieDataSet getDataSetByIndex(int index) {
public IPieDataSet getDataSetByIndex(int index) {
return index == 0 ? getDataSet() : null;
}
@Override
public PieDataSet getDataSetByLabel(String label, boolean ignorecase) {
public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
: null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
}
/**
* Returns the sum of all values in this PieData object.
*
* @return
*/
public float getYValueSum() {
float sum = 0;
for (int i = 0; i < getDataSet().getEntryCount(); i++)
sum += getDataSet().getEntryForIndex(i).getVal();
return sum;
}
}

View file

@ -1,12 +1,13 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class PieDataSet extends DataSet<Entry> {
public class PieDataSet extends DataSet<Entry> implements IPieDataSet {
/** the space in degrees between the chart-slices, default 0f */
private float mSliceSpace = 0f;
@ -38,7 +39,7 @@ public class PieDataSet extends DataSet<Entry> {
/**
* sets the space that is left out between the piechart-slices, default: 0°
* --> no space, maximum 45, minimum 0 (no space)
*
*
* @param degrees
*/
public void setSliceSpace(float degrees) {
@ -51,12 +52,7 @@ public class PieDataSet extends DataSet<Entry> {
mSliceSpace = degrees;
}
/**
* returns the space that is set to be between the piechart-slices of this
* DataSet, in degrees
*
* @return
*/
@Override
public float getSliceSpace() {
return mSliceSpace;
}
@ -71,12 +67,7 @@ public class PieDataSet extends DataSet<Entry> {
mShift = Utils.convertDpToPixel(shift);
}
/**
* returns the distance a highlighted piechart slice is "shifted" away from
* the chart-center
*
* @return
*/
@Override
public float getSelectionShift() {
return mShift;
}

View file

@ -1,46 +1,55 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import java.util.ArrayList;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Data container for the RadarChart.
*
*
* @author Philipp Jahoda
*/
public class RadarData extends ChartData<RadarDataSet> {
public class RadarData extends ChartData<IRadarDataSet> {
public RadarData(RealmResults<? extends RealmObject> result, String xValuesField, List<IRadarDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public RadarData() {
super();
}
public RadarData(List<String> xVals) {
super(xVals);
}
public RadarData(String[] xVals) {
super(xVals);
}
public RadarData(List<String> xVals, List<RadarDataSet> dataSets) {
public RadarData(List<String> xVals, List<IRadarDataSet> dataSets) {
super(xVals, dataSets);
}
public RadarData(String[] xVals, List<RadarDataSet> dataSets) {
public RadarData(String[] xVals, List<IRadarDataSet> dataSets) {
super(xVals, dataSets);
}
public RadarData(List<String> xVals, RadarDataSet dataSet) {
public RadarData(List<String> xVals, IRadarDataSet dataSet) {
super(xVals, toList(dataSet));
}
public RadarData(String[] xVals, RadarDataSet dataSet) {
public RadarData(String[] xVals, IRadarDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<RadarDataSet> toList(RadarDataSet dataSet) {
List<RadarDataSet> sets = new ArrayList<RadarDataSet>();
private static List<IRadarDataSet> toList(IRadarDataSet dataSet) {
List<IRadarDataSet> sets = new ArrayList<IRadarDataSet>();
sets.add(dataSet);
return sets;
}

View file

@ -1,10 +1,12 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import java.util.ArrayList;
import java.util.List;
public class RadarDataSet extends LineRadarDataSet<Entry> {
public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataSet {
public RadarDataSet(List<Entry> yVals, String label) {
super(yVals, label);

View file

@ -1,10 +1,19 @@
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import java.util.ArrayList;
import java.util.List;
public class ScatterData extends BarLineScatterCandleBubbleData<ScatterDataSet> {
import io.realm.RealmObject;
import io.realm.RealmResults;
public class ScatterData extends BarLineScatterCandleBubbleData<IScatterDataSet> {
public ScatterData(RealmResults<? extends RealmObject> result, String xValuesField, List<IScatterDataSet> dataSets) {
super(toXVals(result, xValuesField), dataSets);
}
public ScatterData() {
super();
@ -18,24 +27,24 @@ public class ScatterData extends BarLineScatterCandleBubbleData<ScatterDataSet>
super(xVals);
}
public ScatterData(List<String> xVals, List<ScatterDataSet> dataSets) {
public ScatterData(List<String> xVals, List<IScatterDataSet> dataSets) {
super(xVals, dataSets);
}
public ScatterData(String[] xVals, List<ScatterDataSet> dataSets) {
public ScatterData(String[] xVals, List<IScatterDataSet> dataSets) {
super(xVals, dataSets);
}
public ScatterData(List<String> xVals, ScatterDataSet dataSet) {
public ScatterData(List<String> xVals, IScatterDataSet dataSet) {
super(xVals, toList(dataSet));
}
public ScatterData(String[] xVals, ScatterDataSet dataSet) {
public ScatterData(String[] xVals, IScatterDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<ScatterDataSet> toList(ScatterDataSet dataSet) {
List<ScatterDataSet> sets = new ArrayList<ScatterDataSet>();
private static List<IScatterDataSet> toList(IScatterDataSet dataSet) {
List<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
sets.add(dataSet);
return sets;
}
@ -49,7 +58,7 @@ public class ScatterData extends BarLineScatterCandleBubbleData<ScatterDataSet>
float max = 0f;
for (ScatterDataSet set : mDataSets) {
for (IScatterDataSet set : mDataSets) {
float size = set.getScatterShapeSize();
if (size > max)

View file

@ -4,14 +4,17 @@ package com.github.mikephil.charting.data;
import android.graphics.Path;
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> {
public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> implements IScatterDataSet {
/** the size the scattershape will have, in screen pixels */
/**
* the size the scattershape will have, in screen pixels
*/
private float mShapeSize = 15f;
/**
@ -25,7 +28,6 @@ public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> {
* are at. This is used when ScatterShape.CUSTOM is set for a DataSet.
*/
//private Path mCustomScatterPath = null;
public ScatterDataSet(List<Entry> yVals, String label) {
super(yVals, label);
@ -54,36 +56,28 @@ public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> {
/**
* Sets the size in density pixels the drawn scattershape will have. This
* only applies for non custom shapes.
*
*
* @param size
*/
public void setScatterShapeSize(float size) {
mShapeSize = Utils.convertDpToPixel(size);
}
/**
* returns the currently set scatter shape size
*
* @return
*/
@Override
public float getScatterShapeSize() {
return mShapeSize;
}
/**
* Sets the shape that is drawn on the position where the values are at.
*
*
* @param shape
*/
public void setScatterShape(ScatterShape shape) {
mScatterShape = shape;
}
/**
* returns all the different scattershapes the chart uses
*
* @return
*/
@Override
public ScatterShape getScatterShape() {
return mScatterShape;
}

View file

@ -0,0 +1,45 @@
package com.github.mikephil.charting.data.realm.base;
import android.graphics.Color;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 08/11/15.
*/
public abstract class RealmBarLineScatterCandleBubbleDataSet<T extends RealmObject, S extends Entry> extends RealmBaseDataSet<T, S> implements IBarLineScatterCandleBubbleDataSet<S> {
/** default highlight color */
protected int mHighLightColor = Color.rgb(255, 187, 115);
/**
* Constructor that takes the realm RealmResults, sorts & stores them.
*
* @param results
* @param yValuesField
* @param xIndexField
*/
public RealmBarLineScatterCandleBubbleDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
super(results, yValuesField, xIndexField);
}
/**
* Sets the color that is used for drawing the highlight indicators. Dont
* forget to resolve the color using getResources().getColor(...) or
* Color.rgb(...).
*
* @param color
*/
public void setHighLightColor(int color) {
mHighLightColor = color;
}
@Override
public int getHighLightColor() {
return mHighLightColor;
}
}

View file

@ -0,0 +1,298 @@
package com.github.mikephil.charting.data.realm.base;
import com.github.mikephil.charting.data.BaseDataSet;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import java.util.ArrayList;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 06/11/15.
*/
public abstract class RealmBaseDataSet<T extends RealmObject, S extends Entry> extends BaseDataSet<S> {
/**
* a list of queried realm objects
*/
protected RealmResults<T> results;
/**
* a cached list of all data read from the database
*/
protected List<S> mValues;
/**
* maximum y-value in the y-value array
*/
protected float mYMax = 0.0f;
/**
* the minimum y-value in the y-value array
*/
protected float mYMin = 0.0f;
/**
* fieldname of the column that contains the y-values of this dataset
*/
protected String mValuesField;
/**
* fieldname of the column that contains the x-indices of this dataset
*/
protected String mIndexField;
/**
* Constructor that takes the realm RealmResults, sorts & stores them.
*
* @param results
* @param yValuesField
* @param xIndexField
*/
public RealmBaseDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
this.results = results;
this.mValuesField = yValuesField;
this.mIndexField = xIndexField;
this.mValues = new ArrayList<S>();
this.results.sort(mIndexField, true);
}
/**
* Rebuilds the DataSet based on the given RealmResults.
*/
public abstract void build(RealmResults<T> results);
@Override
public float getYMin() {
//return results.min(mValuesField).floatValue();
return mYMin;
}
@Override
public float getYMax() {
//return results.max(mValuesField).floatValue();
return mYMax;
}
@Override
public int getEntryCount() {
return mValues.size();
}
@Override
public void calcMinMax(int start, int end) {
if (mValues == null)
return;
final int yValCount = mValues.size();
if (yValCount == 0)
return;
int endValue;
if (end == 0 || end >= yValCount)
endValue = yValCount - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
S e = mValues.get(i);
if (e != null && !Float.isNaN(e.getVal())) {
if (e.getVal() < mYMin)
mYMin = e.getVal();
if (e.getVal() > mYMax)
mYMax = e.getVal();
}
}
if (mYMin == Float.MAX_VALUE) {
mYMin = 0.f;
mYMax = 0.f;
}
}
@Override
public S getEntryForXIndex(int xIndex) {
//DynamicRealmObject o = new DynamicRealmObject(results.where().equalTo(mIndexField, xIndex).findFirst());
//return new Entry(o.getFloat(mValuesField), o.getInt(mIndexField));
return getEntryForXIndex(xIndex, DataSet.Rounding.CLOSEST);
}
@Override
public S getEntryForXIndex(int xIndex, DataSet.Rounding rounding) {
int index = getEntryIndex(xIndex, rounding);
if (index > -1)
return mValues.get(index);
return null;
}
@Override
public S getEntryForIndex(int index) {
//DynamicRealmObject o = new DynamicRealmObject(results.get(index));
//return new Entry(o.getFloat(mValuesField), o.getInt(mIndexField));
return mValues.get(index);
}
@Override
public int getEntryIndex(int x, DataSet.Rounding rounding) {
int low = 0;
int high = mValues.size() - 1;
int closest = -1;
while (low <= high) {
int m = (high + low) / 2;
if (x == mValues.get(m).getXIndex()) {
while (m > 0 && mValues.get(m - 1).getXIndex() == x)
m--;
return m;
}
if (x > mValues.get(m).getXIndex())
low = m + 1;
else
high = m - 1;
closest = m;
}
if (closest != -1) {
int closestXIndex = mValues.get(closest).getXIndex();
if (rounding == DataSet.Rounding.UP) {
if (closestXIndex < x && closest < mValues.size() - 1) {
++closest;
}
} else if (rounding == DataSet.Rounding.DOWN) {
if (closestXIndex > x && closest > 0) {
--closest;
}
}
}
return closest;
}
@Override
public int getEntryIndex(S e) {
return mValues.indexOf(e);
}
@Override
public float getYValForXIndex(int xIndex) {
//return new DynamicRealmObject(results.where().greaterThanOrEqualTo(mIndexField, xIndex).findFirst()).getFloat(mValuesField);
Entry e = getEntryForXIndex(xIndex);
if (e != null && e.getXIndex() == xIndex)
return e.getVal();
else
return Float.NaN;
}
@Override
public boolean addEntry(S e) {
if (e == null)
return false;
float val = e.getVal();
if (mValues == null) {
mValues = new ArrayList<S>();
}
if (mValues.size() == 0) {
mYMax = val;
mYMin = val;
} else {
if (mYMax < val)
mYMax = val;
if (mYMin > val)
mYMin = val;
}
// add the entry
mValues.add(e);
return true;
}
@Override
public boolean removeEntry(S e) {
if (e == null)
return false;
if (mValues == null)
return false;
// remove the entry
boolean removed = mValues.remove(e);
if (removed) {
calcMinMax(0, mValues.size());
}
return removed;
}
/**
* Returns the List of values that has been extracted from the RealmResults
* using the provided fieldnames.
*
* @return
*/
public List<S> getValues() {
return mValues;
}
/**
* Clears all values from the DataSet.
*/
public void clearValues() {
mValues.clear();
notifyDataSetChanged();
}
public RealmResults<T> getResults() {
return results;
}
public String getValuesField() {
return mValuesField;
}
/**
* Sets the field name that is used for getting the y-values out of the RealmResultSet.
*
* @param yValuesField
*/
public void setValuesField(String yValuesField) {
this.mValuesField = yValuesField;
}
public String getIndexField() {
return mIndexField;
}
/**
* Sets the field name that is used for getting the x-indices out of the RealmResultSet.
*
* @param xIndexField
*/
public void setIndexField(String xIndexField) {
this.mIndexField = xIndexField;
}
}

View file

@ -0,0 +1,98 @@
package com.github.mikephil.charting.data.realm.base;
import android.graphics.Color;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 08/11/15.
*/
public abstract class RealmLineRadarDataSet<T extends RealmObject, S extends Entry> extends RealmLineScatterCandleRadarDataSet<T, S> implements ILineRadarDataSet<S> {
/** the color that is used for filling the line surface */
private int mFillColor = Color.rgb(140, 234, 255);
/** transparency used for filling line surface */
private int mFillAlpha = 85;
/** the width of the drawn data lines */
private float mLineWidth = 2.5f;
/** if true, the data will also be drawn filled */
private boolean mDrawFilled = false;
/**
* Constructor that takes the realm RealmResults, sorts & stores them.
*
* @param results
* @param yValuesField
* @param xIndexField
*/
public RealmLineRadarDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
super(results, yValuesField, xIndexField);
}
@Override
public int getFillColor() {
return mFillColor;
}
/**
* sets the color that is used for filling the line surface
*
* @param color
*/
public void setFillColor(int color) {
mFillColor = color;
}
@Override
public int getFillAlpha() {
return mFillAlpha;
}
/**
* sets the alpha value (transparency) that is used for filling the line
* surface (0-255), default: 85
*
* @param alpha
*/
public void setFillAlpha(int alpha) {
mFillAlpha = alpha;
}
/**
* set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
* thinner line == better performance, thicker line == worse performance
*
* @param width
*/
public void setLineWidth(float width) {
if (width < 0.2f)
width = 0.2f;
if (width > 10.0f)
width = 10.0f;
mLineWidth = Utils.convertDpToPixel(width);
}
@Override
public float getLineWidth() {
return mLineWidth;
}
@Override
public void setDrawFilled(boolean filled) {
mDrawFilled = filled;
}
@Override
public boolean isDrawFilledEnabled() {
return mDrawFilled;
}
}

View file

@ -0,0 +1,119 @@
package com.github.mikephil.charting.data.realm.base;
import android.graphics.DashPathEffect;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 08/11/15.
*/
public abstract class RealmLineScatterCandleRadarDataSet<T extends RealmObject, S extends Entry> extends RealmBarLineScatterCandleBubbleDataSet<T, S> implements ILineScatterCandleRadarDataSet<S> {
protected boolean mDrawVerticalHighlightIndicator = true;
protected boolean mDrawHorizontalHighlightIndicator = true;
/** the width of the highlight indicator lines */
protected float mHighlightLineWidth = 0.5f;
/** the path effect for dashed highlight-lines */
protected DashPathEffect mHighlightDashPathEffect = null;
/**
* Constructor that takes the realm RealmResults, sorts & stores them.
*
* @param results
* @param yValuesField
* @param xIndexField
*/
public RealmLineScatterCandleRadarDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
super(results, yValuesField, xIndexField);
}
/**
* Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn.
* @param enabled
*/
public void setDrawHorizontalHighlightIndicator(boolean enabled) {
this.mDrawHorizontalHighlightIndicator = enabled;
}
/**
* Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn.
* @param enabled
*/
public void setDrawVerticalHighlightIndicator(boolean enabled) {
this.mDrawVerticalHighlightIndicator = enabled;
}
/**
* Enables / disables both vertical and horizontal highlight-indicators.
* @param enabled
*/
public void setDrawHighlightIndicators(boolean enabled) {
setDrawVerticalHighlightIndicator(enabled);
setDrawHorizontalHighlightIndicator(enabled);
}
@Override
public boolean isVerticalHighlightIndicatorEnabled() {
return mDrawVerticalHighlightIndicator;
}
@Override
public boolean isHorizontalHighlightIndicatorEnabled() {
return mDrawHorizontalHighlightIndicator;
}
/**
* Sets the width of the highlight line in dp.
* @param width
*/
public void setHighlightLineWidth(float width) {
mHighlightLineWidth = Utils.convertDpToPixel(width);
}
@Override
public float getHighlightLineWidth() {
return mHighlightLineWidth;
}
/**
* Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -"
*
* @param lineLength the length of the line pieces
* @param spaceLength the length of space inbetween the line-pieces
* @param phase offset, in degrees (normally, use 0)
*/
public void enableDashedHighlightLine(float lineLength, float spaceLength, float phase) {
mHighlightDashPathEffect = new DashPathEffect(new float[] {
lineLength, spaceLength
}, phase);
}
/**
* Disables the highlight-line to be drawn in dashed mode.
*/
public void disableDashedHighlightLine() {
mHighlightDashPathEffect = null;
}
/**
* Returns true if the dashed-line effect is enabled for highlight lines, false if not.
* Default: disabled
*
* @return
*/
public boolean isDashedHighlightLineEnabled() {
return mHighlightDashPathEffect == null ? false : true;
}
@Override
public DashPathEffect getDashPathEffectHighlight() {
return mHighlightDashPathEffect;
}
}

View file

@ -0,0 +1,244 @@
package com.github.mikephil.charting.data.realm.implementation;
import android.graphics.Color;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.dynamic.DynamicRealmList;
import io.realm.dynamic.DynamicRealmObject;
/**
* Created by Philipp Jahoda on 07/11/15.
*/
public class RealmBarDataSet<T extends RealmObject> extends RealmBarLineScatterCandleBubbleDataSet<T, BarEntry> implements IBarDataSet {
private String mStackValueFieldName;
/**
* space indicator between the bars 0.1f == 10 %
*/
private float mBarSpace = 0.15f;
/**
* the maximum number of bars that are stacked upon each other, this value
* is calculated from the Entries that are added to the DataSet
*/
private int mStackSize = 1;
/**
* the color used for drawing the bar shadows
*/
private int mBarShadowColor = Color.rgb(215, 215, 215);
/**
* the alpha value used to draw the highlight indicator bar
*/
private int mHighLightAlpha = 120;
/**
* array of labels used to describe the different values of the stacked bars
*/
private String[] mStackLabels = new String[]{
"Stack"
};
public RealmBarDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
super(results, yValuesField, xIndexField);
mHighLightColor = Color.rgb(0, 0, 0);
build(this.results);
calcMinMax(0, results.size());
}
/**
* Constructor for supporting stacked values.
*
* @param results
* @param yValuesField
* @param xIndexField
* @param stackValueFieldName
*/
public RealmBarDataSet(RealmResults<T> results, String yValuesField, String xIndexField, String stackValueFieldName) {
super(results, yValuesField, xIndexField);
this.mStackValueFieldName = stackValueFieldName;
mHighLightColor = Color.rgb(0, 0, 0);
build(this.results);
calcMinMax(0, results.size());
}
@Override
public void build(RealmResults<T> results) {
for (T realmObject : results) {
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
try {
float value = dynamicObject.getFloat(mValuesField);
mValues.add(new BarEntry(value, dynamicObject.getInt(mIndexField)));
} catch (IllegalArgumentException e) {
DynamicRealmList list = dynamicObject.getList(mValuesField);
float[] values = new float[list.size()];
int i = 0;
for (DynamicRealmObject o : list) {
values[i] = o.getFloat(mStackValueFieldName);
i++;
}
mValues.add(new BarEntry(values, dynamicObject.getInt(mIndexField)));
}
}
calcStackSize();
}
@Override
public void calcMinMax(int start, int end) {
if (mValues == null)
return;
final int yValCount = mValues.size();
if (yValCount == 0)
return;
int endValue;
if (end == 0 || end >= yValCount)
endValue = yValCount - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
BarEntry e = mValues.get(i);
if (e != null && !Float.isNaN(e.getVal())) {
if (e.getVals() == null) {
if (e.getVal() < mYMin)
mYMin = e.getVal();
if (e.getVal() > mYMax)
mYMax = e.getVal();
} else {
if (-e.getNegativeSum() < mYMin)
mYMin = -e.getNegativeSum();
if (e.getPositiveSum() > mYMax)
mYMax = e.getPositiveSum();
}
}
}
if (mYMin == Float.MAX_VALUE) {
mYMin = 0.f;
mYMax = 0.f;
}
}
private void calcStackSize() {
for (int i = 0; i < mValues.size(); i++) {
float[] vals = mValues.get(i).getVals();
if (vals != null && vals.length > mStackSize)
mStackSize = vals.length;
}
}
@Override
public int getStackSize() {
return mStackSize;
}
@Override
public boolean isStacked() {
return mStackSize > 1 ? true : false;
}
/**
* returns the space between bars in percent of the whole width of one value
*
* @return
*/
public float getBarSpacePercent() {
return mBarSpace * 100f;
}
@Override
public float getBarSpace() {
return mBarSpace;
}
/**
* sets the space between the bars in percent (0-100) of the total bar width
*
* @param percent
*/
public void setBarSpacePercent(float percent) {
mBarSpace = percent / 100f;
}
/**
* Sets the color used for drawing the bar-shadows. The bar shadows is a
* surface behind the bar that indicates the maximum value. Don't for get to
* use getResources().getColor(...) to set this. Or Color.rgb(...).
*
* @param color
*/
public void setBarShadowColor(int color) {
mBarShadowColor = color;
}
@Override
public int getBarShadowColor() {
return mBarShadowColor;
}
/**
* Set the alpha value (transparency) that is used for drawing the highlight
* indicator bar. min = 0 (fully transparent), max = 255 (fully opaque)
*
* @param alpha
*/
public void setHighLightAlpha(int alpha) {
mHighLightAlpha = alpha;
}
@Override
public int getHighLightAlpha() {
return mHighLightAlpha;
}
/**
* Sets labels for different values of bar-stacks, in case there are one.
*
* @param labels
*/
public void setStackLabels(String[] labels) {
mStackLabels = labels;
}
@Override
public String[] getStackLabels() {
return mStackLabels;
}
}

View file

@ -0,0 +1,162 @@
package com.github.mikephil.charting.data.realm.implementation;
import android.graphics.Color;
import com.github.mikephil.charting.data.BubbleEntry;
import com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.utils.Utils;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.dynamic.DynamicRealmObject;
/**
* Created by Philipp Jahoda on 07/11/15.
*/
public class RealmBubbleDataSet<T extends RealmObject> extends RealmBarLineScatterCandleBubbleDataSet<T, BubbleEntry> implements IBubbleDataSet {
private String mSizeField;
protected float mXMax;
protected float mXMin;
protected float mMaxSize;
private float mHighlightCircleWidth = 2.5f;
public RealmBubbleDataSet(RealmResults<T> result, String yValuesField, String xIndexField, String sizeField) {
super(result, yValuesField, xIndexField);
this.mSizeField = sizeField;
build(this.results);
calcMinMax(0, results.size());
}
@Override
public void build(RealmResults<T> results) {
for (T object : results) {
DynamicRealmObject dynamicObject = new DynamicRealmObject(object);
mValues.add(new BubbleEntry(dynamicObject.getInt(mIndexField), dynamicObject.getFloat(mValuesField), dynamicObject.getFloat(mSizeField)));
}
}
@Override
public void calcMinMax(int start, int end) {
if (mValues == null)
return;
if (mValues.size() == 0)
return;
int endValue;
if (end == 0 || end >= mValues.size())
endValue = mValues.size() - 1;
else
endValue = end;
mYMin = yMin(mValues.get(start));
mYMax = yMax(mValues.get(start));
// need chart width to guess this properly
for (int i = start; i < endValue; i++) {
final BubbleEntry entry = mValues.get(i);
final float ymin = yMin(entry);
final float ymax = yMax(entry);
if (ymin < mYMin) {
mYMin = ymin;
}
if (ymax > mYMax) {
mYMax = ymax;
}
final float xmin = xMin(entry);
final float xmax = xMax(entry);
if (xmin < mXMin) {
mXMin = xmin;
}
if (xmax > mXMax) {
mXMax = xmax;
}
final float size = largestSize(entry);
if (size > mMaxSize) {
mMaxSize = size;
}
}
}
@Override
public float getXMax() {
return mXMax;
}
@Override
public float getXMin() {
return mXMin;
}
@Override
public float getMaxSize() {
return mMaxSize;
}
private float yMin(BubbleEntry entry) {
return entry.getVal();
}
private float yMax(BubbleEntry entry) {
return entry.getVal();
}
private float xMin(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float xMax(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float largestSize(BubbleEntry entry) {
return entry.getSize();
}
@Override
public void setHighlightCircleWidth(float width) {
mHighlightCircleWidth = Utils.convertDpToPixel(width);
}
@Override
public float getHighlightCircleWidth() {
return mHighlightCircleWidth;
}
/**
* Sets the database fieldname for the bubble size.
*
* @param sizeField
*/
public void setSizeField(String sizeField) {
this.mSizeField = sizeField;
}
/**
* Returns the database fieldname that stores bubble size.
*
* @return
*/
public String getSizeField() {
return mSizeField;
}
}

Some files were not shown because too many files have changed in this diff Show more