private void setData(int start, int count, float range) {

    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < count; i++) {
      xVals.add((start + i) + "日");
    }

    ArrayList<Entry> vals1 = new ArrayList<Entry>();

    for (int i = 0; i < count; i++) {
      vals1.add(new Entry(TurnControl.PunchPerDay[9 - i], i));
    }

    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(vals1, "近期打卡情况");
    set1.setDrawCubic(true);
    set1.setCubicIntensity(0.2f);
    set1.setDrawFilled(true);
    set1.setDrawCircles(true);
    set1.setLineWidth(2f);
    set1.setCircleSize(5f);
    set1.setHighLightColor(Color.rgb(244, 117, 117));
    set1.setColor(Color.rgb(104, 241, 175));
    set1.setFillColor(ColorTemplate.getHoloBlue());

    // create a data object with the datasets
    LineData data = new LineData(xVals, set1);
    data.setValueTypeface(tf);
    data.setValueTextSize(9f);
    data.setDrawValues(false);

    // set data
    mChart.setData(data);
  }
  @Override
  public void onResponse(Response<List<Purchase>> response) {
    if (!response.isSuccess()) {
      return;
    }

    List<Purchase> purchases = response.body();

    if (purchases.size() < 2) {
      setAlpha(.2f);
      purchases = PLACEHOLDER_DATA;
    } else {
      setAlpha(1);
    }

    ArrayList<String> xVals = new ArrayList<>();
    ArrayList<Entry> yVals = new ArrayList<>();
    for (int i = 0; i < purchases.size(); i++) {
      xVals.add(String.valueOf(i));
      yVals.add(new Entry(purchases.get(purchases.size() - i - 1).amount, i));
    }

    LineDataSet dataSet = new LineDataSet(yVals, "Purchases");
    dataSet.setDrawValues(false);
    dataSet.setDrawCircles(false);
    dataSet.setColor(Color.WHITE);
    dataSet.setDrawFilled(true);
    dataSet.setFillColor(Color.WHITE);
    setData(new LineData(xVals, Collections.singletonList(dataSet)));

    invalidate();
  }
Esempio n. 3
0
  /**
   * Creates a LineDataSet object.
   *
   * @param signalSourceId
   * @param date
   * @return
   */
  public LineDataSet createChartDataSet(String signalSourceId, Date date) {
    LineDataSet lineDataSet = new LineDataSet(new ArrayList<Entry>(), signalSourceId);
    int color = getColor(signalSourceId);
    lineDataSet.setColors(new int[] {color});
    lineDataSet.setDrawCircles(false);

    return lineDataSet;
  }
  private void loadData(boolean drawLast) {
    ChartCollection collection =
        fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection();
    if (collection != null) {
      int size = collection.size();
      if (size > 0) {
        List<Entry> entries = new ArrayList<>();
        List<String> xVals = new ArrayList<>();

        ChartData data = collection.getCharData(size - 1);
        Map<Double, Double> values = data.getData();
        List<Double> keyList = new ArrayList<>();
        keyList.addAll(values.keySet());
        Collections.sort(keyList);

        for (Double x : keyList) {
          Number numX = x;
          int intX = numX.intValue();
          xVals.add(String.valueOf(x));

          double value = values.get(x);

          Number num = value;
          float val = num.floatValue();
          Entry entry = new Entry(val, intX);
          entries.add(entry);
        }

        LineDataSet dataSet = new LineDataSet(entries, "Dados");
        dataSet.setDrawCircleHole(false);
        dataSet.setDrawCircles(false);
        LineData chartData = new LineData(xVals, dataSet);
        chart.setData(chartData);

        totalGraphs = size;
        if (drawLast) {
          currentGraph = totalGraphs;
        } else {
          if (currentGraph < 1 || currentGraph > size) {
            currentGraph = totalGraphs;
          }
        }

        mainHandler.post(
            new Runnable() {
              @Override
              public void run() {
                chart.notifyDataSetChanged();
                chart.invalidate();

                txtTotal.setText(String.valueOf(totalGraphs));
                txtCurrent.setText(String.valueOf(currentGraph));
              }
            });
      }
    }
  }
