// 产生数据 记录
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    private void generateDefaultData(int[] recordMsgBuffer) {
      int max = recordMsgBuffer[0];
      int min = recordMsgBuffer[0];
      List<PointValue> values = new ArrayList<PointValue>();

      for (int j = 0; j < recordMsgBuffer.length; j++) {
        values.add(new PointValue(j, (float) recordMsgBuffer[j] / 10f));

        if (recordMsgBuffer[j] > max) {
          max = recordMsgBuffer[j];
        }

        if (recordMsgBuffer[j] < min) {
          min = recordMsgBuffer[j];
        }
      }

      if (max - min < 50) {
        max = max + 25;
        min = min - 25;
      }

      Line line = new Line(values);
      line.setColor(ChartUtils.COLOR_GREEN);
      line.setHasPoints(false); // too many values so don't draw points.
      //            line.setFilled(true);

      List<PointValue> values1 = new ArrayList<PointValue>();
      values1.add(new PointValue(0, (float) max / 10f + 0.2f));
      Line line1 = new Line(values1);
      line1.setHasPoints(false); // too many values so don't draw points.
      line1.setPointRadius(0);

      List<PointValue> values2 = new ArrayList<PointValue>();
      values2.add(new PointValue(0, (float) min / 10f - 0.2f));
      Line line2 = new Line(values2);
      line2.setHasPoints(false); // too many values so don't draw points.
      line2.setPointRadius(0);

      List<Line> lines = new ArrayList<Line>();
      lines.add(line);
      lines.add(line1);
      lines.add(line2);

      data = new LineChartData(lines);
      data.setAxisXBottom(new Axis().setHasLines(true).setTextColor(ChartUtils.COLOR_GREEN));
      data.setAxisYLeft(
          new Axis().setHasLines(true).setMaxLabelChars(4).setTextColor(ChartUtils.COLOR_GREEN));

      // prepare preview data, is better to use separate deep copy for preview recordChart.
      // Set color to grey to make preview area more visible.
      previewData = new LineChartData(data);
      previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);
    }
    private void generateLineData(int color, int range, float textTemple) {
      // Cancel last animation if not finished.
      // chartTop.cancelDataAnimation();

      // Modify data targets
      // 修改数据目标
      Line line = lineData.getLines().get(0); // For this example there is always only one line.
      line.setColor(color);
      line.setFilled(true);
      line.setHasLabels(true);
      line.setHasPoints(false);
      List<PointValue> lineList = line.getValues();

      for (int j = 0; j < lineList.size(); j++) {
        PointValue value = lineList.get(j);
        if (j == lineList.size() - 1) {
          value.setTarget(value.getX(), textTemple);
        } else {
          PointValue nextValue = lineList.get(j + 1);
          value.setTarget(value.getX(), nextValue.getY());
        }
      }

      // Start new data animation with 300ms duration;
      realeChartTop.startDataAnimation(0);
    }
 public Line rawInterpretedLine() {
   Line line = new Line(rawInterpretedValues);
   line.setHasLines(false);
   line.setPointRadius(1);
   line.setHasPoints(true);
   return line;
 }
 public Line inRangeValuesLine() {
   Line inRangeValuesLine = new Line(inRangeValues);
   inRangeValuesLine.setColor(Utils.COLOR_BLUE);
   inRangeValuesLine.setHasLines(false);
   inRangeValuesLine.setPointRadius(pointSize);
   inRangeValuesLine.setHasPoints(true);
   return inRangeValuesLine;
 }
 public Line lowValuesLine() {
   Line lowValuesLine = new Line(lowValues);
   lowValuesLine.setColor(Color.parseColor("#C30909"));
   lowValuesLine.setHasLines(false);
   lowValuesLine.setPointRadius(pointSize);
   lowValuesLine.setHasPoints(true);
   return lowValuesLine;
 }
 public Line highValuesLine() {
   Line highValuesLine = new Line(highValues);
   highValuesLine.setColor(Utils.COLOR_ORANGE);
   highValuesLine.setHasLines(false);
   highValuesLine.setPointRadius(pointSize);
   highValuesLine.setHasPoints(true);
   return highValuesLine;
 }
 public Line inRangeValuesLine() {
   Line inRangeValuesLine = new Line(inRangeValues);
   inRangeValuesLine.setColor(Color.parseColor("#00FF00"));
   inRangeValuesLine.setHasLines(false);
   inRangeValuesLine.setPointRadius(pointSize);
   inRangeValuesLine.setHasPoints(true);
   return inRangeValuesLine;
 }
 public Line highValuesLine() {
   Line highValuesLine = new Line(highValues);
   highValuesLine.setColor(Color.parseColor("#FFFF00"));
   highValuesLine.setHasLines(false);
   highValuesLine.setPointRadius(pointSize);
   highValuesLine.setHasPoints(true);
   return highValuesLine;
 }
 public Line maxShowLine() {
   List<PointValue> maxShowValues = new ArrayList<PointValue>();
   maxShowValues.add(new PointValue((float) start_time / FUZZER, (float) defaultMaxY));
   maxShowValues.add(new PointValue((float) end_time / FUZZER, (float) defaultMaxY));
   Line maxShowLine = new Line(maxShowValues);
   maxShowLine.setHasLines(false);
   maxShowLine.setHasPoints(false);
   return maxShowLine;
 }
 public Line minShowLine() {
   List<PointValue> minShowValues = new ArrayList<PointValue>();
   minShowValues.add(new PointValue((float) start_time, (float) defaultMinY));
   minShowValues.add(new PointValue((float) end_time, (float) defaultMinY));
   Line minShowLine = new Line(minShowValues);
   minShowLine.setHasPoints(false);
   minShowLine.setHasLines(false);
   return minShowLine;
 }
 public Line highLine() {
   List<PointValue> highLineValues = new ArrayList<PointValue>();
   highLineValues.add(new PointValue((float) start_time, (float) highMark));
   highLineValues.add(new PointValue((float) end_time, (float) highMark));
   Line highLine = new Line(highLineValues);
   highLine.setHasPoints(false);
   highLine.setStrokeWidth(1);
   highLine.setColor(Utils.COLOR_ORANGE);
   return highLine;
 }
 public Line lowLine() {
   List<PointValue> lowLineValues = new ArrayList<PointValue>();
   lowLineValues.add(new PointValue((float) start_time, (float) lowMark));
   lowLineValues.add(new PointValue((float) end_time, (float) lowMark));
   Line lowLine = new Line(lowLineValues);
   lowLine.setHasPoints(false);
   lowLine.setAreaTransparency(50);
   lowLine.setColor(Color.parseColor("#C30909"));
   lowLine.setStrokeWidth(1);
   lowLine.setFilled(true);
   return lowLine;
 }
    // 产生数据 实时
    /////////////////////////////////////////////////////////////////////////////////////////
    private void generateInitialLineData() {
      int numValues = 19;

      List<AxisValue> axisValues = new ArrayList<AxisValue>();
      List<PointValue> values = new ArrayList<PointValue>();
      for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, 0));
        axisValues.add(new AxisValue(i).setLabel(days[i]));
      }

      Line line = new Line(values);
      line.setColor(ChartUtils.COLOR_BLUE);
      line.setHasPoints(false);
      line.getShape();
      line.setCubic(false); // 平滑

      List<Line> lines = new ArrayList<Line>();
      lines.add(line);
      //            lines.add(line1);
      //            lines.add(line2);

      Axis axisX = new Axis(axisValues);
      Axis axisY = new Axis().setHasLines(true);
      if (hasAxesNames) {
        axisX.setName("时间间隔");
        // axisY.setName("温度");
        axisX.setTextColor(ChartUtils.HOLO_BLUE_DARK);
        axisY.setTextColor(ChartUtils.HOLO_BLUE_DARK);
      }

      lineData = new LineChartData(lines);
      lineData.setAxisXBottom(axisX.setHasLines(true));
      lineData.setAxisYLeft(axisY.setMaxLabelChars(4));

      realeChartTop.setLineChartData(lineData);

      // For build-up animation you have to disable viewport recalculation.
      // 建立动画你必须禁用视图重新计算。
      realeChartTop.setViewportCalculationEnabled(false);

      // And set initial max viewport and current viewport- remember to set viewports after data.
      // 设置初始值和当前视口视口记得要在数据集视图。
      Viewport v = new Viewport(0, 50, 20, -10);
      realeChartTop.setMaximumViewport(v);
      realeChartTop.setCurrentViewport(v);
      realeChartTop.setZoomType(ZoomType.HORIZONTAL);

      // toggleFilled();
      // toggleLabels();
      toggleAxesNames();
    }
        @Override
        public void onDataReceived(DataReadResult dataReadResult) {
          Log.d(TAG, "Received activity result");
          final String DATE_FORMAT = "dd/MM";
          SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);

          List<Line> lines = new ArrayList<>(); // all lines
          List<PointValue> calories; // a single line
          calories = new ArrayList<>();
          int x_val = 0;
          List<AxisValue> xAxisValues = new ArrayList<>();

          if (dataReadResult.getBuckets().size() > 0) {
            for (Bucket bucket : dataReadResult.getBuckets()) {
              String date = dateFormat.format(bucket.getStartTime(TimeUnit.MILLISECONDS));
              DataSet dataSet = bucket.getDataSet(DataType.AGGREGATE_CALORIES_EXPENDED);
              Log.d(TAG, "New databucket with date: " + date);

              // Increase counter
              x_val = x_val + 1;

              // Set axis labels
              xAxisValues.add(new AxisValue(x_val).setLabel(date));

              // Add a zero measurement point
              calories.add(new PointValue(x_val, 0));

              List<DataPoint> dataPointList = dataSet.getDataPoints();
              for (DataPoint dp : dataPointList) {
                String timestamp = dateFormat.format(dp.getTimestamp(TimeUnit.MILLISECONDS));
                float calorie = dp.getValue(Field.FIELD_CALORIES).asFloat();

                // Set graph values
                calories.set(x_val - 1, new PointValue(x_val, calorie));
                Log.d(TAG, "timestamp: " + timestamp + ", calories: " + calorie);
              }
            }
            Line line = new Line(calories);
            line.setColor(ChartUtils.COLOR_BLUE);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            line.setHasLabels(false);
            line.setHasLabelsOnlyForSelected(true);
            lines.add(line);

            fitnessFragment.setCalorieData(xAxisValues, lines);
          }
        }
