GWT Formatter wrapper for Google Visualization

The Google Visualization API allows you to create visualization and reporting applications over structured data and helps integrate these directly into your website or on a Gadget. Google also released the Google API library wrappers to use with GWT.

But Visualization's Formatter classes are missing in current SDK. So I have decided to implement those missing classes.

You can download the Jar to use with your GWT application (released with Apache 2.0 license).



You can download the library from here and source code here.

GWT Formatter Demo

Usage

1) In your <module>.gwt.xml file include following Visualization API module along with Google's visualization API:

<inherits name="com.sheelapps.gwt.visualization.Visualization" /> 

2) Formatter in your code :

Using Formatter wrapper class is very easy.

1) create the <Formatter>.Options and set appropriate properties.

2) Create Formatter class <Formatter>.create(op) with options

3) Call <Formatter>.format(<AbstractDataTable>,<column>);

 For example  :

 a)  ArrowFormat :

ArrowFormat.Options op = ArrowFormat.Options.create();
 op.setBase(1000); // optional property
 ArrowFormat formatter = ArrowFormat.create(op);

 b) DateFormat :

DateFormat.Options op  =     DateFormat.Options.create();
 op.setPattern("EEE, MMM d, ''yy");
 DateFormat format = DateFormat.create(op);
format.format(data,1);

 c) ColorFormat :

ColorFormat format = ColorFormat.create();
 format.addRange(1000,2000, "white","yellow");
 format.format(data,1);

d) PatternFormat :

PatternFormat format = PatternFormat.create("<a href=\"mailto:{1}\">{0}</a>");
format.format(data,new int[] {0,1});

 e) NumberFormat :

NumberFormat.Options op  =  NumberFormat.Options.create();
 op.setNegativeParens(true);
 op.setPrefix("$");
 op.setNegativeColor("red");
 NumberFormat format = NumberFormat.create(op);
 format.format(data,1);

f) BarFormat :

BarFormat.Options opt = BarFormat.Options.create();
opt.showValue(false);
opt.drawZeroLine(true);
opt.setColorPositive(BarColor.GREEN);
BarFormat format = BarFormat.create(opt);
format.format(data,1);



May 01, 2009 by Sheel Khanna
Add Comment
blog comments powered by Disqus