Пример #1
0
 /**
  * Checks the validity of the dataset and renderer parameters.
  *
  * @param dataset the multiple series dataset (cannot be null)
  * @param renderer the multiple series renderer (cannot be null)
  * @throws IllegalArgumentException if dataset is null or renderer is null or if the dataset and
  *     the renderer don't include the same number of series
  */
 private static void checkParameters(
     XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {
   if (dataset == null
       || renderer == null
       || dataset.getSeriesCount() != renderer.getSeriesRendererCount()) {
     throw new IllegalArgumentException(
         "Dataset and renderer should be not null and should have the same number of series");
   }
 }
Пример #2
0
  /**
   * Executes the chart demo.
   *
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context, Child aChild) {
    Cursor c;
    List<double[]> x = new ArrayList<double[]>();
    List<double[]> values = new ArrayList<double[]>();
    SQLiteDatabase db = new DatabaseOpenHelper(context).getReadableDatabase();
    c =
        db.query(
            "bmichart", new String[] {"day", "P99", "P01", "P50"}, null, null, null, null, null);
    int factor = 5;

    double[] p99 = new double[(c.getCount() / factor) + 1];
    double[] p0 = new double[(c.getCount() / factor) + 1];
    double[] p50 = new double[(c.getCount() / factor) + 1];
    double[] days = new double[(c.getCount() / factor) + 1];
    double[] bmiData = new double[c.getCount() / factor + 1];
    c.moveToFirst();
    int i = 0;
    int temp;
    do {
      if (i % factor == 0) {
        temp = i / factor;
        p99[temp] = c.getDouble(1);
        p0[temp] = c.getDouble(2);
        p50[temp] = c.getDouble(3);
        days[temp] = i;
      }
      i++;
    } while (c.moveToNext());
    c.close();

    // initializing height to -5
    for (i = 0; i < bmiData.length; i++) {
      bmiData[i] = -5;
    }
    c =
        db.query(
            aChild.getDataTableName(), new String[] {"day", "bmi"}, null, null, null, null, null);

    i = 0;
    String[] titles = new String[] {"P99", "P0", "P50", "BMI"};
    int[] colors = new int[] {Color.CYAN, Color.GREEN, Color.RED, Color.BLUE};
    PointStyle[] styles =
        new PointStyle[] {PointStyle.POINT, PointStyle.POINT, PointStyle.POINT, PointStyle.CIRCLE};
    if (c.moveToFirst()) {
      do {
        temp = (int) (c.getDouble(0) / factor);
        bmiData[temp] = c.getDouble(1);
        i++;
      } while (c.moveToNext());
      values.add(bmiData);
    } else {
      titles = new String[] {"P99", "P0", "P50"};
      colors = new int[] {Color.CYAN, Color.GREEN, Color.RED};
      styles = new PointStyle[] {PointStyle.POINT, PointStyle.POINT, PointStyle.POINT};
    }
    for (int v = 0; v < titles.length; v++) {
      x.add(days);
    }
    values.add(p99);
    values.add(p0);
    values.add(p50);

    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);

    int length = renderer.getSeriesRendererCount();
    for (i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }

    setChartSettings(
        renderer, "BMI Day Chart", "Days", "BMI", 0, 1000, 0, 125, Color.LTGRAY, Color.LTGRAY);
    renderer.setXLabels(12);
    renderer.setYLabels(10);
    renderer.setShowGrid(true);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setZoomButtonsVisible(true);
    renderer.setPanLimits(new double[] {-10, 20, -10, 40});
    renderer.setZoomLimits(new double[] {-10, 20, -10, 40});
    Intent intent =
        ChartFactory.getLineChartIntent(
            context, buildDataset(titles, x, values), renderer, aChild.getName());
    c.close();
    db.close();
    return intent;
  }
  /**
   * Executes the chart demo.
   *
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context) {
    String[] titles = new String[] {"Crete Air Temperature", "Skiathos Air Temperature"};
    List<double[]> x = new ArrayList<double[]>();
    for (int i = 0; i < titles.length; i++) {
      x.add(new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
    }
    List<double[]> values = new ArrayList<double[]>();
    values.add(
        new double[] {12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2, 13.9});
    values.add(new double[] {9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10});
    int[] colors = new int[] {Color.GREEN, Color.rgb(200, 150, 0)};
    PointStyle[] styles = new PointStyle[] {PointStyle.CIRCLE, PointStyle.DIAMOND};
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    renderer.setPointSize(5.5f);
    int length = renderer.getSeriesRendererCount();

    for (int i = 0; i < length; i++) {
      XYSeriesRenderer r = (XYSeriesRenderer) renderer.getSeriesRendererAt(i);
      r.setLineWidth(5);
      r.setFillPoints(true);
    }
    setChartSettings(
        renderer,
        "Weather data",
        "Month",
        "Temperature",
        0.5,
        12.5,
        0,
        40,
        Color.LTGRAY,
        Color.LTGRAY);

    renderer.setXLabels(12);
    renderer.setYLabels(10);
    renderer.setShowGrid(true);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setZoomButtonsVisible(true);
    renderer.setPanLimits(new double[] {-10, 20, -10, 40});
    renderer.setZoomLimits(new double[] {-10, 20, -10, 40});

    XYValueSeries sunSeries = new XYValueSeries("Sunshine hours");
    sunSeries.add(1, 35, 4.3);
    sunSeries.add(2, 35, 4.9);
    sunSeries.add(3, 35, 5.9);
    sunSeries.add(4, 35, 8.8);
    sunSeries.add(5, 35, 10.8);
    sunSeries.add(6, 35, 11.9);
    sunSeries.add(7, 35, 13.6);
    sunSeries.add(8, 35, 12.8);
    sunSeries.add(9, 35, 11.4);
    sunSeries.add(10, 35, 9.5);
    sunSeries.add(11, 35, 7.5);
    sunSeries.add(12, 35, 5.5);
    XYSeriesRenderer lightRenderer = new XYSeriesRenderer();
    lightRenderer.setColor(Color.YELLOW);

    XYSeries waterSeries = new XYSeries("Water Temperature");
    waterSeries.add(1, 16);
    waterSeries.add(2, 15);
    waterSeries.add(3, 16);
    waterSeries.add(4, 17);
    waterSeries.add(5, 20);
    waterSeries.add(6, 23);
    waterSeries.add(7, 25);
    waterSeries.add(8, 25.5);
    waterSeries.add(9, 26.5);
    waterSeries.add(10, 24);
    waterSeries.add(11, 22);
    waterSeries.add(12, 18);
    renderer.setBarSpacing(0.5);
    XYSeriesRenderer waterRenderer = new XYSeriesRenderer();
    waterRenderer.setColor(Color.argb(250, 0, 210, 250));

    XYMultipleSeriesDataset dataset = buildDataset(titles, x, values);
    dataset.addSeries(0, sunSeries);
    dataset.addSeries(0, waterSeries);
    renderer.addSeriesRenderer(0, lightRenderer);
    renderer.addSeriesRenderer(0, waterRenderer);
    waterRenderer.setDisplayChartValues(true);
    waterRenderer.setChartValuesTextSize(10);

    String[] types =
        new String[] {BarChart.TYPE, BubbleChart.TYPE, LineChart.TYPE, CubicLineChart.TYPE};
    Intent intent =
        ChartFactory.getCombinedXYChartIntent(
            context, dataset, renderer, types, "Weather parameters");
    return intent;
  }
Пример #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    Cursor settings;
    mDbHelper = new gasDbAdapter(getApplicationContext());
    mDbHelper.open();
    settings = mDbHelper.GetSettings();
    setContentView(R.layout.xy_chart);
    setTitle(R.string.analyze_d);
    mLayout = (LinearLayout) findViewById(R.id.chart);
    mDailyCost = (TextView) findViewById(R.id.avg_cost);

    if (settings.moveToFirst()) {
      dunits = settings.getString(settings.getColumnIndex(mDbHelper.KEY_DUNITS));
      cunits = settings.getString(settings.getColumnIndex(mDbHelper.KEY_CUNITS));
      funits = settings.getString(settings.getColumnIndex(mDbHelper.KEY_FUNITS));
      numVehicles = settings.getInt(settings.getColumnIndex(mDbHelper.KEY_VNUM));

      mVehicle = (Spinner) findViewById(R.id.vname_spinner);
      String[] columns = new String[] {mDbHelper.KEY_VNAME};
      int[] to = new int[] {android.R.id.text1};
      Cursor v = mDbHelper.getVehicles();
      SimpleCursorAdapter mAdapter =
          new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, v, columns, to);
      mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      Spinner spnVnames = (Spinner) findViewById(R.id.vname_spinner);
      spnVnames.setAdapter(mAdapter);
      spnVnames.setOnItemSelectedListener(SpinnerOnItemSelectedListener);

      mVehicle.setSelection(0); // set to first vehicle, spinner is 0-based Db is 1 based

    } else {
      // error - no settings
      Toast.makeText(
              this,
              getApplicationContext().getResources().getString(R.string.nosett_err),
              Toast.LENGTH_SHORT)
          .show();
      finish(); // no settings = no cars, no fuel, nothing to show. Get the hell out.
    }
    mDbHelper.close();

    // get the current date
    Calendar c = Calendar.getInstance();
    today = c.getTimeInMillis();

    String dmsunits = dunits.replace('s', ' ');
    costTitle = cunits + " / " + dmsunits;
    avgCostTitle = "Avg";
    mCurrentCostSeries = new XYSeries(costTitle);

    String fmsunits = funits.replace('s', ' ');
    effTitle = dunits + " / " + fmsunits;
    avgEffTitle = "Avg";
    mCurrentEffSeries = new XYSeries(effTitle, 1);

    mDataset.addSeries(mCurrentCostSeries);
    mDataset.addSeries(mCurrentEffSeries);
    mRenderer = new XYMultipleSeriesRenderer(2);

    setRenderer(mRenderer, colors, styles);
    int length = mRenderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      XYSeriesRenderer r = (XYSeriesRenderer) mRenderer.getSeriesRendererAt(i);
      r.setLineWidth(3f);
    }

    mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer, null);
    mChartView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
            double[] xy = mChartView.toRealPoint(0);
            if (seriesSelection == null) {
              //
            } else {
              String fs;
              Calendar c = Calendar.getInstance();
              c.setTimeInMillis((long) seriesSelection.getXValue());
              if (seriesSelection.getSeriesIndex() == 0) {
                fs = String.format("%.1f " + costTitle + " on %tD", seriesSelection.getValue(), c);
              } else {
                fs = String.format("%.1f " + effTitle + " on %tD", seriesSelection.getValue(), c);
              }
              Toast.makeText(AnalyzeFuel.this, fs, Toast.LENGTH_LONG).show();
            }
          }
        });

    mChartView.addZoomListener(
        new ZoomListener() {
          public void zoomApplied(ZoomEvent e) {
            String type = "out";
            if (e.isZoomIn()) {
              type = "in";
            }
            System.out.println("Zoom " + type + " rate " + e.getZoomRate());
          }

          public void zoomReset() {
            System.out.println("Reset");
          }
        },
        true,
        true);

    mChartView.addPanListener(
        new PanListener() {
          public void panApplied() {
            System.out.println(
                "New X range=["
                    + mRenderer.getXAxisMin()
                    + ", "
                    + mRenderer.getXAxisMax()
                    + "], Y range=["
                    + mRenderer.getYAxisMax()
                    + ", "
                    + mRenderer.getYAxisMax()
                    + "]");
          }
        });
  }
Пример #5
0
  public void drawHRLayout(double[] myHRs, Date[] myDates) {
    String[] titles = new String[] {"FitFormula User"};
    List<Date[]> dates = new ArrayList<Date[]>();
    List<double[]> values = new ArrayList<double[]>();
    for (int i = 0; i < titles.length; i++) {
      dates.add(myDates);
      values.add(myHRs);
    }

    int[] colors = new int[] {Color.YELLOW};
    PointStyle[] styles = new PointStyle[] {PointStyle.CIRCLE};
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    int length = renderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }
    double hrMin = getMinValue(myHRs);
    double hrMax = getMaxValue(myHRs);
    setChartSettings(
        renderer,
        "Resting Heart Rate",
        "Date",
        "BPM",
        dates.get(0)[0].getTime(),
        dates.get(0)[myDates.length - 1].getTime(),
        hrMin - hrMin * 0.20,
        hrMax + hrMax * 0.20,
        Color.LTGRAY,
        Color.LTGRAY);
    renderer.setXLabels(myDates.length - 1);
    renderer.setYLabels(8);
    renderer.setShowGrid(true);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setZoomButtonsVisible(false);
    renderer.setZoomEnabled(false, false);
    renderer.setPanEnabled(true, false);
    renderer.setPanLimits(new double[] {0, myDates.length - 1, 0, hrMax}); // minX, maxX, minY, maxY
    // renderer.setZoomLimits(new double[] { 0, 20, 60, 120 });

    mRelative.removeAllViews();

    titleText.setText(
        Html.fromHtml("<br><b><u><big>My Resting Heart Rate History</big></u></b><br>"));
    titleText.setId(1);
    RelativeLayout.LayoutParams relParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    relParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mRelative.addView(titleText, relParams);

    // Add the view!
    chartView =
        ChartFactory.getTimeChartView(
            context, buildDateDataset(titles, dates, values), renderer, "MM/dd/yyyy");
    chartView.setId(2);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;
    int chartSize = (int) (width * 0.9);
    relParams = new RelativeLayout.LayoutParams(width, chartSize);
    relParams.addRule(RelativeLayout.BELOW, titleText.getId());
    relParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mRelative.addView(chartView, relParams);

    hrButton = new Button(this);
    hrButton.setId(3);
    hrButton.setText("Measure Resting Heart Rate");
    // hrButton.setWidth(width);
    hrButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            Intent i = new Intent(HcHeartRate.this, FitTestHR.class);
            i.putExtra("nextactivity", "HcHeartRate"); // Telling HR Class what is next activity
            getParent().startActivityForResult(i, HCHEARTRATE_REQUEST_CODE);
          }
        });
    relParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relParams.addRule(RelativeLayout.BELOW, chartView.getId());
    relParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mRelative.addView(hrButton, relParams);
  }