Esempio n. 5
0
 public void formatDataSet(LineDataSet set, @ColorInt int color) {
   set.setColor(color);
   set.setLineWidth(2.5f);
   set.setCircleColor(color);
   set.setCircleSize(5f);
   set.setFillColor(color);
   set.setDrawCubic(true);
   set.setValueTextSize(10f);
   set.setDrawValues(false);
   set.setDrawCircles(false);
   set.setValueTextColor(color);
   set.setDrawFilled(true);
 }
Esempio n. 6
0
 @NonNull
 private LineDataSet setMaLine(int ma, ArrayList<String> xVals, ArrayList<Entry> lineEntries) {
   LineDataSet lineDataSetMa = new LineDataSet(lineEntries, "ma" + ma);
   if (ma == 5) {
     lineDataSetMa.setHighlightEnabled(true);
     lineDataSetMa.setDrawHorizontalHighlightIndicator(false);
     lineDataSetMa.setHighLightColor(Color.WHITE);
   } else {
       /*此处必须得写*/
     lineDataSetMa.setHighlightEnabled(false);
   }
   lineDataSetMa.setDrawValues(false);
   if (ma == 5) {
     lineDataSetMa.setColor(Color.GREEN);
   } else if (ma == 10) {
     lineDataSetMa.setColor(Color.GRAY);
   } else {
     lineDataSetMa.setColor(Color.YELLOW);
   }
   lineDataSetMa.setLineWidth(1f);
   lineDataSetMa.setDrawCircles(false);
   lineDataSetMa.setAxisDependency(YAxis.AxisDependency.LEFT);
   return lineDataSetMa;
 }
  private void setData(int count, float range) {

    // only using first meter for now.
    // TODO: graph multiple meters?
    Meter meter = mMeters.get(0);
    List<MeterReading> readings = meter.getReadings();

    ArrayList<Entry> averageEntries = new ArrayList<Entry>();

    // build up X-axis labels; e.g., dates.
    // build up Y-axis with values;
    // skip first date as we can't determine consumption.
    ArrayList<String> xVals = new ArrayList<String>();
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    float runningTotal = 0;
    float dailyAverage;
    for (int lv = 1; lv < count; lv++) {
      MeterReading prevReading = readings.get(lv - 1);
      MeterReading currReading = readings.get(lv);

      xVals.add(removeYearFromDate(currReading.getTimeStamp()));
      float val = (currReading.getConsumption() - prevReading.getConsumption()) * 10;
      yVals1.add(new BarEntry(val, lv - 1));

      // calc & store daily average.
      runningTotal += val;
      dailyAverage = runningTotal / lv;
      averageEntries.add(new Entry(dailyAverage, lv - 1));
    }

    // TODO: allow name to be updated.
    BarDataSet set1 = new BarDataSet(yVals1, "mine");
    set1.setBarSpacePercent(35f);

    ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
    dataSets.add(set1);

    // bar chart data
    BarData barData = new BarData(xVals, dataSets);
    barData.setValueFormatter(new MyValueFormatter());
    barData.setValueTextSize(10f);

    // line chart data
    LineData lineData = new LineData();
    LineDataSet set = new LineDataSet(averageEntries, "average");
    int lineColor = Color.rgb(251, 169, 165);
    set.setColor(lineColor);
    set.setLineWidth(1.5f);
    set.setDrawCircles(false);
    set.setFillColor(lineColor);
    set.setDrawCubic(true);
    set.setDrawValues(false);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    lineData.addDataSet(set);

    CombinedData combinedData = new CombinedData(getDates(meter.getReadings()));
    combinedData.setData(barData);
    combinedData.setData(lineData);

    mChart.setData(combinedData);
    mChart.invalidate();
  }
