Friday, March 22, 2013

Android Graph/charts demo


Chart and Graph Library for Android

GitHub Link


What is GraphView
  • Line Charts
  • Bar Charts

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:
Tested on Android 1.6, 2.2, 2.3 and 3.0 (honeycomb, tablet), 4.0.
Features
  • 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.
  • Manual Y axis limits
  • Realtime Graph (Live)


The mainactivity java class is as follows

package com.jitesh.helographview;

import com.jjoe64.graphview.BarGraphView;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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 BarGraphView(
     this // context
     , "GraphViewDemo" // heading
);
// GraphView graphView = new LineGraphView(
//      this // context
//      , "GraphViewDemo" // heading
// );
graphView.addSeries(exampleSeries); // data

LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(graphView);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

}
activity_main.xml is as below

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" android:id="@+id/layout">
</LinearLayout>

The screen shots are as follows











No comments:

Post a Comment