Android
Plot

Modified

Resources

http://androidplot.com/wiki/Quickstart - Instructions for use with Eclipse.

http://androidplot.com - Home.

Overview

AndroidPlot is a pure Java API for creating dynamic and static charts within Android application. The AndroidPlot developer library is compatible with virtually all versions of Android.

AndroidPlot currently supports the following types of charts:

Android Plot Example

Download

 

AndroidPlotExample.java
package edu.ius.rwisman.AndroidPlotExample;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.series.XYSeries;
import com.androidplot.xy.*;
 import java.text.DecimalFormat;
import java.util.Arrays;
 
public class AndroidPlotExampleActivity extends Activity {
 
    private XYPlot mySimpleXYPlot;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        											// Initialize our XYPlot reference:
        mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
        											// Create two arrays of y-values to plot:
        Number[] series1Numbers = {1, 8, 5, 2, 7, 4};
        Number[] series2Numbers = {4, 6, 3, 8, 2, 10}; 
        											// Turn the above arrays into XYSeries:
        XYSeries series1 = new SimpleXYSeries(
                Arrays.asList(series1Numbers),          					// Turn array to List for SimpleXYSeries  
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, 				// Y_VALS_ONLY: use element index as x value
                "Series1");                             						// Set the display title of the series
        											// Same as above, for series2
        XYSeries series2 = new SimpleXYSeries(
	      Arrays.asList(series2Numbers), 
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, 
                "Series2");
        											// Formatter draws series using LineAndPointRenderer:
        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0),                   					// line color
                Color.rgb(0, 100, 0),                   					// point color
                Color.rgb(150, 190, 150));              					// fill color (optional)
 	       										// Add series1 to the xyplot:
        mySimpleXYPlot.addSeries(series1, series1Format); 
        											// Same as above, with series2:
        mySimpleXYPlot.addSeries(series2, new LineAndPointFormatter(
	     Color.rgb(0, 0, 200), 
	     Color.rgb(0, 0, 100),
                Color.rgb(150, 150, 190)));
        											// Reduce the number of range labels
        mySimpleXYPlot.setTicksPerRangeLabel(3); 
        											// AndroidPlot displays developer guides to aid in plot layout
        											// To get rid of them call disableAllMarkup():
        mySimpleXYPlot.disableAllMarkup();
    }
}

main.xml supplies the plot area parameters.

main.xml
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 
    <com.androidplot.xy.XYPlot
    android:id="@+id/mySimpleXYPlot"
    android:layout_width="fill_parent"
    android:layout_height="200px"
    android:layout_marginTop="10px"
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    title="A Simple XYPlot Example"/>
</LinearLayout>