com.github.mikephil.charting.data.ScatterDataSet Java Examples
The following examples show how to use
com.github.mikephil.charting.data.ScatterDataSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleFragment.java From Stayfit with Apache License 2.0 | 6 votes |
protected ScatterData generateScatterData(int dataSets, float range, int count) { ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>(); ScatterShape[] shapes = ScatterChart.getAllPossibleShapes(); for(int i = 0; i < dataSets; i++) { ArrayList<Entry> entries = new ArrayList<Entry>(); for(int j = 0; j < count; j++) { entries.add(new Entry((float) (Math.random() * range) + range / 4, j)); } 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(ChartData.generateXVals(0, count), sets); d.setValueTypeface(tf); return d; }
Example #2
Source File: SimpleFragment.java From StockChart-MPAndroidChart with MIT License | 6 votes |
protected ScatterData generateScatterData(int dataSets, float range, int count) { ArrayList<IScatterDataSet> sets = new ArrayList<>(); ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes(); for(int i = 0; i < dataSets; i++) { ArrayList<Entry> entries = new ArrayList<>(); 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; }
Example #3
Source File: CombinedChartActivity.java From StockChart-MPAndroidChart with MIT License | 6 votes |
private ScatterData generateScatterData() { ScatterData d = new ScatterData(); ArrayList<Entry> entries = new ArrayList<>(); for (float index = 0; index < count; 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; }
Example #4
Source File: CombinedChartActivity.java From Stayfit with Apache License 2.0 | 6 votes |
protected ScatterData generateScatterData() { ScatterData d = new ScatterData(); ArrayList<Entry> entries = new ArrayList<Entry>(); for (int index = 0; index < itemcount; index++) entries.add(new Entry(getRandom(20, 15), index)); ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet"); set.setColor(Color.GREEN); set.setScatterShapeSize(7.5f); set.setDrawValues(false); set.setValueTextSize(10f); d.addDataSet(set); return d; }
Example #5
Source File: AccelerometerFragment.java From walt with Apache License 2.0 | 6 votes |
private void drawLatencyChart(List<Entry> phoneEntriesShifted, List<Entry> waltEntries) { final ScatterDataSet dataSetWalt = new ScatterDataSet(waltEntries, "WALT Events"); dataSetWalt.setColor(Color.BLUE); dataSetWalt.setScatterShape(ScatterChart.ScatterShape.CIRCLE); dataSetWalt.setScatterShapeSize(8f); final ScatterDataSet dataSetPhoneShifted = new ScatterDataSet(phoneEntriesShifted, "Phone Events Shifted"); dataSetPhoneShifted.setColor(Color.RED); dataSetPhoneShifted.setScatterShapeSize(10f); dataSetPhoneShifted.setScatterShape(ScatterChart.ScatterShape.X); final ScatterData scatterData = new ScatterData(dataSetWalt, dataSetPhoneShifted); final Description desc = new Description(); desc.setText(""); desc.setTextSize(12f); latencyChart.setDescription(desc); latencyChart.setData(scatterData); latencyChart.invalidate(); latencyChartLayout.setVisibility(View.VISIBLE); }
Example #6
Source File: ScatterChartManager.java From react-native-mp-android-chart with MIT License | 6 votes |
@Override void dataSetConfig(IDataSet<Entry> dataSet, ReadableMap config) { ScatterDataSet scatterDataSet = (ScatterDataSet) dataSet; ChartDataSetConfigUtils.commonConfig(scatterDataSet, config); ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(scatterDataSet, config); ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(scatterDataSet, config); // ScatterDataSet only config if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeSize")) { scatterDataSet.setScatterShapeSize((float) config.getDouble("scatterShapeSize")); } if (BridgeUtils.validate(config, ReadableType.String, "scatterShape")) { scatterDataSet.setScatterShape(ScatterShape.valueOf(config.getString("scatterShape").toUpperCase())); } if (BridgeUtils.validate(config, ReadableType.String, "scatterShapeHoleColor")) { scatterDataSet.setScatterShapeHoleColor(Color.parseColor(config.getString("scatterShapeHoleColor"))); } if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeHoleRadius")) { scatterDataSet.setScatterShapeHoleRadius((float) config.getDouble("scatterShapeHoleRadius")); } }
Example #7
Source File: DataSetTest.java From Ticket-Analysis with MIT License | 5 votes |
@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); }
Example #8
Source File: ScatterChartRenderer.java From iMoney with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { ScatterData scatterData = mChart.getScatterData(); for (ScatterDataSet set : scatterData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
Example #9
Source File: ScatterChartRenderer.java From iMoney with Apache License 2.0 | 5 votes |
@Override public void initBuffers() { ScatterData scatterData = mChart.getScatterData(); mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()]; for (int i = 0; i < mScatterBuffers.length; i++) { ScatterDataSet set = scatterData.getDataSetByIndex(i); mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2); } }
Example #10
Source File: DataSetTest.java From android-kline with Apache License 2.0 | 5 votes |
@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); }
Example #11
Source File: DragLatencyFragment.java From walt with Apache License 2.0 | 5 votes |
private void drawLatencyGraph(double[] ft, double[] fy, double[] lt, double averageBestShift) { final ArrayList<Entry> touchEntries = new ArrayList<>(); final ArrayList<Entry> laserEntries = new ArrayList<>(); final double[] laserT = new double[lt.length]; for (int i = 0; i < ft.length; i++) { touchEntries.add(new Entry((float) ft[i], (float) fy[i])); } for (int i = 0; i < lt.length; i++) { laserT[i] = lt[i] + averageBestShift; } final double[] laserY = Utils.interp(laserT, ft, fy); for (int i = 0; i < laserY.length; i++) { laserEntries.add(new Entry((float) laserT[i], (float) laserY[i])); } final ScatterDataSet dataSetTouch = new ScatterDataSet(touchEntries, "Touch Events"); dataSetTouch.setScatterShape(ScatterChart.ScatterShape.CIRCLE); dataSetTouch.setScatterShapeSize(8f); final ScatterDataSet dataSetLaser = new ScatterDataSet(laserEntries, String.format(Locale.US, "Laser Events Latency=%.1f ms", averageBestShift)); dataSetLaser.setColor(Color.RED); dataSetLaser.setScatterShapeSize(10f); dataSetLaser.setScatterShape(ScatterChart.ScatterShape.X); final ScatterData scatterData = new ScatterData(dataSetTouch, dataSetLaser); final Description desc = new Description(); desc.setText("Y-Position [pixels] vs. Time [ms]"); desc.setTextSize(12f); latencyChart.setDescription(desc); latencyChart.setData(scatterData); latencyChartLayout.setVisibility(View.VISIBLE); }
Example #12
Source File: DataSetTest.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@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); }
Example #13
Source File: ScatterChart.java From Notification-Analyser with MIT License | 5 votes |
@Override protected void drawHighlights() { for (int i = 0; i < mIndicesToHightlight.length; i++) { ScatterDataSet set = mCurrentData.getDataSetByIndex(mIndicesToHightlight[i] .getDataSetIndex()); if (set == null) continue; mHighlightPaint.setColor(set.getHighLightColor()); int xIndex = mIndicesToHightlight[i].getXIndex(); // get the // x-position if (xIndex > mDeltaX * mPhaseX) continue; float y = set.getYValForXIndex(xIndex) * mPhaseY; // get the // y-position float[] pts = new float[] { xIndex, mYChartMax, xIndex, mYChartMin, 0, y, mDeltaX, y }; transformPointArray(pts); // draw the highlight lines mDrawCanvas.drawLines(pts, mHighlightPaint); } }
Example #14
Source File: DataSetTest.java From android-kline with Apache License 2.0 | 4 votes |
@Test public void testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) List<Entry> values = new ArrayList<Entry>(); values.add(new Entry(0, 10)); values.add(new Entry(1, 20)); values.add(new Entry(2, 30)); values.add(new Entry(3, 40)); values.add(new Entry(3, 50)); // duplicate values.add(new Entry(4, 60)); values.add(new Entry(4, 70)); // duplicate values.add(new Entry(5, 80)); values.add(new Entry(6, 90)); values.add(new Entry(7, 100)); values.add(new Entry(8, 110)); values.add(new Entry(8, 120)); // duplicate ScatterDataSet set = new ScatterDataSet(values, ""); Entry closest = set.getEntryForXValue(0, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(0, closest.getX(), 0.01f); assertEquals(10, closest.getY(), 0.01f); closest = set.getEntryForXValue(5, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(7, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(7, closest.getX(), 0.01f); assertEquals(100, closest.getY(), 0.01f); closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(4, closest.getX(), 0.01f); assertEquals(60, closest.getY(), 0.01f); List<Entry> entries = set.getEntriesForXValue(4f); assertEquals(2, entries.size()); assertEquals(60, entries.get(0).getY(), 0.01f); assertEquals(70, entries.get(1).getY(), 0.01f); entries = set.getEntriesForXValue(3.5f); assertEquals(0, entries.size()); entries = set.getEntriesForXValue(2f); assertEquals(1, entries.size()); assertEquals(30, entries.get(0).getY(), 0.01f); }
Example #15
Source File: ScatterChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override IDataSet createDataSet(ArrayList<Entry> entries, String label) { return new ScatterDataSet(entries, label); }
Example #16
Source File: ScatterChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.actionToggleValues: { List<IScatterDataSet> sets = mChart.getData() .getDataSets(); for (IScatterDataSet iSet : sets) { ScatterDataSet set = (ScatterDataSet) iSet; set.setDrawValues(!set.isDrawValuesEnabled()); } mChart.invalidate(); break; } case R.id.actionToggleHighlight: { if(mChart.getData() != null) { mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); mChart.invalidate(); } break; } case R.id.actionTogglePinch: { if (mChart.isPinchZoomEnabled()) mChart.setPinchZoom(false); else mChart.setPinchZoom(true); mChart.invalidate(); break; } case R.id.actionToggleAutoScaleMinMax: { mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled()); mChart.notifyDataSetChanged(); break; } case R.id.actionSave: { // mChart.saveToGallery("title"+System.currentTimeMillis()); mChart.saveToPath("title" + System.currentTimeMillis(), ""); break; } case R.id.animateX: { mChart.animateX(3000); break; } case R.id.animateY: { mChart.animateY(3000); break; } case R.id.animateXY: { mChart.animateXY(3000, 3000); break; } } return true; }
Example #17
Source File: ScatterChart.java From Notification-Analyser with MIT License | 4 votes |
@Override protected void drawData() { ArrayList<ScatterDataSet> dataSets = mCurrentData.getDataSets(); for (int i = 0; i < mCurrentData.getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); ArrayList<Entry> entries = dataSet.getYVals(); float shapeHalf = dataSet.getScatterShapeSize() / 2f; float[] valuePoints = generateTransformedValuesLineScatter(entries); ScatterShape shape = dataSet.getScatterShape(); for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) { if (isOffContentRight(valuePoints[j])) break; // make sure the lines don't do shitty things outside bounds if (j != 0 && isOffContentLeft(valuePoints[j - 1]) && isOffContentTop(valuePoints[j + 1]) && isOffContentBottom(valuePoints[j + 1])) continue; // Set the color for the currently drawn value. If the index is // out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j)); if (shape == ScatterShape.SQUARE) { mDrawCanvas.drawRect(valuePoints[j] - shapeHalf, valuePoints[j + 1] - shapeHalf, valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf, mRenderPaint); } else if (shape == ScatterShape.CIRCLE) { mDrawCanvas.drawCircle(valuePoints[j], valuePoints[j + 1], shapeHalf, mRenderPaint); } else if (shape == ScatterShape.CROSS) { mDrawCanvas.drawLine(valuePoints[j] - shapeHalf, valuePoints[j + 1], valuePoints[j] + shapeHalf, valuePoints[j + 1], mRenderPaint); mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1] - shapeHalf, valuePoints[j], valuePoints[j + 1] + shapeHalf, mRenderPaint); } else if (shape == ScatterShape.TRIANGLE) { // create a triangle path Path tri = new Path(); tri.moveTo(valuePoints[j], valuePoints[j + 1] - shapeHalf); tri.lineTo(valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf); tri.lineTo(valuePoints[j] - shapeHalf, valuePoints[j + 1] + shapeHalf); tri.close(); mDrawCanvas.drawPath(tri, mRenderPaint); } else if (shape == ScatterShape.CUSTOM) { Path customShape = dataSet.getCustomScatterShape(); if (customShape == null) return; // transform the provided custom path transformPath(customShape); mDrawCanvas.drawPath(customShape, mRenderPaint); } } } }
Example #18
Source File: ScatterChart.java From Notification-Analyser with MIT License | 4 votes |
@Override protected void drawValues() { // if values are drawn if (mDrawYValues && mCurrentData.getYValCount() < mMaxVisibleCount * mScaleX) { ArrayList<ScatterDataSet> dataSets = mCurrentData .getDataSets(); for (int i = 0; i < mCurrentData.getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); ArrayList<Entry> entries = dataSet.getYVals(); float[] positions = generateTransformedValuesLineScatter(entries); float shapeSize = dataSet.getScatterShapeSize(); for (int j = 0; j < positions.length * mPhaseX; j += 2) { if (isOffContentRight(positions[j])) break; if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1])) continue; float val = entries.get(j / 2).getVal(); if (mDrawUnitInChart) { mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val) + mUnit, positions[j], positions[j + 1] - shapeSize, mValuePaint); } else { mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - shapeSize, mValuePaint); } } } } }
Example #19
Source File: ScatterChartRenderer.java From iMoney with Apache License 2.0 | 4 votes |
@Override public void drawValues(Canvas c) { // if values are drawn if (mChart.getScatterData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) { List<ScatterDataSet> dataSets = mChart.getScatterData().getDataSets(); for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); List<Entry> entries = dataSet.getYVals(); float[] positions = mChart.getTransformer(dataSet.getAxisDependency()) .generateTransformedValuesScatter(entries, mAnimator.getPhaseY()); float shapeSize = dataSet.getScatterShapeSize(); for (int j = 0; j < positions.length * mAnimator.getPhaseX(); j += 2) { if (!mViewPortHandler.isInBoundsRight(positions[j])) break; // make sure the lines don't do shitty things outside bounds if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1]))) continue; Entry entry = entries.get(j / 2); drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, positions[j], positions[j + 1] - shapeSize); } } } }
Example #20
Source File: DataSetTest.java From Ticket-Analysis with MIT License | 4 votes |
@Test public void testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) List<Entry> values = new ArrayList<Entry>(); values.add(new Entry(0, 10)); values.add(new Entry(1, 20)); values.add(new Entry(2, 30)); values.add(new Entry(3, 40)); values.add(new Entry(3, 50)); // duplicate values.add(new Entry(4, 60)); values.add(new Entry(4, 70)); // duplicate values.add(new Entry(5, 80)); values.add(new Entry(6, 90)); values.add(new Entry(7, 100)); values.add(new Entry(8, 110)); values.add(new Entry(8, 120)); // duplicate ScatterDataSet set = new ScatterDataSet(values, ""); Entry closest = set.getEntryForXValue(0, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(0, closest.getX(), 0.01f); assertEquals(10, closest.getY(), 0.01f); closest = set.getEntryForXValue(5, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(7, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(7, closest.getX(), 0.01f); assertEquals(100, closest.getY(), 0.01f); closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(4, closest.getX(), 0.01f); assertEquals(60, closest.getY(), 0.01f); List<Entry> entries = set.getEntriesForXValue(4f); assertEquals(2, entries.size()); assertEquals(60, entries.get(0).getY(), 0.01f); assertEquals(70, entries.get(1).getY(), 0.01f); entries = set.getEntriesForXValue(3.5f); assertEquals(0, entries.size()); entries = set.getEntriesForXValue(2f); assertEquals(1, entries.size()); assertEquals(30, entries.get(0).getY(), 0.01f); }
Example #21
Source File: ScatterChartActivity.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.viewGithub: { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java")); startActivity(i); break; } case R.id.actionToggleValues: { List<IScatterDataSet> sets = chart.getData() .getDataSets(); for (IScatterDataSet iSet : sets) { ScatterDataSet set = (ScatterDataSet) iSet; set.setDrawValues(!set.isDrawValuesEnabled()); } chart.invalidate(); break; } case R.id.actionToggleHighlight: { if(chart.getData() != null) { chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); } break; } case R.id.actionTogglePinch: { if (chart.isPinchZoomEnabled()) chart.setPinchZoom(false); else chart.setPinchZoom(true); chart.invalidate(); break; } case R.id.actionToggleAutoScaleMinMax: { chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); chart.notifyDataSetChanged(); break; } case R.id.animateX: { chart.animateX(3000); break; } case R.id.animateY: { chart.animateY(3000); break; } case R.id.animateXY: { chart.animateXY(3000, 3000); break; } case R.id.actionSave: { if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { saveToGallery(); } else { requestStoragePermission(chart); } break; } } return true; }
Example #22
Source File: DataSetTest.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Test public void testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) List<Entry> values = new ArrayList<Entry>(); values.add(new Entry(0, 10)); values.add(new Entry(1, 20)); values.add(new Entry(2, 30)); values.add(new Entry(3, 40)); values.add(new Entry(3, 50)); // duplicate values.add(new Entry(4, 60)); values.add(new Entry(4, 70)); // duplicate values.add(new Entry(5, 80)); values.add(new Entry(6, 90)); values.add(new Entry(7, 100)); values.add(new Entry(8, 110)); values.add(new Entry(8, 120)); // duplicate ScatterDataSet set = new ScatterDataSet(values, ""); Entry closest = set.getEntryForXValue(0, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(0, closest.getX(), 0.01f); assertEquals(10, closest.getY(), 0.01f); closest = set.getEntryForXValue(5, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(7, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(7, closest.getX(), 0.01f); assertEquals(100, closest.getY(), 0.01f); closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(4, closest.getX(), 0.01f); assertEquals(60, closest.getY(), 0.01f); List<Entry> entries = set.getEntriesForXValue(4f); assertEquals(2, entries.size()); assertEquals(60, entries.get(0).getY(), 0.01f); assertEquals(70, entries.get(1).getY(), 0.01f); entries = set.getEntriesForXValue(3.5f); assertEquals(0, entries.size()); entries = set.getEntriesForXValue(2f); assertEquals(1, entries.size()); assertEquals(30, entries.get(0).getY(), 0.01f); }
Example #23
Source File: ScatterChartRenderer.java From iMoney with Apache License 2.0 | 3 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { for (int i = 0; i < indices.length; i++) { ScatterDataSet set = mChart.getScatterData().getDataSetByIndex(indices[i] .getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; int xIndex = indices[i].getXIndex(); // get the // x-position if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX()) continue; final float yVal = set.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; float y = yVal * mAnimator.getPhaseY(); float[] pts = new float[] { xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } }
Example #24
Source File: DataSetTest.java From StockChart-MPAndroidChart with MIT License | 3 votes |
@Test public void testCalcMinMax() { 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(10f, set.getXMin(), 0.01f); assertEquals(21f, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(3, set.getEntryCount()); set.addEntry(new Entry(25, 1)); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(25f, set.getXMax(), 0.01f); assertEquals(1f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(4, set.getEntryCount()); set.removeEntry(3); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(21, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); }
Example #25
Source File: DataSetTest.java From android-kline with Apache License 2.0 | 3 votes |
@Test public void testCalcMinMax() { 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(10f, set.getXMin(), 0.01f); assertEquals(21f, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(3, set.getEntryCount()); set.addEntry(new Entry(25, 1)); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(25f, set.getXMax(), 0.01f); assertEquals(1f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(4, set.getEntryCount()); set.removeEntry(3); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(21, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); }
Example #26
Source File: DataSetTest.java From Ticket-Analysis with MIT License | 3 votes |
@Test public void testCalcMinMax() { 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(10f, set.getXMin(), 0.01f); assertEquals(21f, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(3, set.getEntryCount()); set.addEntry(new Entry(25, 1)); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(25f, set.getXMax(), 0.01f); assertEquals(1f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(4, set.getEntryCount()); set.removeEntry(3); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(21, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); }
Example #27
Source File: DataSetTest.java From android-kline with Apache License 2.0 | 2 votes |
@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()); }
Example #28
Source File: DataSetTest.java From Ticket-Analysis with MIT License | 2 votes |
@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()); }
Example #29
Source File: DataSetTest.java From StockChart-MPAndroidChart with MIT License | 2 votes |
@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()); }