@Override
  public void renderChart(List<CaloriePerDay> data) {
    String[] days = getResources().getStringArray(R.array.days_array);

    float[] caloryData = new float[days.length];
    for (int i = 0; i < data.size(); i++) {
      caloryData[data.get(i).getDayOfWeek() - 1] = data.get(i).getCalories();
    }

    float max = getMaxValue(caloryData);
    int step;

    if (max <= 5) {
      max = 5;
      step = 1;
    } else {
      step = (int) (max / 5f);
    }

    if (mChartView.getData().size() > 0) {
      mChartView.setAxisBorderValues(0, (int) max, step);

      mChartView.updateValues(0, caloryData);
      mChartView.notifyDataUpdate();
      mChartView.show();
      return;
    }
    LineSet dataSet = new LineSet(days, caloryData);
    dataSet
        .setColor(Color.parseColor("#FF4081"))
        .setFill(Color.parseColor("#FF4081"))
        .setSmooth(true);
    mChartView.addData(dataSet);

    mChartView
        .setTopSpacing(Tools.fromDpToPx(5))
        .setBorderSpacing(Tools.fromDpToPx(0))
        .setAxisBorderValues(0, (int) max, step)
        .setXLabels(AxisController.LabelPosition.OUTSIDE)
        .setYLabels(AxisController.LabelPosition.OUTSIDE)
        .setLabelsColor(Color.parseColor("#ffffff"))
        .setAxisColor(Color.parseColor("#ffffff"))
        .setXAxis(false);

    mChartView.show();
  }
Exemplo n.º 2
0
  LineSet createThresh(LineSet d, int height) {

    LineSet thresh = new LineSet();
    int num = 0;
    try {
      for (int i = 0; true; i++) {
        num = i;
        String s = d.getLabel(i);
        thresh.addPoint(s, height);
      }

    } catch (Exception e) {

    }

    thresh.setColor(0x000000);
    thresh.setSmooth(true);
    thresh.setThickness(5);

    float[] f = new float[num];
    for (int i = 0; i < num; i++) {
      f[i] = 10;
    }
    thresh.setDashed(f);
    return thresh;
  }
Exemplo n.º 3
0
  void drawGraph(float[] data) {
    int length = data.length;
    String[] labels = new String[length];
    for (int i = 0; i < length; i++) {
      labels[i] = Integer.toString(i);
    }

    LineChartView lView = (LineChartView) findViewById(R.id.linechart);
    lView.reset();
    LineSet dataSet = new LineSet(labels, data);
    //
    dataSet.setDotsRadius(15);
    dataSet.setDotsColor(0xFFFFFF);
    dataSet.setColor(0xBCCACF);

    // dataSet.setGradientFill(new int[]{0xFFFFFF, 0x20CE99}, new float[]{0, 1});
    lView.setBackgroundColor(0x20CE99);
    //        dataSet.setFill(0x20CE99);
    dataSet.setDotsStrokeColor(0xBCCACF);
    dataSet.setDotsStrokeThickness(10);

    Animation anim = new Animation(2000);
    anim.setEasing(new CircEase());
    lView.setYLabels(AxisController.LabelPosition.NONE);
    //        lView.setYAxis(false);

    Paint p = new Paint();

    p.setColor(0xBCCACF);
    //        lView.setValueThreshold(10, 10, p);
    lView.setAxisThickness(5);

    // LineSet threshLower = new LineSet(new String[]{"1", "2", "3", "4", "5", "6"}, new
    // float[]{10,10,10,10,10,10});

    //        LineSet threshLower = new LineSet(new String[]{"1", "2", "3", "4", "5", "6"}, new
    // float[]{10,10,10,10,10,10,});
    //
    //        threshLower.setColor(0x000000);
    //
    //        threshLower.setDashed(new float[]{10, 10, 10, 10, 10, 10});
    //        threshLower.setSmooth(true);
    //        threshLower.setThickness(5);

    lView.addData(createThresh(dataSet, 70));
    lView.addData(createThresh(dataSet, 200));
    lView.addData(dataSet);

    lView.show(anim);

    bGlucose = (TextView) findViewById(R.id.bglucose);

    setGlucoseLevel((int) data[length - 1]);
  }