use of com.github.mikephil.charting.data.ScatterDataSet 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;
}
use of com.github.mikephil.charting.data.ScatterDataSet 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));
}
use of com.github.mikephil.charting.data.ScatterDataSet in project MPAndroidChart by PhilJay.
the class DataSetTest method testAddRemoveEntry.
@Test
public void testAddRemoveEntry() {
List<Entry> entries = new ArrayList<Entry>();
entries.add(new Entry(10, 10));
entries.add(new Entry(15, 2));
entries.add(new Entry(21, 5));
ScatterDataSet set = new ScatterDataSet(entries, "");
assertEquals(3, set.getEntryCount());
set.addEntryOrdered(new Entry(5, 1));
assertEquals(4, set.getEntryCount());
assertEquals(5, set.getXMin(), 0.01f);
assertEquals(21, set.getXMax(), 0.01f);
assertEquals(1f, set.getYMin(), 0.01f);
assertEquals(10f, set.getYMax(), 0.01f);
assertEquals(5, set.getEntryForIndex(0).getX(), 0.01f);
assertEquals(1, set.getEntryForIndex(0).getY(), 0.01f);
set.addEntryOrdered(new Entry(20, 50));
assertEquals(5, set.getEntryCount());
assertEquals(20, set.getEntryForIndex(3).getX(), 0.01f);
assertEquals(50, set.getEntryForIndex(3).getY(), 0.01f);
assertTrue(set.removeEntry(3));
assertEquals(4, set.getEntryCount());
assertEquals(21, set.getEntryForIndex(3).getX(), 0.01f);
assertEquals(5, set.getEntryForIndex(3).getY(), 0.01f);
assertEquals(5, set.getEntryForIndex(0).getX(), 0.01f);
assertEquals(1, set.getEntryForIndex(0).getY(), 0.01f);
assertTrue(set.removeFirst());
assertEquals(3, set.getEntryCount());
assertEquals(10, set.getEntryForIndex(0).getX(), 0.01f);
assertEquals(10, set.getEntryForIndex(0).getY(), 0.01f);
set.addEntryOrdered(new Entry(15, 3));
assertEquals(4, set.getEntryCount());
assertEquals(15, set.getEntryForIndex(1).getX(), 0.01f);
assertEquals(3, set.getEntryForIndex(1).getY(), 0.01f);
assertEquals(21, set.getEntryForIndex(3).getX(), 0.01f);
assertEquals(5, set.getEntryForIndex(3).getY(), 0.01f);
assertTrue(set.removeLast());
assertEquals(3, set.getEntryCount());
assertEquals(15, set.getEntryForIndex(2).getX(), 0.01f);
assertEquals(2, set.getEntryForIndex(2).getY(), 0.01f);
assertTrue(set.removeLast());
assertEquals(2, set.getEntryCount());
assertTrue(set.removeLast());
assertEquals(1, set.getEntryCount());
assertEquals(10, set.getEntryForIndex(0).getX(), 0.01f);
assertEquals(10, set.getEntryForIndex(0).getY(), 0.01f);
assertTrue(set.removeLast());
assertEquals(0, set.getEntryCount());
assertFalse(set.removeLast());
assertFalse(set.removeFirst());
}
use of com.github.mikephil.charting.data.ScatterDataSet in project MPAndroidChart by PhilJay.
the class DataSetTest method testGetEntryForXValue.
@Test
public void testGetEntryForXValue() {
List<Entry> entries = new ArrayList<Entry>();
entries.add(new Entry(10, 10));
entries.add(new Entry(15, 5));
entries.add(new Entry(21, 5));
ScatterDataSet set = new ScatterDataSet(entries, "");
Entry closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(15, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.DOWN);
assertEquals(15, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXValue(15, Float.NaN, DataSet.Rounding.DOWN);
assertEquals(15, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXValue(14, Float.NaN, DataSet.Rounding.DOWN);
assertEquals(10, closest.getX(), 0.01f);
assertEquals(10, closest.getY(), 0.01f);
closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.UP);
assertEquals(21, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXValue(21, Float.NaN, DataSet.Rounding.UP);
assertEquals(21, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXValue(21, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(21, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
}
use of com.github.mikephil.charting.data.ScatterDataSet in project carat by amplab.
the class ScatterChart method drawHighlights.
@Override
protected void drawHighlights() {
for (int i = 0; i < mIndicesToHightlight.length; i++) {
ScatterDataSet set = mData.getDataSetByIndex(mIndicesToHightlight[i].getDataSetIndex());
if (set == null)
continue;
mHighlightPaint.setColor(set.getHighLightColor());
// get the
int xIndex = mIndicesToHightlight[i].getXIndex();
if (xIndex > mDeltaX * mPhaseX)
continue;
// get the
float y = set.getYValForXIndex(xIndex) * mPhaseY;
// y-position
float[] pts = new float[] { xIndex, mYChartMax, xIndex, mYChartMin, 0, y, mDeltaX, y };
mTrans.pointValuesToPixel(pts);
// draw the highlight lines
mDrawCanvas.drawLines(pts, mHighlightPaint);
}
}
Aggregations