rohitranjan
rohitranjan

Reputation: 23

adding dynamic data to MPAndroidChart

Can anyone explain with a simple example on how to add the data dynamically to the chart which is already drawn. I tried with the details in the github link to add the data, but couldn't do so. A very short example or link is also fine. Thanks

Upvotes: 0

Views: 3728

Answers (1)

rafaelasguerra
rafaelasguerra

Reputation: 2555

You can download the project here https://github.com/PhilJay/MPAndroidChart/archive/master.zip Open the project, and in MPChartExample, you have the file DynamicalAddingActivity.java.

  1. You need to create the chart:
  2. Add dataSet (your line(s)) with the values (please view the example in addDataSet() method in MPChartExample project).
  3. After you can do a CountTimerDown that add a new Entry, for the dataset.
/** each 5 seconds **/
new CountDownTimer(5000, 1000) {

     public void onTick(long millisUntilFinished) {
     }

     public void onFinish() {
        double randomValue = 19.0 + (Math.random() * (21.0 - 19.0)); 
        int indexOfMyLine = 0;

        Entry newEntry = new Entry((float) randomValue, indexOfMyLine); 
     }

}.start();

Upvotes: 1

Related Questions