Alles fängt mit http://jquery.com/ an. Darauf baut auf http://code.google.com/p/flot/, eine JavaScript-Bib. für Chars:
- Basic example
- Different graph types and setting various options
- Turning series on/off
- Selection support and zooming and zooming with overview
- Plotting time series and visitors per day with zooming and weekends
- Dual axis support
- Interacting with the data
http://code.google.com/p/gflot/ ist nun der GWT-Aufsatz auf flot.
Für eine Bar-Diagramm ist nur folgender Quellcode nötig:
final String[] MONTH_NAMES = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };
PlotModel model = new PlotModel();
PlotOptions plotOptions = new PlotOptions();
BarSeriesOptions barSeriesOptions = new BarSeriesOptions();
barSeriesOptions.setShow(true);
barSeriesOptions.setLineWidth(1);
barSeriesOptions.setBarWidth(1);
barSeriesOptions.setAlignment(BarAlignment.CENTER);
plotOptions.setDefaultBarsSeriesOptions(barSeriesOptions);
plotOptions.setLegendOptions(new LegendOptions().setShow(false));
// add tick formatter to the options
plotOptions.setXAxisOptions(new AxisOptions().setTicks(12).setTickFormatter(new TickFormatter() {
public String formatTickValue(double tickValue, Axis axis) {
if (tickValue > 0 && tickValue <= 12) {
return MONTH_NAMES[(int) (tickValue - 1)];
}
return "";
}
}));
// create a series
SeriesHandler handler = model.addSeries("Ottawa's Month Temperatures (Daily Average in °C)", "blue");
// add data
handler.add(new DataPoint(1, -10.5));
handler.add(new DataPoint(2, -8.6));
handler.add(new DataPoint(3, -2.4));
handler.add(new DataPoint(4, 6));
handler.add(new DataPoint(5, 13.6));
handler.add(new DataPoint(6, 18.4));
handler.add(new DataPoint(7, 21));
handler.add(new DataPoint(8, 19.7));
handler.add(new DataPoint(9, 14.7));
handler.add(new DataPoint(10, 8.2));
handler.add(new DataPoint(11, 1.5));
handler.add(new DataPoint(12, -6.6));
// create the plot
SimplePlot plot = new SimplePlot(model, plotOptions);
// put it on a panel
FlowPanel panel = new FlowPanel();
panel.add(plot);
return panel;
Eine Alternative dazu ist http://code.google.com/p/charts4j/ bzw. http://code.google.com/p/charts4j/wiki/GWT_Port.