package com.googlecode.gchart.gchartdemoapp.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; /* * Loads the five charts of GChart's live demo into a table * in the host page.
* * Contains the EntryPoint class plus all the boilerplate * GChart requires to take advantage of the cross-browser * canvas provided by the gwt-incubator's GWTCanvas class. *
* * If you are using GWTCanvas, you can just paste the entire static * section below into your own EntryPoint class. *
* * We don't include this boilerplate in GChart to insulate GChart from * changes in GWTCanvas (it's still evolving), to allow you to use a * different GWT canvas Widget if you like, and to make it possible for * you to grok the boilerplate to access features of GWTCanvas we don't * explicitly support in GChart. For example, the default * GWTCanvas.MITER line join setting is replaced below with * GWTCanvas.ROUND because, with the default, * small pie slices tend to jut out at acute angles into the * opposing slices otherwise. But other options for eliminating such * overly pointy-edged slices are available, such as * setLineJoin(GWTCanvas.BEVEL); or setMiterLimit(2);. * * */ //<<1 // Required imports: import com.googlecode.gchart.client.GChart; import com.googlecode.gchart.client.GChartCanvasFactory; import com.googlecode.gchart.client.GChartCanvasLite; import com.google.gwt.widgetideas.graphics.client.Color; import com.google.gwt.widgetideas.graphics.client.GWTCanvas; //>>1 public class GChartDemoApp implements EntryPoint { //<<2 // Paste these lines into the top-level GWT class that kicks off your // application (the one that "implements EntryPoint"): static { final class GWTCanvasBasedCanvasLite extends GWTCanvas implements GChartCanvasLite { // GChartCanvasLite requires CSS/RGBA color strings, but // GWTCanvas uses its own Color class instead, so we wrap: public void setStrokeStyle(String cssColor) { // Sharp angles of default MITER can overwrite adjacent pie slices setLineJoin(GWTCanvas.ROUND); setStrokeStyle(new Color(cssColor)); } public void setFillStyle(String cssColor) { setFillStyle(new Color(cssColor)); } // Note: all other GChartCanvasLite methods (lineTo, moveTo, // arc, etc.) are directly inherited from GWTCanvas, so no // wrapper methods are needed. } final class GWTCanvasBasedCanvasFactory implements GChartCanvasFactory { public GChartCanvasLite create() { GChartCanvasLite result = new GWTCanvasBasedCanvasLite(); return result; } } // This line "teaches" GChart how to create the canvas // widgets it needs to render any continuous, // non-rectangular, chart aspects (solid fill pie slices, // continously connected lines, etc.) clearly and // efficiently. It's generally best to do this exactly once, // when your entire GWT application loads. GChart.setCanvasFactory(new GWTCanvasBasedCanvasFactory()); } // end of static { //>>2 // stuff charts into the cells of an ordinary table in the host page public void onModuleLoad() { RootPanel.get("leftTopCell").add( new GChartExample11()); RootPanel.get("rightTopCell").add( new GChartExample02()); RootPanel.get("leftBottomCell").add( new GChartExample20()); RootPanel.get("middleBottomCell").add( new GChartExample22a()); RootPanel.get("rightBottomCell").add( new GChartExample17()); RootPanel.get("loadingMessage").setVisible(false); } }