Using AndroidPlot to display charts and graphs in your Android application.
Problem:Depicting data graphically in an Android application.
Solution:There are many 3rd party graph libraries for Android available. In this example we make use of AndroidPlot library (open source) to depict a simple graph.
Discussion:Step 1: Download AndroidPlot library from here: http://androidplot.com/wiki/Download (any version).
Step 2: Create a new Android project and add the AndroidPlot library to the new project. To do this, create a new folder in the project folder by the name 'lib'. To this folder add the downloaded AndroidPlot jar file (named something like this: 'Androidplot-core-0.4a-release.jar'). (At this stage you should be having directories like src, res, gen, lib.)
Step 3: To use the library, it must be added to the build path. For this, in Eclipse, right click the .jar you added and select the "Build Path -- Add to Build Path" option. This will show another directory called 'Referenced Libraries' in the Eclipse project.
Step 4: In our sample application, we are hard-coding some data and showing the plot corresponding to the data in the application. So, we require to add an XY plot to our XML layout (main.xml). Here's what main.xml looks like with a XYPlot component in a linear layout:
Step 5: Get a reference to the XYplot defined in the XML.
Step 6: Initialize two arrays of numbers for which the plot will be displayed.
Step 7: Turn the above arrays into XYSeries:
Step 8: Create a formatter to use for drawing a series using LineAndPointRenderer:
Step 9: Add series1 and series2 to the xyplot:
Step 10: Make it look cleaner:
Step 11: Run the application! This is how it looks:
Downloads:(not handled yet)