예제 #1
0
  private void generateInitialLineData() {
    int numValues = 7;
    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_GREEN).setCubic(true);
    List<Line> lines = new ArrayList<Line>();
    lines.add(line);
    lineData = new LineChartData(lines);
    lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true));
    lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(3));
    chartTop.setLineChartData(lineData);
    // For build-up animation you have to disable viewport recalculation.
    chartTop.setViewportCalculationEnabled(false);

    // And set initial max viewport and current viewport- remember to set viewports after data.
    Viewport v = new Viewport(0, 110, 6, 0);
    chartTop.setMaximumViewport(v);
    chartTop.setCurrentViewport(v);

    chartTop.setZoomType(ZoomType.HORIZONTAL);
    generateLineData(ChartUtils.COLOR_GREEN, 100);
  }
예제 #2
0
 private void updateChartView() {
   Viewport viewport = new Viewport(0, maxValueOfLineChartData + OFFSET, maxNumberToShow, 0);
   chart.setMaximumViewport(viewport);
   chart.setCurrentViewport(viewport);
   previewChart.setMaximumViewport(viewport);
   previewX(false);
 }
    // 产生数据 实时
    /////////////////////////////////////////////////////////////////////////////////////////
    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();
    }
예제 #4
0
  public void setupCharts() {
    if (bgDataList.size()
        > 0) { // Dont crash things just because we dont have values, people dont like crashy things
      if (singleLine) {
        bgGraphBuilder =
            new BgGraphBuilder(getApplicationContext(), bgDataList, pointSize, midColor);
      } else {
        bgGraphBuilder =
            new BgGraphBuilder(
                getApplicationContext(), bgDataList, pointSize, highColor, lowColor, midColor);
      }

      chart.setLineChartData(bgGraphBuilder.lineData());
      chart.setViewportCalculationEnabled(true);
      chart.setMaximumViewport(chart.getMaximumViewport());
    } else {
      ListenerService.requestData(this);
    }
  }
    public void setupChart() {
      basalvsTempBasalChart.setZoomType(ZoomType.HORIZONTAL);
      basalvsTempBasalChart.setLineChartData(extendedGraphBuilder.basalvsTempBasalData());

      Viewport iobv =
          new Viewport(
              basalvsTempBasalChart
                  .getMaximumViewport()); // Sets the min and max for Top and Bottom of the
                                          // viewpoint
      iobv.top = extendedGraphBuilder.maxBasal.floatValue();
      iobv.bottom = -(extendedGraphBuilder.maxBasal.floatValue() - 1);
      basalvsTempBasalChart.setMaximumViewport(iobv);
      iobv.left = previewChart.getCurrentViewport().left;
      iobv.right = previewChart.getCurrentViewport().right;
      basalvsTempBasalChart.setCurrentViewport(iobv);

      basalvsTempBasalChart.setViewportCalculationEnabled(true);
      // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener());
      // //causes a crash, no idea why #// TODO: 28/08/2015
    }
    public void setupChart() {

      iobcobPastChart.setZoomType(ZoomType.HORIZONTAL);
      iobcobPastChart.setLineChartData(extendedGraphBuilder.iobcobPastLineData());

      Viewport iobv =
          new Viewport(
              iobcobPastChart
                  .getMaximumViewport()); // Sets the min and max for Top and Bottom of the
                                          // viewpoint
      iobv.top = Float.parseFloat(extendedGraphBuilder.yCOBMax.toString());
      iobv.bottom = Float.parseFloat(extendedGraphBuilder.yCOBMin.toString());
      iobcobPastChart.setMaximumViewport(iobv);
      iobv.left = previewChart.getCurrentViewport().left;
      iobv.right = previewChart.getCurrentViewport().right;
      iobcobPastChart.setCurrentViewport(iobv);

      iobcobPastChart.setViewportCalculationEnabled(true);
      // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener());
      // //causes a crash, no idea why #// TODO: 28/08/2015
    }
  private void updateGraph(Cursor cursor) {
    // set up the goal line
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    int goalCalories = Integer.parseInt(prefs.getString("preference_calorie_goal", "2000"));
    List<PointValue> goalValues = new ArrayList<>();

    // set up the data
    List<PointValue> values = new ArrayList<>();
    cursor.moveToFirst();

    if (!cursor.isAfterLast()) {
      goalValues.add(new PointValue(getTimeFromRow(cursor), goalCalories));
    }

    while (cursor.isAfterLast() == false) {
      float value = cursor.getFloat(cursor.getColumnIndex("total"));
      // Log.d("graph", "adding " + value + " on " + sdf.format(getTimeFromRow(cursor)));
      values.add(new PointValue(getTimeFromRow(cursor), value));
      cursor.moveToNext();
    }

    cursor.moveToLast();
    goalValues.add(new PointValue(getTimeFromRow(cursor), goalCalories));

    List<Line> lines = new ArrayList<Line>();

    Line goalLine = new Line(goalValues).setColor(Color.parseColor("#ff0000"));
    lines.add(goalLine);

    Line line = new Line(values).setColor(Color.parseColor("#44a134")).setCubic(true);
    // line.setFilled(true);
    // line.setHasLabels(true);

    lines.add(line);

    LineChartData data = new LineChartData();
    data.setLines(lines);

    Axis timeAxis = new Axis();
    // timeAxis.setName("");
    // timeAxis.setTextColor(ChartUtils.COLOR_ORANGE);
    timeAxis.setMaxLabelChars(5);
    timeAxis.setFormatter(new TimestampAxisFormatter());
    timeAxis.setHasLines(true);
    timeAxis.setHasTiltedLabels(true);
    data.setAxisXBottom(timeAxis);

    Axis calorieAxis = new Axis();
    // weightAxis.setName("");
    // weightAxis.setTextColor(ChartUtils.COLOR_GREEN);
    calorieAxis.setMaxLabelChars(7);
    calorieAxis.setFormatter(new SimpleAxisValueFormatter().setAppendedText(" C".toCharArray()));
    calorieAxis.setHasLines(true);
    calorieAxis.setHasTiltedLabels(true);
    data.setAxisYLeft(calorieAxis);

    hellochart.setLineChartData(data);
    hellochart.setZoomType(ZoomType.HORIZONTAL);
    hellochart.setOnValueTouchListener(new ValueTouchListener());

    // set up zoom so we can see 0 calories
    Viewport viewport = new Viewport(hellochart.getMaximumViewport());
    viewport.bottom = 0;
    hellochart.setMaximumViewport(viewport);
    hellochart.setCurrentViewport(viewport);

    hellochart.invalidate();
  }