Open In App
Related Articles

Point Graph Series in Android

Improve Article
Save Article
Like Article

We have seen using a simple line graph and BarChart implementation in Android to represent data in the graphical format. Another graphical format for representing data is a point graph series. In this article, we will take a look at the implementation of the Point Graph Series in Android. 

What we are going to build in this article? 

We will be building a simple application in which we will be displaying sample data in a point graph view in Android. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency to build.gradle(Module:app)

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.    

implementation ‘com.jjoe64:graphview:4.2.2’

After adding the above dependency now sync your project and we will now move towards the implementation of our GraphView.  

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
    <!--graph view to display our graph-->
        android:layout_height="match_parent" />

Step 4: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.PointsGraphSeries;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // initializing our variable for graph view.
        GraphView graphView = findViewById(;
        // on below line we are creating a new data
        // point series for our point graph series.
        // we are calling get data point method to add 
        // data point to our point graph series.
        PointsGraphSeries<DataPoint> series = new PointsGraphSeries<>(getDataPoint());
        // below line is to add series
        // to our graph view.
        // below line is to activate
        // horizontal scrolling.
        // below line is to activate horizontal 
        // zooming and scrolling.
        // below line is to activate vertical and 
        // horizontal zoom with scrolling.
        // below line is to activate vertical scrolling.
        // below line is to set shape 
        // for the point of graph view.
        // below line is to set 
        // the size of our shape.
        // below line is to add color 
        // to our shape of graph view.
    private DataPoint[] getDataPoint() {
        // creating a variable for data point.
        DataPoint[] dataPoints = new DataPoint[]
                        // on below line we are adding a new
                        // data point to our Data Point class.
                        new DataPoint(0, 1),
                        new DataPoint(1, 2),
                        new DataPoint(2, 3),
                        new DataPoint(3, 5),
                        new DataPoint(4, 1),
                        new DataPoint(4, 3),
                        new DataPoint(5, 3),
                        new DataPoint(6, 2)
        // at last we are returning
        // the data point class.
        return dataPoints;

Now run your app and see the output of the app.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 04 Feb, 2021
Like Article
Save Article
Similar Reads
Complete Tutorials