Skip to main content

Draw line graphs with AchartEngine in Android

AchartEngine provides an easy way of drawing both line and bar graphs in android platform. In here I describe drawing line graphs. 

First need to add AchartEngine jar file to your android project. You can download it from here.
If it is maven based project you can add the dependency and all details are in here.
After you download the jar, add it into the libs folder and right click on the jar and Select Build the path as Figure 1 follows.

Figure 1 - Configure Build Path

If it is a maven based project, simply you have to build the project, will be downloaded the jar file to your project.

Figure 2 - Graph class
In above java class, you can refer easily to understand AchartEngine line graphs implementation. In here, used two pre-defined arrays as X and Y. 

Then add those values to TimeSeries which is names as “Line1” 
Then you need to add this TimeSeries to XYMultipleSeriesDataset, then that dataset should add to the XYSeriesRender

That renderer is responsible to draw the graph. So it contains features to customize the graph like setColor, setPointStyle etc. 
So you need add that renderer to XYMultipleSeriesRenderer. Like that you can add so many graphs(renderers) to XYMultipleSeriesRenderer. It defines a graph uniquely. 
So it contains several features to customize each graph uniquely. It has setChartTitle, setYTitle, setXTitle etc. 
Then you need to add XYMultipleSeriesRenderer to the Intent through ChartFactory which is a pre-defined class in AchartEngine.

You have to add an Activity called Graphical Activity in AchartEngine to the Manifest as well.

Figure 3 - Android Manifest






That’s what you all have to do then you can call the DrawGraph intent.
Figure 4 - Start the activity
 If you follow these steps properly, you will see the graph and here is the screenshot for above graph.

Figure 5 - Screen shot of the graph
You can get this full code from here. It also contains a code to draw a dynamic line graph. You can also refer on that too. Hope you enjoy this.


Comments

Popular posts from this blog

IbirdsPro – Identify birds in Sri Lanka via their colours

This application for nature lovers especially who interested in birds. This is recommended for anyone to improve the knowledge about birds even for beginners. Users can use this application in anywhere because this application doesn’t need any internet connection. This is the upgraded version of the application - Ibirds which is capable to identify forest birds in Sri Lanka. There are more enhanced features in the application. 3 detailed sketches with including 8 parts. (bill, head, face, neck, feathers, breast, tail, legs) High efficient colour matching algorithm Optimized for both android phones and tablets. Contain a large database about the birds. This is the list of birds containing in three sections in IBirdsPro 1.0 version. Section 1     Crimson-fronted Barbet Brown-headed Barbet Yellow-fronted Barbet Brown-capped Woodpacker Yellow-crowned Woodpecker Lesser Yellownape Streak-throated Woodpecker Rufous Woodpecker Black-rumped Flameback Great...

Spatial Data Processing Library for Stratosphere

Stratophere is big data analysis platform which implements through parallel programming concepts. Stratosphere's programming model provides six parallelizable operator functions Map Reduce Join  Cross CoGroup Union JTS library is a standard java library to perform geographical analysis with special data types like points, paths, polygons. In this spatial data processing library, we are going to implement various geographical analysis such as intersections, joins with big map data in standard formats like OSM(Open Street Map) There is some effort in here to create new data types in stratosphere which is compatible with JTS library. Here is an example to Stratosphere Java API with WordCount example. You can simply download the stratosphere-examples and check it your own. When you need to familiar with stratosphere, there is exercises in bigdataclass website. You can find out those implemented exercises in java. Word Count examp...

Setting environment variables in ubuntu

Ubuntu has a nice way to configure most of the important softwares (java,sbt,scala,....etc) without installing through ubuntu software centre- sudo apt-get install ….... You only have to do is, download that files folder and put it that folder wherever you like and set environment variables. That's all.  Java Configuration  Go to this url  http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html   Download  jdk-7u45-linux-x64.tar.gz  Move that file where you want to store.  In here I've created a directory named 'hms' in my home folder and in hms there is a directory called 'installs' (path = /home/shashika/hms/installs )  Then go to your directory and extract the jdk-7u45-linux-x64.tar.gz file Then you can see the extracted file Now the important part. That is set the jdk/bin path in bashrc file which is in your home folder.  If you can see it in your home folder press ctrl-h then you ...