Search in sources :

Example 1 with ScatterData

use of com.github.mikephil.charting.data.ScatterData in project MPAndroidChart by PhilJay.

the class CombinedChartActivity method generateScatterData.

protected ScatterData generateScatterData() {
    ScatterData d = new ScatterData();
    ArrayList<Entry> entries = new ArrayList<Entry>();
    for (float index = 0; index < itemcount; index += 0.5f) entries.add(new Entry(index + 0.25f, getRandom(10, 55)));
    ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet");
    set.setColors(ColorTemplate.MATERIAL_COLORS);
    set.setScatterShapeSize(7.5f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    d.addDataSet(set);
    return d;
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 2 with ScatterData

use of com.github.mikephil.charting.data.ScatterData in project MPAndroidChart by PhilJay.

the class ChartDataTest method testDynamicChartData.

@Test
public void testDynamicChartData() {
    List<Entry> entries1 = new ArrayList<Entry>();
    entries1.add(new Entry(10, 10));
    entries1.add(new Entry(15, -2));
    entries1.add(new Entry(21, 50));
    ScatterDataSet set1 = new ScatterDataSet(entries1, "");
    List<Entry> entries2 = new ArrayList<Entry>();
    entries2.add(new Entry(-1, 10));
    entries2.add(new Entry(10, 2));
    entries2.add(new Entry(20, 5));
    ScatterDataSet set2 = new ScatterDataSet(entries2, "");
    ScatterData data = new ScatterData(set1, set2);
    assertEquals(-2, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(50f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(6, data.getEntryCount());
    assertEquals(-1f, data.getXMin(), 0.01f);
    assertEquals(21f, data.getXMax(), 0.01f);
    assertEquals(-2f, data.getYMin(), 0.01f);
    assertEquals(50f, data.getYMax(), 0.01f);
    assertEquals(3, data.getMaxEntryCountSet().getEntryCount());
    // now add and remove values
    data.addEntry(new Entry(-10, -10), 0);
    assertEquals(set1, data.getMaxEntryCountSet());
    assertEquals(4, data.getMaxEntryCountSet().getEntryCount());
    assertEquals(-10f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(50f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-10f, data.getXMin(), 0.01f);
    assertEquals(21f, data.getXMax(), 0.01f);
    assertEquals(-10f, data.getYMin(), 0.01f);
    assertEquals(50f, data.getYMax(), 0.01f);
    data.addEntry(new Entry(-100, 100), 0);
    data.addEntry(new Entry(0, -100), 0);
    assertEquals(-100f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(100f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    // right axis will adapt left axis values if no right axis values are present
    assertEquals(-100, data.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(100f, data.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    List<Entry> entries3 = new ArrayList<Entry>();
    entries3.add(new Entry(0, 200));
    entries3.add(new Entry(0, -50));
    ScatterDataSet set3 = new ScatterDataSet(entries3, "");
    set3.setAxisDependency(YAxis.AxisDependency.RIGHT);
    data.addDataSet(set3);
    assertEquals(3, data.getDataSetCount());
    assertEquals(-100f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(100f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-50f, data.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(200f, data.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    LineData lineData = new LineData();
    assertEquals(Float.MAX_VALUE, lineData.getYMin(), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(0, lineData.getDataSetCount());
    List<Entry> lineEntries1 = new ArrayList<Entry>();
    lineEntries1.add(new Entry(10, 90));
    lineEntries1.add(new Entry(1000, 1000));
    LineDataSet lineSet1 = new LineDataSet(lineEntries1, "");
    lineData.addDataSet(lineSet1);
    assertEquals(1, lineData.getDataSetCount());
    assertEquals(2, lineSet1.getEntryCount());
    assertEquals(2, lineData.getEntryCount());
    assertEquals(10, lineData.getXMin(), 0.01f);
    assertEquals(1000f, lineData.getXMax(), 0.01f);
    assertEquals(90, lineData.getYMin(), 0.01f);
    assertEquals(1000, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(1000, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    List<Entry> lineEntries2 = new ArrayList<Entry>();
    lineEntries2.add(new Entry(-1000, 2000));
    lineEntries2.add(new Entry(2000, -3000));
    Entry e = new Entry(-1000, 2500);
    lineEntries2.add(e);
    LineDataSet lineSet2 = new LineDataSet(lineEntries2, "");
    lineSet2.setAxisDependency(YAxis.AxisDependency.RIGHT);
    lineData.addDataSet(lineSet2);
    assertEquals(2, lineData.getDataSetCount());
    assertEquals(3, lineSet2.getEntryCount());
    assertEquals(5, lineData.getEntryCount());
    assertEquals(-1000, lineData.getXMin(), 0.01f);
    assertEquals(2000, lineData.getXMax(), 0.01f);
    assertEquals(-3000, lineData.getYMin(), 0.01f);
    assertEquals(2500, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-3000, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(2500, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertTrue(lineData.removeEntry(e, 1));
    assertEquals(-1000, lineData.getXMin(), 0.01f);
    assertEquals(2000, lineData.getXMax(), 0.01f);
    assertEquals(-3000, lineData.getYMin(), 0.01f);
    assertEquals(2000, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-3000, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(2000, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(2, lineData.getDataSetCount());
    assertTrue(lineData.removeDataSet(lineSet2));
    assertEquals(1, lineData.getDataSetCount());
    assertEquals(10, lineData.getXMin(), 0.01f);
    assertEquals(1000, lineData.getXMax(), 0.01f);
    assertEquals(90, lineData.getYMin(), 0.01f);
    assertEquals(1000, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(1000, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertTrue(lineData.removeDataSet(lineSet1));
    assertEquals(0, lineData.getDataSetCount());
    assertEquals(Float.MAX_VALUE, lineData.getXMin(), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getXMax(), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertFalse(lineData.removeDataSet(lineSet1));
    assertFalse(lineData.removeDataSet(lineSet2));
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData) Test(org.junit.Test)

Example 3 with ScatterData

use of com.github.mikephil.charting.data.ScatterData in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityScatter method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
    set.setLabel("Realm ScatterDataSet");
    set.setScatterShapeSize(9f);
    set.setColor(ColorTemplate.rgb("#CDDC39"));
    set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    ScatterData data = new ScatterData(dataSets);
    styleData(data);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ArrayList(java.util.ArrayList) RealmScatterDataSet(com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 4 with ScatterData

use of com.github.mikephil.charting.data.ScatterData in project MPAndroidChart by PhilJay.

the class SimpleFragment method generateScatterData.

protected ScatterData generateScatterData(int dataSets, float range, int count) {
    ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
    ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();
    for (int i = 0; i < dataSets; i++) {
        ArrayList<Entry> entries = new ArrayList<Entry>();
        for (int j = 0; j < count; j++) {
            entries.add(new Entry(j, (float) (Math.random() * range) + range / 4));
        }
        ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
        ds.setScatterShapeSize(12f);
        ds.setScatterShape(shapes[i % shapes.length]);
        ds.setColors(ColorTemplate.COLORFUL_COLORS);
        ds.setScatterShapeSize(9f);
        sets.add(ds);
    }
    ScatterData d = new ScatterData(sets);
    d.setValueTypeface(tf);
    return d;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) PieEntry(com.github.mikephil.charting.data.PieEntry) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 5 with ScatterData

use of com.github.mikephil.charting.data.ScatterData in project MPAndroidChart by PhilJay.

the class ScatterChartActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    tvX.setText("" + (mSeekBarX.getProgress() + 1));
    tvY.setText("" + (mSeekBarY.getProgress()));
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    ArrayList<Entry> yVals2 = new ArrayList<Entry>();
    ArrayList<Entry> yVals3 = new ArrayList<Entry>();
    for (int i = 0; i < mSeekBarX.getProgress(); i++) {
        float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
        yVals1.add(new Entry(i, val));
    }
    for (int i = 0; i < mSeekBarX.getProgress(); i++) {
        float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
        yVals2.add(new Entry(i + 0.33f, val));
    }
    for (int i = 0; i < mSeekBarX.getProgress(); i++) {
        float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
        yVals3.add(new Entry(i + 0.66f, val));
    }
    // create a dataset and give it a type
    ScatterDataSet set1 = new ScatterDataSet(yVals1, "DS 1");
    set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
    ScatterDataSet set2 = new ScatterDataSet(yVals2, "DS 2");
    set2.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    set2.setScatterShapeHoleColor(ColorTemplate.COLORFUL_COLORS[3]);
    set2.setScatterShapeHoleRadius(3f);
    set2.setColor(ColorTemplate.COLORFUL_COLORS[1]);
    ScatterDataSet set3 = new ScatterDataSet(yVals3, "DS 3");
    set3.setShapeRenderer(new CustomScatterShapeRenderer());
    set3.setColor(ColorTemplate.COLORFUL_COLORS[2]);
    set1.setScatterShapeSize(8f);
    set2.setScatterShapeSize(8f);
    set3.setScatterShapeSize(8f);
    ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
    // add the datasets
    dataSets.add(set1);
    dataSets.add(set2);
    dataSets.add(set3);
    // create a data object with the datasets
    ScatterData data = new ScatterData(dataSets);
    data.setValueTypeface(mTfLight);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : Entry(com.github.mikephil.charting.data.Entry) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) CustomScatterShapeRenderer(com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData)

Aggregations

ScatterData (com.github.mikephil.charting.data.ScatterData)6 Entry (com.github.mikephil.charting.data.Entry)5 ArrayList (java.util.ArrayList)5 ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)4 IScatterDataSet (com.github.mikephil.charting.interfaces.datasets.IScatterDataSet)4 BarEntry (com.github.mikephil.charting.data.BarEntry)2 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)1 CandleEntry (com.github.mikephil.charting.data.CandleEntry)1 LineData (com.github.mikephil.charting.data.LineData)1 LineDataSet (com.github.mikephil.charting.data.LineDataSet)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 RealmScatterDataSet (com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 MPPointD (com.github.mikephil.charting.utils.MPPointD)1 CustomScatterShapeRenderer (com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer)1 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)1 Test (org.junit.Test)1