0

I am using GraphView I need to display the graph points concurrently as real time. But problem is, it's displaying the graph as completely. But my requirement is, it should plot the graph concurrently.

As per the suggested one, I modified based on my requirement but it's not displaying as real time graph plot.

public class MainActivity extends AppCompatActivity {
    private LineGraphSeries<DataPoint> mSeries1;
    private Runnable mTimer1;
    private final Handler mHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GraphView graph = (GraphView) findViewById(R.id.graph);
        mSeries1 = new LineGraphSeries<>(generateData());
        graph.addSeries(mSeries1);
    }

    private DataPoint[] generateData() {
       DataPoint[] dataPoint= new DataPoint[]{
               new DataPoint(0, 1),
               new DataPoint(1, 5),
               new DataPoint(2, 4),
               new DataPoint(3, 6),
               new DataPoint(4, 8),
               new DataPoint(5, 10),
       };
       return dataPoint;
    }

    @Override
    protected void onResume() {
        super.onResume();
        mTimer1 = new Runnable() {
            @Override
            public void run() {
                mSeries1.resetData(generateData());
                mHandler.postDelayed(this, 300);
            }
        };
        mHandler.postDelayed(mTimer1, 300);
    }
    @Override
    public void onPause() {
        mHandler.removeCallbacks(mTimer1);
        super.onPause();
    }
}

in Xml:

<com.jjoe64.graphview.GraphView
    android:layout_width="match_parent"
    android:layout_height="200dip"
    android:id="@+id/graph" />
Shadow
  • 6,864
  • 6
  • 44
  • 93
  • 1
    does this https://proandroiddev.com/android-bring-life-to-your-custom-view-8604ab3967b3 help although its not graphview – Raghunandan May 31 '18 at 04:47

2 Answers2

0

https://github.com/PhilJay/MPAndroidChart

Use this library for Graphs. It has animation.

Parth Suthar
  • 123
  • 4
0

Be sure to include the following method so that your graph scrolls to the end each time new data is added.

appendData

public void appendData(E dataPoint,
                       boolean scrollToEnd,
                       int maxDataPoints)

Parameters:

dataPoint - values the values must be in the correct order! x-value has to be ASC. First the lowest x value and at least the highest x value.

scrollToEnd - true => graphview will scroll to the end (maxX)

maxDataPoints - if max data count is reached, the oldest data value will be lost to avoid memory leaks

Jantzilla
  • 638
  • 1
  • 7
  • 19