DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • VPN Architecture for Internal Networks
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  1. DZone
  2. Data Engineering
  3. Data
  4. How to Add Graphs in Android

How to Add Graphs in Android

Learn how to implement the GraphView library to add a variety of customizable graphs to your Android mobile application.

Adam Smith user avatar by
Adam Smith
·
Aug. 07, 17 · Tutorial
Like (7)
Save
Tweet
Share
22.20K Views

Join the DZone community and get the full member experience.

Join For Free

GraphView is a library for Android to programmatically create flexible and nice-looking diagrams. It is easy to understand, integrate, and customize.

Recently we’ve seen some View article like Increment ProductView, OverlayVeiw, Image SlideView, Discreate ScrollView, SwipeView and many more you can get. But today i am going to share a Graph Library for creating zoomable and scrollable line and bar graphs.

Supported graph types:

  • Line Graphs.
  • Bar Graphs.
  • Point Graphs.
  • Or, implement your own custom types.
GraphView - Android Graph Library

Key Features

  • Different plotting types: Line Charts, Bar Charts, and Point Charts can be plotted together as a combination.
  • Draw multiple series of data: Let the diagram show more than one series in a graph. You can set a color and a description for every series.
  • Realtime / Live Chart: Append new data live or reset the whole data.
  • Secondary Scale.
  • Tap Listener: Handle tap events on specific data points.
  • Show legend: A legend can be displayed inline the chart. You can set the width and the vertical alignment (top, middle, bottom).
  • Custom label formatter: The labels for the x- and y-axis are generated automatically. But you can set your own labels, Strings are possible.
  • Handle incomplete data: It’s possible to give the data in a different frequency.
  • Viewport: You can limit the viewport so that only a part of the data will be displayed.
  • Scrolling and Scaling/Zooming: You can scroll with a finger touch move gesture. With a two-fingers touch scale gesture (multi-touch), the viewport can be changed.
  • XML Integration.
  • Optional Axis Titles: Set vertical and horizontal axis titles.
  • Many Styles: Change the color and thickness, label font size/color and more.
  • Very customizable: There are many hooks to use in order to do custom rendering or changing the paint objects.

Implementation of GraphView

Add gradle dependency:

compile 'com.jjoe64:graphview:4.2.1'


Add view to layout:

<com.jjoe64.graphview.GraphView
 android:layout_width="match_parent"
 android:layout_height="200dip"
 android:id="@+id/graph" />


Add some data:

GraphView graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
 new DataPoint(0, 1),
 new DataPoint(1, 5),
 new DataPoint(2, 3),
 new DataPoint(3, 2),
 new DataPoint(4, 6)
});
graph.addSeries(series);


Hope you like this article. Please comment us and share with your friends.

Android (robot) Data (computing)

Opinions expressed by DZone contributors are their own.

Trending

  • VPN Architecture for Internal Networks
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
  • Mastering Time Series Analysis: Techniques, Models, and Strategies

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: