예제 #1
0
  private void addData() {
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

    for (int i = 0; i < yData.length; i++) yVals1.add(new BarEntry(yData[i], i));

    ArrayList<String> xVals = new ArrayList<String>();

    for (int i = 0; i < xData.length; i++) xVals.add(xData[i]);

    // create pie data set
    BarDataSet dataSet = new BarDataSet(yVals1, "Stock");
    //	dataSet.setSliceSpace(5);
    //	dataSet.setSelectionShift(5);

    // add many colors
    ArrayList<Integer> colors = new ArrayList<Integer>();
    colors.add(Color.rgb(0, 204, 68));
    colors.add(Color.rgb(230, 0, 0));

    dataSet.setColors(colors);

    // instantiate pie data object
    BarData data = new BarData(xVals, dataSet);

    data.setValueTextSize(16);
    data.setValueTextColor(Color.BLACK);

    mChart.setData(data);

    // undo highlights
    mChart.highlightValue(null);

    // update pie chart
    mChart.invalidate();
  }
  private void refreshWeekBeforeSteps(
      DBHandler db, BarLineChartBase barChart, Calendar day, GBDevice device) {

    ActivityAnalysis analysis = new ActivityAnalysis();

    day = (Calendar) day.clone(); // do not modify the caller's argument
    day.add(Calendar.DATE, -7);
    List<BarEntry> entries = new ArrayList<>();
    List<String> labels = new ArrayList<>();

    for (int counter = 0; counter < 7; counter++) {
      entries.add(
          new BarEntry(analysis.calculateTotalSteps(getSamplesOfDay(db, day, device)), counter));
      labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
      day.add(Calendar.DATE, 1);
    }

    BarDataSet set = new BarDataSet(entries, "");
    set.setColor(akActivity.color);

    BarData data = new BarData(labels, set);
    data.setValueTextColor(
        Color
            .GRAY); // prevent tearing other graph elements with the black text. Another approach
                    // would be to hide the values cmpletely with data.setDrawValues(false);

    LimitLine target = new LimitLine(mTargetSteps);
    barChart.getAxisLeft().getLimitLines().clear();
    barChart.getAxisLeft().addLimitLine(target);

    setupLegend(barChart);
    barChart.setData(data);
    barChart.getLegend().setEnabled(false);
  }