0

How to refresh graph dynamic?

  • Init Chart.

        final LineData mLineData = mChart.getData();
    
        final ILineDataSet[] xSet = {mLineData.getDataSetByIndex(0)};
    
        final int xSetArrayItem = 0;
    
        if (xSet[xSetArrayItem] == null) {
            xSet[xSetArrayItem] = createSet("Ecg", getResources().getColor(android.R.color.holo_red_dark));
            mLineData.addDataSet(xSet[xSetArrayItem]);
        }
    
  • After this I'm doing subscribe for real data and putting it into graph.

    mLineData.addEntry(new Entry(xValue++, ecgModel.getBody().getData()[i]), 0);
    
    mLineData.notifyDataChanged();
    
    // let the chart know it's data has changed
       mChart.notifyDataSetChanged();
    // limit the number of visible entries
       mChart.setVisibleXRangeMaximum(200);
    // move to the latest entry
      mChart.moveViewToX(xValue);
    
  • And Problem is I don't want to scroll X Axis. I want to put for example 400 inputs clear graph and let chart draw new 400 inputs.

Something like this:

       if (xValue == 400) {
           xValue = 0;
           mLineData.clearValues();
           mChart.invalidate();
         }

- But this clearing graph but then nothing is draw on chart.

Esperanz0
  • 1,524
  • 13
  • 35

1 Answers1

0

try this,

yVals.clear();
xLabel.clear();
set = new BarDataSet(yVals, "");
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add(set);
data = new BarData(dataSets);
ArrayList<Float> count = reportPojo.getCounts();
for (int i = 0; i < count.size(); i++) {
    float val = count.get(i);
    yVals.add(new BarEntry(i, val));
}
for (String label : reportPojo.getLabels()) {
    xLabel.add(label);
}
chart.setData(data);
set.notifyDataSetChanged();
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
chart.invalidate();
return set;
Twinkle
  • 37
  • 11
g7pro
  • 817
  • 1
  • 6
  • 11
  • And where is dynamic refresh here? You are drawing chart after data is ready. – Esperanz0 May 10 '18 at 15:55
  • i too couldn't find a way so i used this instead notifying this chart is crashing mine also i was using in a recycler view. – g7pro May 10 '18 at 16:09