Esempio n. 8
0
  private void drawChart() {
    BPRecord[] recs = mRecords;
    LineChart chart = (LineChart) findViewById(R.id.chart);
    ArrayList<Entry> valsHigh = new ArrayList<Entry>();
    ArrayList<Entry> valsLow = new ArrayList<Entry>();
    // ArrayList<Entry> heartRate = new ArrayList<Entry>();
    // ArrayList<Entry> o2Index = new ArrayList<Entry>();
    // ArrayList<Entry> avgArtP = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    Date firstTime = null;
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat f2 = new SimpleDateFormat("MM/dd HH:mm");
    for (int i = 0; i < recs.length; ++i) {
      BPRecord rec = recs[i];
      int x = 0; // minutes from first data
      Date time = new Date();
      try {
        time = f.parse(rec.dateTime);
      } catch (ParseException ex) {
        Log.d("GetBPDate", "Exception:" + ex.toString());
        continue;
      }
      if (firstTime == null) {
        firstTime = time;
      } else {
        x = (int) ((time.getTime() - firstTime.getTime()) / 60000);
      }
      x = i;
      xVals.add(f2.format(time));
      valsHigh.add(new Entry(rec.systolic, x));
      valsLow.add(new Entry(rec.diastolic, x));
      // heartRate.add(new Entry(rec.heartRate,x));
      // avgArtP.add(new Entry(rec.avg_art_pressure,x));
      // o2Index.add(new Entry(rec.o2Index/100,x));
    }
    String hp = getResources().getString(R.string.hightPressure);
    String lp = getResources().getString(R.string.lowPressure);
    /*
    String hr = getResources().getString(R.string.heartBeatLabel);
    String avgAP = getResources().getString(R.string.average_artery_pressure);
    String o2 = getResources().getString(R.string.O2Index);
    */
    LineDataSet setHigh = new LineDataSet(valsHigh, hp);
    setHigh.setAxisDependency(YAxis.AxisDependency.LEFT);
    setHigh.setDrawCircles(false);
    setHigh.setColor(Color.RED);
    setHigh.setValueFormatter(new IntFormatter());
    setHigh.setValueTextSize(10);
    LineDataSet setLow = new LineDataSet(valsLow, lp);
    setLow.setAxisDependency(YAxis.AxisDependency.LEFT);
    setLow.setColor(Color.BLUE);
    setLow.setDrawCircles(false);
    setLow.setValueFormatter(new IntFormatter());
    setLow.setValueTextSize(10);
    /*
    LineDataSet setHr = new LineDataSet(heartRate, hr);
    setHr.setAxisDependency(YAxis.AxisDependency.LEFT);
    setHr.setColor(Color.GREEN);
    setHr.setDrawCircles(false);
    setHr.setValueFormatter(new IntFormatter());
    setHr.setValueTextSize(10);
    LineDataSet setAAP = new LineDataSet(avgArtP, avgAP);
    setAAP.setAxisDependency(YAxis.AxisDependency.LEFT);
    setAAP.setColor(Color.DKGRAY);
    setAAP.setDrawCircles(false);
    setAAP.setValueFormatter(new IntFormatter());
    setAAP.setValueTextSize(10);
    LineDataSet setO2 = new LineDataSet(o2Index, o2);
    setO2.setAxisDependency(YAxis.AxisDependency.LEFT);
    setO2.setColor(Color.CYAN);
    setO2.setDrawCircles(false);
    setO2.setValueFormatter(new IntFormatter());
    setO2.setValueTextSize(10);
    */
    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(setHigh);
    dataSets.add(setLow);
    /*
    dataSets.add(setHr);
    dataSets.add(setAAP);
    dataSets.add(setO2);
    */

    /*
    xVals.add("12-15"); xVals.add("12-17"); xVals.add("12-18"); xVals.add("12-20");
    xVals.add("12-21"); xVals.add("12-22"); xVals.add("12-23"); xVals.add("12-24");
    */

    LineData data = new LineData(xVals, dataSets);
    // chart.setGridBackgroundColor(Color.BLACK);
    // chart.getLegend().setEnabled(false);
    chart.setData(data);
    chart.setDescription(getResources().getString(R.string.blood_pressure));
    chart.invalidate(); // refresh
  }