Пример #15
0
  public Line highLine(boolean show) {
    List<PointValue> highLineValues = new ArrayList<PointValue>();
    highLineValues.add(new PointValue((float) start_time / FUZZER, (float) highMark));
    highLineValues.add(new PointValue((float) end_time / FUZZER, (float) highMark));
    Line highLine = new Line(highLineValues);
    highLine.setHasPoints(false);

    highLine.setStrokeWidth(1);
    if (show) {
      highLine.setColor(Color.parseColor("#FFFF00"));
    } else {
      highLine.setColor(Color.TRANSPARENT);
    }
    return highLine;
  }
Пример #16
0
 public Line lowLine(boolean show, boolean line_only) {
   List<PointValue> lowLineValues = new ArrayList<PointValue>();
   lowLineValues.add(new PointValue((float) start_time / FUZZER, (float) lowMark));
   lowLineValues.add(new PointValue((float) end_time / FUZZER, (float) lowMark));
   Line lowLine = new Line(lowLineValues);
   lowLine.setHasPoints(false);
   if (!line_only) {
     lowLine.setAreaTransparency(20);
     lowLine.setFilled(true);
   }
   lowLine.setStrokeWidth(1);
   if (show) {
     lowLine.setColor(Color.parseColor("#FF0000"));
   } else {
     lowLine.setColor(Color.TRANSPARENT);
   }
   return lowLine;
 }
