Ejemplo n.º 1
0
  private void createChart(View v) {
    BarChart chart = (BarChart) v.findViewById(R.id.barChart);
    chart.clear();
    PSDatePickerView datePickerView = (PSDatePickerView) v.findViewById(R.id.date_picker_view);
    PSUserDataCollection dataCollection = PSDataStore.getInstance().getUserDataCollection();
    ArrayList<BarEntry> entriesAgg = new ArrayList<BarEntry>();
    ArrayList<String> xVals = new ArrayList<String>();

    int idx = 0;
    for (Calendar cur = (Calendar) datePickerView.getStartDate().clone();
        PSUtil.beforeCalender(cur, datePickerView.getEndDate());
        cur.add(Calendar.DATE, 1)) {
      PSDailyData dailyData = dataCollection.getDailyData(cur.getTimeInMillis());
      BarEntry ent = null;
      if (dailyData != null) {
        ent = new BarEntry(dailyData.getFormula(), idx, dailyData);
      }
      if (ent != null) {
        entriesAgg.add(ent);
      }
      xVals.add(PSUtil.weekDays[idx]);

      idx++;
    }

    BarDataSet setAgg = new BarDataSet(entriesAgg, PSDataStore.getInstance().getUser().getName());
    setAgg.setAxisDependency(YAxis.AxisDependency.LEFT);
    setAgg.setColor(getResources().getColor(R.color.ps_blue_sky));

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

    // BarData
    BarData data = new BarData(xVals, dataSets);
    chart.setData(data);
    // Config chart
    chart.setDescription("");
    chart.setDrawHighlightArrow(true);
    // Config axises
    YAxis leftAxis = chart.getAxisLeft();
    YAxis rightAxis = chart.getAxisRight();
    leftAxis.setDrawGridLines(false);
    rightAxis.setDrawGridLines(false);
    // Config limit line
    LimitLine ll = new LimitLine(60f);
    ll.setLineColor(Color.CYAN);
    ll.setLineWidth(1f);
    leftAxis.removeAllLimitLines();
    leftAxis.addLimitLine(ll);
    // Config marker
    PSDailyDataMarkerView markerView =
        new PSDailyDataMarkerView(v.getContext(), R.layout.ps_daily_data_marker_view);
    chart.setMarkerView(markerView);
    // Legend
    Legend l = chart.getLegend();
    l.setEnabled(false);
    // Show data
    chart.animateY(600);
  }
Ejemplo n.º 2
0
 private void setupControls(View view) {
   PSDatePickerView datePickerView = (PSDatePickerView) view.findViewById(R.id.date_picker_view);
   datePickerView.setListener(
       new PSDatePickerView.PSDatePickerViewListener() {
         @Override
         public void onDateChanged() {
           createChart(getView());
         }
       });
   Button changeButton = (Button) view.findViewById(R.id.change);
   changeButton.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           showAlertDialog();
         }
       });
 }