Data used to be stored as x,y coordinates in an object and an array of objects was used to store all data points. The data structure was changed to store data in float arrays. Float arrays have the following advantages compared to the previous implementation:
- uses significantly less storage space (reduction of about 3:1)
- should be faster (not sure how much without benchmarking)
- less garbage collection to be done
- less memory fragmentation
- faster to add data points to the existing data
The new structure also changes the way the data storage is allocated for appending data to the existing data. The data arrays will now be 'oversized' when single points are added/appended. The number of values to display in the array will therefore differ from the size. The result is that there might already be space in the array when new values are added, the new value can be added directly without copying all the elements in the array to a newly allocated array of the new size. If there is no space a new array object is created with extra space for future use. Unfortunately these changes are not compatable with the previous implementation. Maybe I can add a convertion constructor?
Made more changes to speedup the graphs with large data sets.
- Derived the graphs from View and not from LinearLayout. Had to change all the views in the class to be part of a singel view as well.
- Improved performance for large datasets by only drawing the graphs if the data are within the current viewport. (This is a huge speedup if the viewport is small compared to the dataset)
- Changed the scroll/pan and zoom functions. The original functions did not work correcly on my 2 test tablets if the graphs were embedded in a scroller (most of the examples if not all are embedded within a scroller)
GraphView is a library for Android to programmatically create flexible and nice-looking diagramms. It is easy to understand, to integrate and to customize it. At the moment there are two different types:
- Line Charts
- Bar Charts
Tested on Android 1.6, 2.2, 2.3 and 3.0 (honeycomb, tablet).
- Two chart types Line Chart and Bar Chart.
- Draw multiple series of data Let the diagram show more that one series in a graph. You can set a color and a description for every series.
- Show legend A legend can be displayed inline the chart. You can set the width and the vertical align (top, middle, bottom).
- Custom labels 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 different frequency.
- Viewport You can limit the viewport so that only a part of the data will be displayed.
- Scrolling You can scroll with a finger touch move gesture.
- Scaling / Zooming Since Android 2.3! With two-fingers touch scale gesture (Multi-touch), the viewport can be changed.
- Background (line graph) Optionally draws a light background under the diagram stroke.
Very simple example:
// init example series data
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
});
GraphView graphView = new LineGraphView(
this // context
, "GraphViewDemo" // heading
);
graphView.addSeries(exampleSeries); // data
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(graphView);

