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);
  }
Пример #2
0
  @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();
  }
Пример #3
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);
 }
Пример #4
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    DateFormat df =
        new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); // défini un nouveau format de date en string
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.fragment_statistics_linechart, container, false);

    LineChart chart = (LineChart) rootView.findViewById(R.id.firstChart);
    chart.setLogEnabled(true);
    chart.setNoDataTextDescription(getString(R.string.no_data));

    ArrayList<DrinkIncome> incomesByDrink = getIncomes();

    ArrayList<Entry> Income1 =
        new ArrayList<Entry>(); // creation d'un arrayList d'entrées pour le tableau
    ArrayList<Entry[]> drink2 = new ArrayList<Entry[]>();
    ArrayList<Entry> drink3 = new ArrayList<Entry>();
    ArrayList<Entry> drink4 = new ArrayList<Entry>();
    ArrayList<Entry> drink5 = new ArrayList<Entry>();
    ArrayList<String> xVals =
        new ArrayList<String>(); // creation d'une arrayList pour les valeurs des abscisses

    Iterator<DrinkIncome> it = incomesByDrink.iterator();
    for (int i = 0; it.hasNext() && i < 5; i++) {
      DrinkIncome s = it.next();
      Entry element = new Entry(s.getIncome(), i);
      Income1.add(element);
      // xVals.add(df.format(s.getDateOrder()));
      xVals.add("J-" + i);
    }

    LineDataSet setBestDrinks = new LineDataSet(Income1, getString(R.string.daily_incomes));
    setBestDrinks.setDrawFilled(true);
    setBestDrinks.setColors(
        new int[] {R.color.blue1, R.color.blue2, R.color.blue3, R.color.blue1},
        rootView.getContext());

    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(setBestDrinks);

    LineData data = new LineData(xVals, dataSets);
    chart.setData(data);

    return rootView;
  }