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; }
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; }
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>(); dataSets.add(set); // add the dataset // 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); }
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; }
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; }
/** * Create dataset to be displayed in chart legend * @return CombinedData representing dummy data for a legend */ private CombinedData buildDummyDataForLegend(){ CombinedData combinedData = new CombinedData(); float xIndex = 1.5f; float close = 13; float open = 26f; float shadowH = 30.33f; float shadowL = -2.05f; float average = 20f; CandleData candleData = generateCandleData(xIndex, shadowH, shadowL, open, close, "EMU HI/LO" ); ScatterData scatterData = generateScatterData(average, "EMU Mean"); LineData s1 = generateOceanHiLo(close, open, "Ocean HI/LO"); combinedData.setData(s1); combinedData.setData(candleData); combinedData.setData(scatterData); return combinedData; }
/** * Build a CombinedData object containing temperature data * @param observation - EMUObservation * @param stat - EMUStat * @return - CombinedData */ private CombinedData buildTempData(EMUObservation observation, EMUStat stat){ CombinedData combinedData = new CombinedData(); if (stat.getTemp_max() == null || stat.getTemp_min() == null || stat.getTemp_mean() == null || observation.getTemperature() == null){ return combinedData; } float xIndex = 1.5f; float close = (float) stat.getTemp_min().doubleValue(); float open = (float) stat.getTemp_max().doubleValue(); float shadowH = (float)mDataManager.getMaxTemperatureFromSummary().doubleValue(); // 30.33f; // Greatest max temp from summary table float shadowL = (float) mDataManager.getMinTemperatureFromSummary().doubleValue(); // -2.05f; // Lowest min temp from summary table float averageTemp = (float)observation.getTemperature().doubleValue(); Log.i("SummaryChartPresenter", "Temperature: Ocean high = " + shadowH + " ocean low = "+ shadowL + " emu min = " + close + " emu max = "+ open + " emu mean for location = "+ averageTemp); combinedData.setData(generateCandleData(xIndex, shadowH, shadowL, open, close, TEMPERATURE )); ScatterData sdata = generateScatterData(averageTemp, TEMPERATURE); combinedData.setData(sdata); return combinedData; }
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); }
@Override public void drawData(Canvas c) { ScatterData scatterData = mChart.getScatterData(); for (IScatterDataSet set : scatterData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
@Override public void initBuffers() { ScatterData scatterData = mChart.getScatterData(); mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()]; for (int i = 0; i < mScatterBuffers.length; i++) { IScatterDataSet set = scatterData.getDataSetByIndex(i); mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2); } }
/** * Prepare ScatterData object * @param averageValue * @param seriesName * @return ScatterData */ private ScatterData generateScatterData(float averageValue, String seriesName){ ScatterData d = new ScatterData(); ArrayList<Entry> entries = new ArrayList<>(); entries.add(new Entry(1.5f, averageValue)); ScatterDataSet set = new ScatterDataSet(entries, seriesName); set.setColor(Color.parseColor("#FF4081")); set.setScatterShape(ScatterChart.ScatterShape.SQUARE); set.setScatterShapeSize(15f); set.setDrawValues(false); set.setValueTextSize(10f); d.addDataSet(set); return d; }
@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); } }
@Override public void drawData(Canvas c) { ScatterData scatterData = mChart.getScatterData(); for (ScatterDataSet set : scatterData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
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); }
@Override public void drawData(Canvas c) { ScatterData scatterData = mChart.getScatterData(); IScatterDataSet set; int setCount = scatterData.getDataSets().size(); for(int i = 0 ; i < setCount ; i++){ set = scatterData.getDataSets().get(i); if (set.isVisible()) drawDataSet(c, set); } }
/** * Generate scatter data scatter data. * * @param dataSets the data sets * @param range the range * @param count the count * @return the scatter data */ 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; }
@Override public ScatterData getScatterData() { return mData; }
@Override public ScatterData getScatterData() { if (mData == null) return null; return mData.getScatterData(); }
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { ScatterData scatterData = mChart.getScatterData(); for (Highlight high : indices) { IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; final Entry e = set.getEntryForXValue(high.getX(), high.getY()); if (!isInBoundsX(e, set)) continue; MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator .getPhaseY()); high.setDraw((float) pix.x, (float) pix.y); // draw the lines drawHighlightLines(c, (float) pix.x, (float) pix.y, set); } }
public ScatterData getScatterData() { return mData; }
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { ScatterData scatterData = mChart.getScatterData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? scatterData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { IScatterDataSet set = scatterData.getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; int xIndex = high.getXIndex(); // get the // x-position if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX()) continue; final float yVal = set.getYValForXIndex(xIndex); if (Float.isNaN(yVal)) 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); } } }