/** Add the data of a specific signal type of a specific point to chart. */
  public void refreshChartOfSignal(MapPoint p, String signalTypeId) {
    LineChart chart = getChart(signalTypeId);
    ArrayList<LineDataSet> currentChartDataSets = new ArrayList<LineDataSet>();

    for (SignalDataSet ds : p.getDataSetsOfSignal(signalTypeId)) {
      // Log.i("NewPointActivity", "addToGraph ("+p+"): "+signalTypeId+",
      // "+ds.getSignalSourceId()+", "+ds.getDate()+", "+ds.size());

      LineDataSet chartDataSet = createChartDataSet(ds.getSignalSourceId(), ds.getDate());

      for (SignalSample s : ds.getSamples()) {
        if (s == null) {
          // @todo Each dataset must have its own null value.
          // Here the null value is fixed -150f.
          chartDataSet.addEntry(new Entry(-150f, chartDataSet.getEntryCount()));
        } else {
          // Add the sample to chart line.
          DoubleSignalSample doubleSignalSample = (DoubleSignalSample) s;
          chartDataSet.addEntry(
              new Entry(doubleSignalSample.getValue().floatValue(), chartDataSet.getEntryCount()));
        }
      }

      // Add the line to chart.
      currentChartDataSets.add(chartDataSet);

      // Updates table.
      updateDataTable(ds);
    }

    refreshChart(chart, currentChartDataSets);
  }
  /**
   * 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();
  }
Beispiel #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);
    }
  }