示例#1
0
  /**
   * DESCRIPTION: Creates the graph.
   *
   * @see android.app.Activity#onCreate(android.os.Bundle)
   */
  public void onCreate(Bundle savedInstanceState, Activity parent, XYPlot xyplot) {
    this.activity = parent;
    this.plot = xyplot;

    // get current units of measurement
    units = new Units(Settings.KEY_UNITS);

    // create a formatter to use for drawing the plot series
    plotFormatter =
        new BarFormatter(
            activity.getResources().getColor(R.color.plot_fill_color),
            activity.getResources().getColor(R.color.plot_line_color));

    // create a formatter for average label
    float hOffset = 50f;
    float vOffset = -10f;
    avgLabelFormatter =
        new PointLabelFormatter(
            activity.getResources().getColor(R.color.plot_avgline_color), hOffset, vOffset);

    // create a formatter to use for drawing the average line
    avgFormatter =
        new LineAndPointFormatter(
            activity.getResources().getColor(R.color.plot_avgline_color),
            null,
            null,
            avgLabelFormatter);

    // white background for the plot
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    // remove the series legend
    plot.getLayoutManager().remove(plot.getLegendWidget());

    // make room for bigger labels
    // TODO: is there a better way to do this?
    float width = plot.getGraphWidget().getRangeLabelWidth() * 2f;
    plot.getGraphWidget().setRangeLabelWidth(width);
    width = plot.getGraphWidget().getDomainLabelWidth() * 1.5f;
    plot.getGraphWidget().setDomainLabelWidth(width);
    float margin = plot.getGraphWidget().getMarginTop() * 3f;
    plot.getGraphWidget().setMarginTop(margin);
    margin = plot.getGraphWidget().getMarginBottom() * 3f;
    plot.getGraphWidget().setMarginBottom(margin);

    // define plot axis labels
    plot.setRangeLabel(units.getLiquidVolumeLabel());
    plot.setDomainLabel(activity.getString(R.string.months_label));

    // specify format of axis value labels
    plot.setRangeValueFormat(ylabels);
    plot.setDomainValueFormat(xlabels);

    // plot the data
    drawPlot();
  }
  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);
  }
示例#3
0
文件: chart.java 项目: summy00/IHA
  private void ShowPlot() {
    mySimpleXYPlot = (XYPlot) findViewById(R.id.chartPlot);
    mySimpleXYPlot.setTitle("Weight");

    if (plotLine != null) mySimpleXYPlot.removeSeries(plotLine);

    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot
        .getGraphWidget()
        .getGridLinePaint()
        .setPathEffect(new DashPathEffect(new float[] {1, 1}, 1));
    mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
    mySimpleXYPlot.getBorderPaint().setStrokeWidth(1);
    mySimpleXYPlot.getBorderPaint().setAntiAlias(false);
    mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().setPaddingRight(5);

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.rgb(0, 100, 0), // line color
            Color.rgb(0, 100, 0), // point color
            Color.rgb(100, 200, 0)); // fill color

    // setup our line fill paint to be a slightly transparent gradient:
    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    lineFill.setShader(
        new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));

    LineAndPointFormatter formatter =
        new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.BLUE, Color.RED);
    formatter.setFillPaint(lineFill);

    plotLine = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(weights), "Weight over time");
    mySimpleXYPlot.addSeries(plotLine, formatter);
    mySimpleXYPlot.redraw();

    // draw a domain tick for each year:
    int min = DomainMin();
    int max = DomainMax();
    int domainStep = domainStep(min, max);
    mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, domainStep);
    // mySimpleXYPlot.setDomainBoundaries(min, max, BoundaryMode.AUTO);

    // customize our domain/range labels
    mySimpleXYPlot.setDomainLabel("Date");
    mySimpleXYPlot.setRangeLabel("Weight");

    Double minimum = FindMinimum();
    Double maximum = FindMaximum();
    Double stepSize = FindStep(maximum, minimum);
    mySimpleXYPlot.setRangeBoundaries(minimum, maximum, BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepSize);

    mySimpleXYPlot.setDomainValueFormat(
        new Format() {
          private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM");

          @Override
          public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {

            // because our timestamps are in seconds and SimpleDateFormat expects milliseconds
            // we multiply our timestamp by 1000:
            long timestamp = ((Number) obj).longValue() * 1000;
            Date date = new Date(timestamp);
            return dateFormat.format(date, toAppendTo, pos);
          }

          @Override
          public Object parseObject(String source, ParsePosition pos) {
            return null;
          }
        });

    // by default, AndroidPlot displays developer guides to aid in laying out your plot.
    // To get rid of them call disableAllMarkup():
    mySimpleXYPlot.disableAllMarkup();
  }
示例#4
0
  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();
  }