예제 #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);
  }
 @Override
 protected void setupChart() {
   super.setupChart();
   lineChart.setData(setupTheeComponentData("X", "Y", "Z"));
   lineChart.getLegend().setEnabled(true);
   lineChart.getLegend().setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
   LimitLine line = new LimitLine(FeatureAcceleration.DATA_MIN, "timestamp (ms)");
   line.setLineColor(Color.BLACK);
   line.setLineWidth(1f);
   line.setTextColor(Color.BLACK);
   line.setTextSize(12f);
   line.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_TOP);
   lineChart.getAxisLeft().addLimitLine(line);
 }
예제 #3
0
  @Override
  public View getView(int position, View convertView, Context c) {

    ViewHolder holder = null;

    if (convertView == null) {

      holder = new ViewHolder();

      convertView = LayoutInflater.from(c).inflate(R.layout.list_item_linechart, null);
      holder.chart = (LineChart) convertView.findViewById(R.id.chart);

      convertView.setTag(holder);

    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    // holder.chart.setValueTypeface(mTf);
    holder.chart.setDescription("");
    holder.chart.setDrawGridBackground(false);

    XAxis xAxis = holder.chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);

    YAxis leftAxis = holder.chart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(5, false);

    YAxis rightAxis = holder.chart.getAxisRight();
    rightAxis.setTypeface(mTf);
    rightAxis.setLabelCount(5, false);
    rightAxis.setDrawGridLines(false);

    // set data
    holder.chart.setData((LineData) mChartData);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateX(750);
    // at 20151130
    // at 20151117
    //        if(mType==0) {
    //        	LimitLine ll = new LimitLine(30, "目标温度");
    //        	ll.setLineWidth(4f);
    //        	ll.enableDashedLine(10f, 10f, 0f);
    //        	ll.setLabelPosition(LimitLabelPosition.LEFT_BOTTOM);
    //        	ll.setTextSize(10f);
    //        	leftAxis.addLimitLine(ll);
    //        } else {
    //            LimitLine ll = new LimitLine(60, "目标湿度");
    //            ll.setLineWidth(4f);
    //            ll.enableDashedLine(10f, 10f, 0f);
    //            ll.setLabelPosition(LimitLabelPosition.LEFT_BOTTOM);
    //            ll.setTextSize(10f);
    //            leftAxis.addLimitLine(ll);
    //        }

    // end 20151117
    LimitLine ll = new LimitLine(this.aimValue, this.aimName);
    ll.setLineWidth(4f);
    ll.enableDashedLine(10f, 10f, 0f);
    ll.setLabelPosition(LimitLabelPosition.LEFT_BOTTOM);
    ll.setTextSize(10f);
    leftAxis.addLimitLine(ll);
    // end 20151130
    return convertView;
  }