1

Looking at other examples, I see that the chart needs all the data sets at once and you cannot add them iteratively once they are ready. Am I wrong?

ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
...
dataSets.add(d1);
dataSets.add(d2);
...
LineData data = new LineData(dataSets);
mChart.setData(data);

My problem is that I hold the necessary data for the multiple LineDataSet in a database and access them through LiveData. To draw a single LineDataSet would be simple because I would write the logic of this inside stuff.observe{}.

stuff.observe(this, goodStuff -> {
    Data data = generateData(goodStuff);
    mChart.setData(data);
});

But now I have to observe multiple stuff and then set the data of multiple stuff to the chart. How to achieve this?

adriennoir
  • 1,329
  • 1
  • 15
  • 29

1 Answers1

3

Yes, you can add data Dynamically/Real time, just keep in mind that you also need to notify your chart about data in your observer,

stuff.observe(this, goodStuff -> {
    Data data = generateData(goodStuff);
    mChart.setData(data);
    mChart.notifyDataSetChanged(); // let the chart know it's data changed
    mChart.invalidate(); // refresh chart
});

Check more info from here

Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
  • I have multiple stuff to observe and the results of each stuff should go into an array of ILineDataSet before setting the data. But I guess it's fine. I'll create a LineData member in my class and add to it in each .observe, then notify and invalidate. – adriennoir Sep 28 '18 at 10:15