Пример #17
0
  public void addListToChart(List<Day> days) {
    int currentValue;
    int size = days.size();
    maxValueOfLineChartData = 0;
    List<PointValue> valuePoints = new ArrayList<PointValue>();

    if (size == 1) {
      for (int i = 0; i < 24; i++) {
        currentValue = days.get(0).getHours().get(i).getMmm().getMean();
        if (currentValue > maxValueOfLineChartData) {
          maxValueOfLineChartData = currentValue;
        }
        valuePoints.add(new PointValue(i, currentValue));
      }
    } else {
      for (int i = 0; i < size; i++) {
        currentValue = days.get(i).getMmm().getMean();
        if (currentValue > maxValueOfLineChartData) {
          maxValueOfLineChartData = currentValue;
        }
        valuePoints.add(new PointValue(i, currentValue));
      }
    }

    dataLine = new Line(valuePoints);
    dataLine.setColor(ChartUtils.COLOR_ORANGE);
    dataLine.setHasPoints(false);

    List<Line> lines = new ArrayList<Line>();
    lines.add(dataLine);

    data = new LineChartData(lines);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    previewData = new LineChartData(data);
    previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);

    chart.setLineChartData(data);
    previewChart.setLineChartData(previewData);

    updateChartView();
  }
    private LineChartData generatePreviewLineChartData() {
      int numValues = 50;

      List<PointValue> values = new ArrayList<PointValue>();
      for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, (float) Math.random() * 100f));
      }

      Line line = new Line(values);
      line.setColor(ChartUtils.DEFAULT_DARKEN_COLOR);
      line.setHasPoints(false); // too many values so don't draw points.

      List<Line> lines = new ArrayList<Line>();
      lines.add(line);

      LineChartData data = new LineChartData(lines);
      data.setAxisXBottom(new Axis());
      data.setAxisYLeft(new Axis().setHasLines(true));

      return data;
    }
  /** ************************** DATA POINTS *************************** */
  private void getForecastData() {

    List<PointValue> values = new ArrayList<PointValue>();
    // List<PointValue> values2 = new ArrayList<PointValue>();
    for (int i = 0; i < numData; ++i) {
      Log.d("VALUES", "Time: " + Integer.toString(times[i]));
      Log.d("VALUES", "Temp: " + Double.toString(temperatures[i]));

      values.add(new PointValue(times[i], (float) temperatures[i]));
      /*
      if (i==0 || i==6 || i==12 || i==15 || i==17 || i==20) {
          values2.add(new PointValue(times[i], (float) temperatures[i]+(float) (Math.random() - 0.50f)));
      } else {
          values2.add(new PointValue(times[i], values2.get(i-1).getY() + (float) (Math.random()/3 - 0.25f)));
      }*/
    }

    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN);
    line.setHasPoints(false); // too many values so don't draw points.
    List<Line> lines = new ArrayList<Line>();
    lines.add(line);
    /*
            Line line2 = new Line(values2);
            line2.setColor(ChartUtils.COLOR_BLUE);
            line2.setHasPoints(false);
            lines.add(line2);
    */
    data = new LineChartData(lines);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    // prepare preview data, is better to use separate deep copy for preview chart.
    // Set color to grey to make preview area more visible.
    previewData = new LineChartData(data);
    previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);
    //        previewData.getLines().get(1).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);

  }
  private void generateDefaultData() {
    int numValues = 50;

    List<PointValue> values = new ArrayList<PointValue>();
    for (int i = 0; i < numValues; ++i) {
      values.add(new PointValue(i, (float) Math.random() * 100f));
    }

    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN);
    line.setHasPoints(false); // too many values so don't draw points.

    List<Line> lines = new ArrayList<Line>();
    lines.add(line);

    data = new LineChartData(lines);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    // prepare preview data, is better to use separate deep copy for preview chart.
    // Set color to grey to make preview area more visible.
    previewData = new LineChartData(data);
    previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);
  }
        @Override
        public void onDataReceived(DataReadResult dataReadResult) {
          Log.d(TAG, "Received activity result");
          final String DATE_FORMAT = "dd/MM";
          SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
          // GoogleApiSubscription.printData(dataReadResult);

          List<Line> lines = new ArrayList<>(); // all lines
          List<PointValue> walking = new ArrayList<>(); // a single line
          List<PointValue> biking = new ArrayList<>();
          List<PointValue> in_vehicle = new ArrayList<>();
          List<AxisValue> xAxisValues = new ArrayList<>();

          int x_val = 0;

          if (dataReadResult.getBuckets().size() > 0) {
            for (Bucket bucket : dataReadResult.getBuckets()) {
              String date = dateFormat.format(bucket.getStartTime(TimeUnit.MILLISECONDS));
              DataSet dataSet = bucket.getDataSet(DataType.AGGREGATE_ACTIVITY_SUMMARY);
              Log.d(TAG, "New databucket with date: " + date);

              // Increase counter
              x_val = x_val + 1;

              // Set axis labels
              xAxisValues.add(new AxisValue(x_val).setLabel(date));

              // Add a zero measurement point
              walking.add(new PointValue(x_val, 0));
              biking.add(new PointValue(x_val, 0));
              in_vehicle.add(new PointValue(x_val, 0));

              List<DataPoint> dataPointList = dataSet.getDataPoints();
              for (DataPoint dp : dataPointList) {
                String timestamp = dateFormat.format(dp.getTimestamp(TimeUnit.MILLISECONDS));
                String activity = dp.getValue(Field.FIELD_ACTIVITY).asActivity();
                int duration = dp.getValue(Field.FIELD_DURATION).asInt();

                if (dp.getValue(Field.FIELD_ACTIVITY).asActivity() == "walking") {
                  walking.set(x_val - 1, new PointValue(x_val, duration / 60000));
                } else if (dp.getValue(Field.FIELD_ACTIVITY).asActivity() == "biking") {
                  biking.set(x_val - 1, new PointValue(x_val, duration / 60000));
                } else if (dp.getValue(Field.FIELD_ACTIVITY).asActivity() == "in_vehicle") {
                  in_vehicle.set(x_val - 1, new PointValue(x_val, duration / 60000));
                }
                Log.d(
                    TAG,
                    "timestamp: "
                        + timestamp
                        + ", activity: "
                        + activity
                        + ", duration: "
                        + duration / 60000);
              }
            }
            Line line = new Line(walking);
            line.setColor(ChartUtils.COLOR_GREEN);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            lines.add(line);

            line = new Line(biking);
            line.setColor(ChartUtils.COLOR_BLUE);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            lines.add(line);

            line = new Line(in_vehicle);
            line.setColor(ChartUtils.COLOR_VIOLET);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            lines.add(line);

            fitnessFragment.setActivityData(xAxisValues, lines);
          }
        }