private void p1Graph() { p1Series = new LineGraphSeries(); p1Series.setColor(Color.RED); // p1graph.setManualYAxisBounds(127, -127); p1graph.addSeries(p1Series); // data p1graph.getViewport().setYAxisBoundsManual(true); p1graph.getViewport().setMaxY(4096); p1graph.getViewport().setMinY(-1); p1graph.getViewport().setScalable(false); p1graph.getViewport().setScrollable(false); p1graph.setTitle("Upper Sensor Leg"); p1graph.setTitleColor(R.color.PMDBlue); p1graph.getGridLabelRenderer().setHorizontalLabelsVisible(false); p1graph.getGridLabelRenderer().setVerticalLabelsVisible(false); RelativeLayout layout = (RelativeLayout) findViewById(R.id.p1Layout); layout.addView(p1graph); ////////////////////////////////////// p2Series = new LineGraphSeries(); p2Series.setColor(Color.BLUE); // p1graph.setManualYAxisBounds(127, -127); p2graph.addSeries(p2Series); // data p2graph.getViewport().setYAxisBoundsManual(true); p2graph.getViewport().setMaxY(4096); p2graph.getViewport().setMinY(-1); p2graph.getViewport().setScalable(false); p2graph.getViewport().setScrollable(false); p2graph.setTitle("Lower Sensor Leg"); p2graph.setTitleColor(R.color.PMDBlue); p2graph.getGridLabelRenderer().setHorizontalLabelsVisible(false); p2graph.getGridLabelRenderer().setVerticalLabelsVisible(false); RelativeLayout layout2 = (RelativeLayout) findViewById(R.id.p2Layout); layout2.addView(p2graph); ////////////////////////////////////// vSeries = new LineGraphSeries(); vSeries.setColor(Color.rgb(0, 156, 2)); // p1graph.setManualYAxisBounds(127, -127); vgraph.addSeries(vSeries); // data vgraph.getViewport().setYAxisBoundsManual(true); vgraph.getViewport().setMaxY(4096); vgraph.getViewport().setMinY(-1); vgraph.getViewport().setScalable(false); vgraph.getViewport().setScrollable(false); vgraph.setTitle("Reference Voltage"); vgraph.setTitleColor(R.color.PMDBlue); vgraph.getGridLabelRenderer().setHorizontalLabelsVisible(false); vgraph.getGridLabelRenderer().setVerticalLabelsVisible(false); RelativeLayout layout3 = (RelativeLayout) findViewById(R.id.vRefLayout); layout3.addView(vgraph); }
private void updatePressureValue(BluetoothGattCharacteristic characteristic) { counter++; byte[] value = characteristic.getValue(); int x = twoBytesToShort(value[0], value[1]); x = x >> 6; int y = twoBytesToShort(value[2], value[3]); y = y >> 6; int z = twoBytesToShort(value[4], value[5]); z = z >> 6; int ref = value[6]; ref += 2048; int p1 = twoBytesToShort(value[7], value[8]); int p2 = twoBytesToShort(value[9], value[10]); int spi = (int) value[11]; String s = ("0000000" + Integer.toBinaryString(0xFF & value[12])).replaceAll(".*(.{8})$", "$1"); if (s.charAt(0) == '1') { fpc = true; } char[] chars = s.toCharArray(); chars[0] = '0'; s = String.valueOf(chars); byte b = Byte.parseByte(s, 2); int batt = b; battCharge = "" + batt; runOnUiThread( new Runnable() { public void run() { battLevel.setText(battCharge + "%"); } }); float mP1 = p1; float p1Value = (((float) .000733) * mP1); float mP2 = p2; float p2Value = (((float) .000733) * mP2); float mP3 = ref; float p3Value = (((float) .000733) * mP3); usl.setText((String.format("%.2f", round(p1Value, 2)) + " V")); lsl.setText((String.format("%.2f", round(p2Value, 2)) + " V")); vref.setText((String.format("%.2f", round(p3Value, 2)) + " V")); Integer[] values = {x, y, z, ref, p1, p2, spi, batt}; xBar.setProgress(x + 512); yBar.setProgress(y + 512); zBar.setProgress(z + 512); if (logging) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(values); } else { p1Series.appendData(new DataPoint(counter, p1), true, 100); p2Series.appendData(new DataPoint(counter, p2), true, 100); vSeries.appendData(new DataPoint(counter, ref), true, 100); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cpuinfo); activeCores = (TextView) findViewById(R.id.activeCores); processor = (TextView) findViewById(R.id.processor); featuresCPU = (TextView) findViewById(R.id.features); hardWareCpu = (TextView) findViewById(R.id.cpuHardware); cpuMaxFrequency = (TextView) findViewById(R.id.cpuMaxFrequency); cpuCurrentFreq = (TextView) findViewById(R.id.cpuCurrentFrequency); updateView(); // graph settings graph = (GraphView) findViewById(R.id.graph1); seriesLive = new LineGraphSeries<DataPoint>(); seriesLive.setColor(getResources().getColor(R.color.tabs)); seriesLive.setDrawBackground(true); seriesLive.setBackgroundColor(getResources().getColor(R.color.graph_filling)); seriesLive.setThickness(2); seriesLive.setTitle("CPU Usage"); graph.addSeries(seriesLive); graph.getViewport().setYAxisBoundsManual(true); graph.getViewport().setXAxisBoundsManual(true); graph.getViewport().setMinX(0); graph.getViewport().setMaxX(10); graph.getViewport().setScrollable(true); graph.getViewport().setMinY(0); graph.getViewport().setMaxY(100); graph.getViewport().setBackgroundColor(Color.WHITE); graph.getGridLabelRenderer().setGridColor(Color.WHITE); graph.getGridLabelRenderer().setHorizontalLabelsVisible(false); graph.getGridLabelRenderer().setNumVerticalLabels(5); graph.getGridLabelRenderer().setNumHorizontalLabels(4); graph.getGridLabelRenderer().setVerticalLabelsVisible(false); graph.getGridLabelRenderer().reloadStyles(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.graph); // generate Dates Calendar calendar = Calendar.getInstance(); Date d1 = calendar.getTime(); calendar.add(Calendar.DATE, 1); Date d2 = calendar.getTime(); calendar.add(Calendar.DATE, 1); Date d3 = calendar.getTime(); Date d4 = calendar.getTime(); calendar.add(Calendar.DATE, 1); Date d5 = calendar.getTime(); calendar.add(Calendar.DATE, 1); Date d6 = calendar.getTime(); Date d7 = calendar.getTime(); calendar.add(Calendar.DATE, 1); Date d8 = calendar.getTime(); calendar.add(Calendar.DATE, 1); Date d9 = calendar.getTime(); GraphView graph = (GraphView) findViewById(R.id.graph); // you can directly pass Date objects to DataPoint-Constructor // this will convert the Date to double via Date#getTime() LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>( new DataPoint[] { new DataPoint(d1, 1), new DataPoint(d2, 5), new DataPoint(d3, 3), new DataPoint(d4, 4), new DataPoint(d5, 6), new DataPoint(d6, 5), new DataPoint(d7, 7), new DataPoint(d8, 4), new DataPoint(d9, 6), }); series.setColor(getResources().getColor(android.R.color.holo_green_dark)); LineGraphSeries<DataPoint> series2 = new LineGraphSeries<DataPoint>( new DataPoint[] { new DataPoint(d1, 2), new DataPoint(d2, 3), new DataPoint(d3, 3), new DataPoint(d4, 4), new DataPoint(d5, 5), new DataPoint(d6, 5), new DataPoint(d7, 7), new DataPoint(d8, 4), new DataPoint(d9, 6), }); series.setColor(getResources().getColor(android.R.color.holo_red_dark)); graph.addSeries(series); graph.addSeries(series2); // set date label formatter graph .getGridLabelRenderer() .setLabelFormatter(new DateAsXAxisLabelFormatter(NativeGraphActivity.this)); graph.getGridLabelRenderer().setNumHorizontalLabels(8); // only 4 because of the space // set manual x bounds to have nice steps graph.getViewport().setMinX(d1.getTime()); graph.getViewport().setMaxX(d9.getTime()); graph.getViewport().setXAxisBoundsManual(true); lecho.lib.hellocharts.view.LineChartView chartView = (LineChartView) findViewById(R.id.chart); List<PointValue> values = new ArrayList<PointValue>(); values.add(new PointValue(0, 2)); values.add(new PointValue(1, 4)); values.add(new PointValue(2, 3)); values.add(new PointValue(3, 4)); // In most cased you can call data model methods in builder-pattern-like manner. Line line = new Line(values) .setColor(getResources().getColor(android.R.color.holo_red_dark)) .setCubic(false); List<Line> lines = new ArrayList<Line>(); lines.add(line); LineChartData data = new LineChartData(); data.setLines(lines); Axis axis = new Axis(); axis.setHasTiltedLabels(true); data.setAxisXBottom(new Axis().setAutoGenerated(true)); data.setAxisYLeft(new Axis().setAutoGenerated(true)); data.setBaseValue(20); chartView.setLineChartData(data); }