@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pressure_monitor); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); pressuremeter = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); textViewPressure = (TextView) findViewById(R.id.textViewPressure); radioGroup = (RadioGroup) findViewById(R.id.radioGroup1); radioGroup.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.preasure) sensorId = 0; else if (checkedId == R.id.altitude) sensorId = 1; else sensorId = 2; plotLongHistory(); } }); setTitle("Pressure"); // setup the APR History plot: preHistoryPlot = (XYPlot) findViewById(R.id.pressurePlot); preHistoryPlot.setRangeBoundaries(900, 1300, BoundaryMode.AUTO); preHistoryPlot.setDomainBoundaries(0, 100, BoundaryMode.AUTO); // FIXED); preHistoryPlot.addSeries( pressureHistorySeries, new LineAndPointFormatter( Color.BLACK, Color.RED, null, new PointLabelFormatter(Color.TRANSPARENT))); preHistoryPlot.setDomainStepValue(5); preHistoryPlot.setTicksPerRangeLabel(3); // preHistoryPlot.setDomainLabel("Sample Index"); preHistoryPlot.getDomainLabelWidget().pack(); preHistoryPlot.setRangeLabel("Temperature (ºC)"); preHistoryPlot.getRangeLabelWidget().pack(); preHistoryPlot.setRangeLabel("Pressure (hPa)"); longHistoryPlot = (XYPlot) findViewById(R.id.longHistoryPlot); longHistoryPlot.setRangeBoundaries(900, 1300, BoundaryMode.AUTO); longHistoryPlot.setDomainBoundaries(0, 100, BoundaryMode.AUTO); // FIXED); longHistoryPlot.addSeries( longHistorySeries, new LineAndPointFormatter( Color.BLACK, Color.BLUE, null, new PointLabelFormatter(Color.TRANSPARENT))); longHistoryPlot.setDomainStepValue(5); longHistoryPlot.setTicksPerRangeLabel(3); longHistoryPlot.getDomainLabelWidget().pack(); longHistoryPlot.setRangeLabel("Temperature (ºC)"); longHistoryPlot.getRangeLabelWidget().pack(); longHistoryPlot.setRangeLabel("Pressure (hPa)"); // TEST if (!SamplingService.isRunning(this)) { SamplingAlarm.SetAlarm(this); } }
// Constructor sets up the series public mPlotUpdater(XYPlot plot) { this.plot = plot; // only display whole numbers in domain labels plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0")); // Line plot if (dispForm == "WAVE") { LineAndPointFormatter maxFormat = new LineAndPointFormatter( Color.rgb(0, 25, 250), // line color Color.rgb(0, 25, 250), // point color null); // fill color (optional) LineAndPointFormatter minFormat = new LineAndPointFormatter( Color.rgb(250, 25, 0), // line color Color.rgb(250, 25, 0), // point color null); // fill color (optional) LineAndPointFormatter audioFormat = new LineAndPointFormatter( Color.rgb(25, 250, 0), // line color Color.rgb(25, 250, 0), // point color null); // fill color (optional) plot.addSeries(audioHistSeries, audioFormat); plot.addSeries(maxSeries, maxFormat); plot.addSeries(minSeries, minFormat); } // Bar plot if (dispForm == "FFT") { plot.addSeries( audioHistSeries, BarRenderer.class, new BarFormatter(Color.argb(100, 0, 200, 0), Color.rgb(0, 80, 0))); } // thin out domain/range tick labels so they don't overlap each other: plot.setGridPadding(5, 0, 5, 0); plot.setTicksPerDomainLabel(5); plot.setTicksPerRangeLabel(3); plot.disableAllMarkup(); // freeze the range boundaries: plot.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL); plot.setDomainStepValue(1); plot.setTicksPerRangeLabel(6); if (dispForm == "WAVE") plot.setDomainLabel("Time"); if (dispForm == "FFT ") plot.setDomainLabel("Frequency"); plot.getDomainLabelWidget().pack(); plot.setRangeLabel("Amplitude"); plot.getRangeLabelWidget().pack(); plot.disableAllMarkup(); }
@SuppressWarnings("deprecation") public void drawGraph( XYPlot plot, List<Number> xseries, List<Number> yseries, String datatitle, String title) { // Log.d(SystemInfo.TIG, TAG + "::drawGraph()"); // set up data series plot.removeSeries(series); series = new SimpleXYSeries(xseries, yseries, datatitle); // create a formatter // TODO solve deprecation waring LineAndPointFormatter format = new LineAndPointFormatter( Color.rgb(0, 200, 0) // line color , Color.rgb(0, 100, 0) // point color , Color.rgb(150, 190, 150)); // fill color (optional) // add series1 and series2 to the XYPlot plot.addSeries(series, format); // Reduce the number of range labels plot.setTicksPerRangeLabel(3); plot.getBackgroundPaint().setAlpha(0); plot.getGraphWidget().getBackgroundPaint().setAlpha(0); plot.getGraphWidget().getGridBackgroundPaint().setAlpha(0); // TODO implement an on-the-fly refresh of the plot // this is just a small "stubbed" redraw for demonstration purposes plot.setDomainStepMode(XYStepMode.SUBDIVIDE); plot.setDomainStepValue(1); plot.setGridPadding(0, 5, 0, 5); plot.setDomainLabel("Time [s]"); if (title.equals(SystemInfo.DB_TABLENAME_BATTERY)) { plot.setTitle(SystemInfo.DB_TABLENAME_BATTERY); plot.setRangeLabel("[%]"); plot.setRangeBoundaries(0, 100, BoundaryMode.FIXED); } else if (title.equals(SystemInfo.DB_TABLENAME_WIFI)) { plot.setTitle(SystemInfo.DB_TABLENAME_WIFI); plot.setRangeLabel("[~mW]"); plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); } else if (title.equals(SystemInfo.DB_TABLENAME_THREEG)) { plot.setTitle(SystemInfo.DB_TABLENAME_THREEG); plot.setRangeLabel("[~mW]"); plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); } else if (title.equals(SystemInfo.DB_TABLENAME_BLUETOOTH)) { plot.setTitle(SystemInfo.DB_TABLENAME_BLUETOOTH); plot.setRangeLabel("[~mW]"); plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); // XXX scale } plot.redraw(); }
public GraphUpdater(Activity activity) { this.activity = activity; wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); plot = (XYPlot) activity.findViewById(R.id.graph); hash = new HashMap<String, WifiStrengthXYSeries>(); plot.setTitle(""); plot.setTicksPerRangeLabel(2); plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1); plot.setDomainBoundaries(-1, 15, BoundaryMode.FIXED); plot.setDomainLabel("Channel"); DecimalFormat df = new DecimalFormat("#0"); df.setParseIntegerOnly(true); plot.setDomainValueFormat(df); plot.setRangeBoundaries(-100, -20, BoundaryMode.FIXED); plot.setRangeLabel("Strength"); plot.getLegendWidget().setVisible(false); }
/** DESCRIPTION: Sets the boundaries for the X and Y-axis based on the data values. */ private void setPlotAxisBoundaries() { // set y-axis boundaries long boundy = 25; while (maxy >= boundy) boundy *= 2; plot.setRangeBoundaries(0, (float) boundy, BoundaryMode.FIXED); // set y-axis steps double stepy = ((double) boundy) / 10; plot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepy); plot.setTicksPerRangeLabel(2); // set x-axis boundaries lowerboundx = minx - 1; upperboundx = maxx + 1; plot.setDomainBoundaries(lowerboundx, upperboundx, BoundaryMode.FIXED); // set x-axis steps plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1); plot.setTicksPerDomainLabel(1); // determine the number of months being plotted long months = maxx - minx + 1; // adjust bar thickness based on number of months being plotted BarRenderer<?> barRenderer = (BarRenderer<?>) plot.getRenderer(BarRenderer.class); if (barRenderer != null) { Display display = activity.getWindowManager().getDefaultDisplay(); float displayWidth = Utilities.convertPixelsToDp(display.getWidth()); float plotWidth = displayWidth * 0.75f; float barWidth = plotWidth / months; barRenderer.setBarWidth(barWidth); } // adjust label size based on number of months being plotted xlabels.setAbbreviate(months > 6); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.poincare); // Rellenar vector RR1 for (int i = 1; i < Representar.RR.size(); i++) { RR1.add(Representar.RR.get(i)); } // Rellenar vector RRaux for (int i = 0; i < Representar.RR.size() - 1; i++) { RRaux.add(Representar.RR.get(i)); Log.i("RRaux", String.valueOf(Representar.RR.get(i))); } // Declarar el Plot mySimpleXYPlot = (XYPlot) findViewById(R.id.plotPoincare); // Configurar el Plot XYSeries series1 = new SimpleXYSeries( RRaux, // Vector a representar en el eje X RR1, // Vector a representar en el eje Y "Poincaré"); // Etiqueta LineAndPointFormatter series1Format = new LineAndPointFormatter( Color.TRANSPARENT, // Color de la línea Color.rgb( Representar.color0, Representar.color1, Representar.color2), // Color de los puntos null); // Color de relleno // Propiedades para configurar el Plot mySimpleXYPlot.addSeries(series1, series1Format); mySimpleXYPlot.setTicksPerRangeLabel(4); mySimpleXYPlot.disableAllMarkup(); mySimpleXYPlot.getBackgroundPaint().setAlpha(0); mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setAlpha(0); mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setAlpha(0); // Redibujar el Plot mySimpleXYPlot.redraw(); // Configuración boundaries mySimpleXYPlot.calculateMinMaxVals(); // Cálculo del valor mínimo y máximo minXY = new PointF( mySimpleXYPlot.getCalculatedMinX().floatValue(), mySimpleXYPlot.getCalculatedMinY().floatValue()); maxXY = new PointF( mySimpleXYPlot.getCalculatedMaxX().floatValue(), mySimpleXYPlot.getCalculatedMaxY().floatValue()); mySimpleXYPlot.setScrollbarFadingEnabled(true); mySimpleXYPlot.setScrollContainer(true); mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getLegendWidget()); // Etiquetas vertical y horizontal mySimpleXYPlot.setRangeLabel("RR N+1"); mySimpleXYPlot.setDomainLabel("RR N"); mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getTitleWidget()); // Márgenes del Plot mySimpleXYPlot.setPlotMargins(10, 10, 10, 10); mySimpleXYPlot.setPlotPadding(10, 10, 10, 10); // Comienzo y fin del plot mySimpleXYPlot.setDomainBoundaries( mySimpleXYPlot.getCalculatedMinX().floatValue() - 10.0, mySimpleXYPlot.getCalculatedMaxX().floatValue() + 10.0, BoundaryMode.FIXED); mySimpleXYPlot.setRangeBoundaries( mySimpleXYPlot.getCalculatedMinY().floatValue() - 10.0, mySimpleXYPlot.getCalculatedMaxY().floatValue() + 10.0, BoundaryMode.FIXED); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // fun little snippet that prevents users from taking screenshots // on ICS+ devices :-) // getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, // WindowManager.LayoutParams.FLAG_SECURE); setContentView(R.layout.simple_xy_plot_example); // initialize our XYPlot reference: plot = (XYPlot) findViewById(R.id.mySimpleXYPlot); StockProvider sHelper = new StockProvider(this); Uri stockUri = null; String stockName = getIntent().getStringExtra("KEY"); plot.setTitle(stockName); switch (stockName) { case "IBM": stockUri = StockContract.StockEntry.CONTENT_URI_IBM; break; case "MSFT": stockUri = StockContract.StockEntry.CONTENT_URI_MSFT; break; case "GOOG": stockUri = StockContract.StockEntry.CONTENT_URI_GOOG; break; case "AAPL": stockUri = StockContract.StockEntry.CONTENT_URI_AAPL; } Cursor values = sHelper.query(stockUri, null, null, null, null); ArrayList<Double> open = new ArrayList<Double>(); ArrayList<Double> high = new ArrayList<Double>(); ArrayList<Double> low = new ArrayList<Double>(); ArrayList<Double> close = new ArrayList<Double>(); for (values.moveToFirst(); !values.isAfterLast(); values.moveToNext()) { open.add(Double.parseDouble(values.getString(2))); high.add(Double.parseDouble(values.getString(3))); low.add(Double.parseDouble(values.getString(4))); close.add(Double.parseDouble(values.getString(5))); } Double[] openArray = new Double[open.size()]; Double[] highArray = new Double[open.size()]; Double[] lowArray = new Double[open.size()]; Double[] closeArray = new Double[open.size()]; double openI = open.get(0); for (int i = 0; i < open.size(); i++) { openArray[i] = open.get(i) / openI * 100; highArray[i] = high.get(i); lowArray[i] = low.get(i); closeArray[i] = close.get(i); } Double[] open5Array = new Double[open.size() / 5 + 1]; Double[] high5Array = new Double[open.size() / 5 + 1]; Double[] low5Array = new Double[open.size() / 5 + 1]; Double[] close5Array = new Double[open.size() / 5 + 1]; for (int i = 0; i < open.size(); i += 5) { open5Array[i / 5] = open.get(i) / openI * 100; double localHigh = high.get(i); double localLow = low.get(i); for (int j = 0; j < 5; j++) { if (i + j > 387) break; if ((i + j) < 388 && localHigh < high.get(i + j)) { localHigh = high.get(i + j); } if ((i + j) < 388 && localLow < low.get(i + j)) { localLow = low.get(i + j); } if (j == 4) { close5Array[i / 5] = close.get(i + j); } } high5Array[i / 5] = localHigh; low5Array[i / 5] = localLow; } // Create a couple arrays of y-values to plot: Number[] series1Numbers = open5Array; // {1, 8, 5, 2, 7, 4}; Number[] series2Numbers = high5Array; // {4, 6, 3, 8, 2, 10}; Number[] series3Numbers = low5Array; Number[] series4Numbers = close5Array; // Turn the above arrays into XYSeries': XYSeries series1 = new SimpleXYSeries( Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Open"); // Set the display title of the series XYSeries series2 = new SimpleXYSeries( Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "High"); XYSeries series3 = new SimpleXYSeries( Arrays.asList(series3Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Low"); XYSeries series4 = new SimpleXYSeries( Arrays.asList(series4Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Close"); // Create a formatter to use for drawing a series using LineAndPointRenderer // and configure it from xml: myLineAndPointFormatter series1Format = new myLineAndPointFormatter(); series1Format.setPointLabelFormatter(new myPointLabelFormatter()); series1Format.configure(getApplicationContext(), R.xml.line_point_formatter_with_plf1); // add a new series' to the xyplot: plot.addSeries(series1, series1Format); // // // same as above: // myLineAndPointFormatter series2Format = new myLineAndPointFormatter(); // series2Format.setPointLabelFormatter(new myPointLabelFormatter() ); // series2Format.configure(getApplicationContext(), // R.xml.line_point_formatter_with_plf2); // plot.addSeries(series2, series2Format); // // myLineAndPointFormatter series3Format = new myLineAndPointFormatter(); // series3Format.setPointLabelFormatter(new myPointLabelFormatter() ); // series3Format.configure(getApplicationContext(), // R.xml.line_point_formatter_with_plf3); // plot.addSeries(series3, series3Format); // // myLineAndPointFormatter series4Format = new myLineAndPointFormatter(); // series4Format.setPointLabelFormatter(new myPointLabelFormatter() ); // series4Format.configure(getApplicationContext(), // R.xml.line_point_formatter_with_plf4); // plot.addSeries(series4, series4Format); // reduce the number of range labels plot.setTicksPerRangeLabel(1); plot.getGraphWidget().setDomainLabelOrientation(-90); plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("####")); }
void generatePlot() { TextView tv = (TextView) findViewById(R.id.plotViewTitle); tv.setText( "Avistamientos durante " + meses[actualMonth - 1] + " del " + String.valueOf(actualYear)); SQLiteDatabase myDB = null; myDB = this.openOrCreateDatabase(DB_NAME, 1, null); myDB.execSQL( "CREATE TABLE IF NOT EXISTS " + TABLE + " (" + ADDR_DB + " TEXT NOT NULL PRIMARY KEY, " + COORD_X_DB + " INTEGER NOT NULL, " + COORD_Y_DB + " INTEGER NOT NULL, " + INF_DB + " TEXT, " + DAY_DB + " INTEGER, " + MONTH_DB + " INTEGER, " + YEAR_DB + " INTEGER);"); /* * Solo obtendremos los días donde se han visto avistamientos ordenados por menor a mayor. */ String[] FROM = {DAY_DB}; String ORDER_BY = YEAR_DB + " DESC, " + MONTH_DB + " DESC, " + DAY_DB + " DESC"; Cursor c = myDB.query( TABLE, FROM, MONTH_DB + "=" + actualMonth + " AND " + YEAR_DB + "=" + actualYear, null, null, null, ORDER_BY); /* * Preparamos el vector de Number dependiendo del mes que tengamos que mostrar */ Number[] series1Numbers; int daysOfMonth = 0; if (actualMonth == 1 || actualMonth == 3 || actualMonth == 5 || actualMonth == 7 || actualMonth == 8 || actualMonth == 10 || actualMonth == 12) { daysOfMonth = 32; series1Numbers = new Number[daysOfMonth]; for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0; } else if (actualMonth == 2) { daysOfMonth = 29; series1Numbers = new Number[daysOfMonth]; for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0; } else { daysOfMonth = 31; series1Numbers = new Number[daysOfMonth]; for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0; } int max = 0; // sirve para establecer el máximo Y valor del gráfico int aux = 0; int dayAux = 0; startManagingCursor(c); while (c.moveToNext()) { int dayDB = c.getInt(0); if (max < aux) max = aux; if (dayAux == 0) { dayAux = dayDB; ++aux; } else { if (dayAux == dayDB) ++aux; else { series1Numbers[dayAux] = aux; aux = 1; dayAux = dayDB; } } } if (dayAux != 0) series1Numbers[dayAux] = aux; c.close(); if (myDB != null) { myDB.close(); } // Inicializamos el objeto XYPlot búscandolo desde el layout: mySimpleXYPlot = (XYPlot) findViewById(R.id.plot); mySimpleXYPlot.clear(); mySimpleXYPlot.setDomainLabel("Días de " + meses[actualMonth - 1]); mySimpleXYPlot.setRangeLabel("Número de avistamientos"); // Añadimos Línea Número UNO: XYSeries series1 = new SimpleXYSeries( Arrays.asList(series1Numbers), // Array de datos SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Valores verticales "Número de avistamientos"); // Nombre de la serie // Modificamos los colores de la primera serie LineAndPointFormatter series1Format = new LineAndPointFormatter( Color.rgb(200, 0, 0), // Color de la l�nea Color.rgb(0, 0, 0), // Color del punto Color.rgb(190, 150, 150)); // Relleno // Una vez definida la serie (datos y estilo), la añadimos al panel mySimpleXYPlot.addSeries(series1, series1Format); if (max == 0) ++max; // Tuneamos el grafico mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("#")); mySimpleXYPlot.setDomainBoundaries(1, daysOfMonth - 1, BoundaryMode.FIXED); mySimpleXYPlot.setDomainStepValue(daysOfMonth); if (daysOfMonth == 32) { mySimpleXYPlot.setTicksPerDomainLabel(2); } else if (daysOfMonth == 31) { mySimpleXYPlot.setTicksPerDomainLabel(3); } else if (daysOfMonth == 28) { mySimpleXYPlot.setTicksPerDomainLabel(2); } mySimpleXYPlot.setRangeUpperBoundary(max + 2, BoundaryMode.FIXED); mySimpleXYPlot.setRangeStepValue(max + 3); mySimpleXYPlot.setTicksPerRangeLabel(1); mySimpleXYPlot.disableAllMarkup(); /* * Generamos la vista de nueva para mostrar la nueva gráfica */ ScrollView sv = (ScrollView) findViewById(R.id.scrollView); sv.postInvalidate(); }