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);
 }
Exemple #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;
  }
Exemple #4
0
  /**
   * Draws the LimitLines associated with this axis to the screen.
   *
   * @param c
   */
  @Override
  public void renderLimitLines(Canvas c) {

    List<LimitLine> limitLines = mXAxis.getLimitLines();

    if (limitLines == null || limitLines.size() <= 0) return;

    float[] pts = new float[4];
    Path limitLinePath = new Path();

    for (int i = 0; i < limitLines.size(); i++) {

      LimitLine l = limitLines.get(i);

      pts[0] = l.getLimit();
      pts[2] = l.getLimit();

      mTrans.pointValuesToPixel(pts);

      pts[1] = mViewPortHandler.contentTop();
      pts[3] = mViewPortHandler.contentBottom();

      limitLinePath.moveTo(pts[0], pts[1]);
      limitLinePath.lineTo(pts[2], pts[3]);

      mLimitLinePaint.setStyle(Paint.Style.STROKE);
      mLimitLinePaint.setColor(l.getLineColor());
      mLimitLinePaint.setStrokeWidth(l.getLineWidth());
      mLimitLinePaint.setPathEffect(l.getDashPathEffect());

      c.drawPath(limitLinePath, mLimitLinePaint);
      limitLinePath.reset();

      String label = l.getLabel();

      // if drawing the limit-value label is enabled
      if (label != null && !label.equals("")) {

        float xOffset = l.getLineWidth();
        float add = Utils.convertDpToPixel(4f);

        mLimitLinePaint.setStyle(l.getTextStyle());
        mLimitLinePaint.setPathEffect(null);
        mLimitLinePaint.setColor(l.getTextColor());
        mLimitLinePaint.setStrokeWidth(0.5f);
        mLimitLinePaint.setTextSize(l.getTextSize());

        float yOffset = Utils.calcTextHeight(mLimitLinePaint, label) + add / 2f;

        if (l.getLabelPosition() == LimitLine.LimitLabelPosition.POS_RIGHT) {
          c.drawText(
              label, pts[0] + xOffset, mViewPortHandler.contentBottom() - add, mLimitLinePaint);
        } else {
          c.drawText(
              label, pts[0] + xOffset, mViewPortHandler.contentTop() + yOffset, mLimitLinePaint);
        }
      }
    }
  }