Exemplo n.º 1
0
  private void addEntry() {
    LineData data = mChart.getData();
    int year = 2015;

    if (data != null) {

      LineDataSet set = data.getDataSetByIndex(0);

      if (set == null) {
        set = createSet();
        data.addDataSet(set);
      }

      //            data.addXValue(mMonths[data.getXValCount() % 12] + " " + (year +
      // data.getXValCount() /12));

      //            data.addEntry(new Entry((float) (Math.random() * 40) + 30f, set.getEntryCount(),
      // 0));

      mChart.notifyDataSetChanged();

      mChart.setVisibleXRangeMaximum(120);
      mChart.moveViewToX(data.getXValCount() - 121);
    }
  }
Exemplo n.º 2
0
  /**
   * Refreshs a chart.
   *
   * @param chart
   * @param chartDataSets
   */
  public void refreshChart(LineChart chart, ArrayList<LineDataSet> chartDataSets) {
    // Populates X List.
    // Identifies the biggets dataset.
    int maxSize = 0;
    for (LineDataSet dataSet : chartDataSets)
      if (dataSet.getEntryCount() > maxSize) maxSize = dataSet.getEntryCount();

    ArrayList<String> xVals = new ArrayList<String>();
    while (xVals.size() < maxSize) xVals.add((xVals.size() + 1) + "");

    LineData chartData = new LineData(xVals, chartDataSets);
    chart.setData(chartData);
    chart.notifyDataSetChanged();
    chart.invalidate();
  }
Exemplo n.º 3
0
  private void addEntry() {
    LineData data = mLineChart.getData();
    if (data != null) {
      LineDataSet set = data.getDataSetByIndex(0);
      if (set == null) {
        set = createSet();
        data.addDataSet(set);
      }
      // add a new random value
      float a = r.nextFloat() * (2.00f + 2.00f) - 2.0f;
      System.out.println(a);
      data.addXValue("");
      data.addEntry(new Entry(a, set.getEntryCount()), 0);

      mLineChart.notifyDataSetChanged();

      mLineChart.setVisibleXRange(6, 0);

      mLineChart.moveViewToX(data.getXValCount() - 7);
    }
  }