We try to keep these pages as up to date as possible, but typos are inevitable, especially immediately following new releases. If you spot an error, please let us know either in the forums or shoot an email to oops@androidplot.com. Thanks!

Last Updated For: Androidplot 0.6.0


This tutorial will show you how to display two series of data in an XYPlot.  You can view this sample on your own device or emulator by installing the DemoApp on your device and clicking on the Simple XY Plot Example.  Full source code for the DemoApp is also available for online browsing and for download here.

Step 1: Create the project

The first thing you’ll need is to get a project setup.  There are a couple ways to go about this.

With an IDE

Obviously how this is done depends on which IDE (if any) that you use.  Google does have some pretty good documentation on the process. If you don’t currently use an IDE but would like to, we suggest IntelliJ IDEA, Android Studio or Eclipse with ADT. These links should get you started:

With Maven

Maven users can generate an Androidplot project from scratch by following these instructions.

Using the Android SDK

You’ll obviously need the Android SDK installed to do this.  Assuming that <android-sdk-dir>/tools is on your PATH, run this from a command line:

For more detailed instructions see the official Google documentation.

Step 2: Add the AndroidPlot library to the project

Download the latest version of the AndroidPlot Core Library and copy it to your /libs directory.  Maven Quickstart users can skip this step.  IDE users may also need to add the library to your classpath.

Or if you’re using Gradle, simply add a compile dependency:

Beginning with Androidplot 0.6.2 and later, the library is also available in .aar format.  Until 0.6.2 is officially released you’ll need to put the core library .aar into your /libs directory and modify your Gradle build script to use /libs as a maven repo:

And then add the dependency:

Step 3: Add an XYPlot Element to the xml layout

Once you’ve got the project skeleton created, it’s time to edit res/layout/simple_xy_plot_example.xml and add an XYPlot view.  By default this file is usually named main.xml.  If it is, go ahead and rename it.


You’ve no doubt noticed there’s quite a bit of stuff here.  Any parameter starting with “androidPlot” above is essentially styling fluff and can be safely ignored for the duration of this tutorial.  For the curious, these values are passed to the Configurator for processing upon Activity startup.

You’ll also notice a few items starting with “@dimen” – these are dimensions specified in another XML file:


Step 4: Create the Activity

The example below uses com.androidplot.demos as it’s package – change this to whatever package you used when you created your project in step 1.

Let’s look at an example Activity that displays the XYPlot graphic shown above.  The basic steps to follow are:

  1. Create an instance of Series and populate it with data to be displayed.
  2. Register the series with the Plot along with a Formatter to describing how the data should be styled.
  3. Draw the Plot

In our case, since we are working with XY data, we’ll be using an XYPlot, a SimpleXYSeries (which is an implementation of the XYSeries interface) and a LineAndPointFormatter:




For the most part everything is pretty straightforward.  One potentially confusing section of the code above is LineAndPointFormatter and the usage of configure(…).  This is actually more Configurator magic.  While it is possible and completely acceptable to programmatically create and configure Formatter instances (such as LineAndPointFormatter) this practice leads to a brittle visual experience.  Never the less for the sake of brevity, one could replace the code:


and get a similar effect.  For more details on how to programmatically configure Formatters etc. consult the latest Javadoc for details on available constructors, setters, getters, etc.

What’s Next?

Now that you know the basics you’re ready to start plotting dynamic data.