shawnjohnson159

Members
  • Content count

    1
  • Joined

  • Last visited

Everything posted by shawnjohnson159

  1. Solution for GWT and FusionCharts

    I was able to make this work, but I had to change it some to suite my needs. I wanted to control the DIV name where the chart was rendered as well as the name of the chart object itself - so I added arguments for those values. Also I was using the Pie3d and Grid, so I added those in too. I added FusionCharts.js as an included resource in my GWT module definition. ------------------------------------------------------------------------------------------- Java Script Object (wrapper) ------------------------------------------------------------------------------------------- import com.google.gwt.core.client.JavaScriptObject; public final class FusionChartJS extends JavaScriptObject { protected FusionChartJS( ) { } public static native FusionChartJS getCylinderInstance( String div, String width, String height ) /*-{ var chart = new $wnd.FusionCharts( "fusioncharts/Cylinder.swf", div, width, height, "0", "0" ); return chart; }-*/; public static native FusionChartJS getPie3dInstance( String div, String width, String height ) /*-{ var chart = new $wnd.FusionCharts( "fusioncharts/Pie3D.swf", div, width, height, "0", "0" ); return chart; }-*/; public static native FusionChartJS getGridInstance( String div, String width, String height ) /*-{ var chart = new $wnd.FusionCharts( "fusioncharts/SSGrid.swf", div, width, height, "0", "0" ); return chart; }-*/; public static native FusionChartJS getInstance( String chartSwf, String div, String width, String height ) /*-{ var chart = new $wnd.FusionCharts( chartSwf, div, width, height, "0", "0" ); return chart; }-*/; public native void setDataUrl( String url ) /*-{ this.setDataURL( url ); }-*/; public native void addParam( String name, String value ) /*-{ this.addParam( name, value ); }-*/; public native void addVariable( String name, String value ) /*-{ this.addVariable( name, value ); }-*/; public native void setTransparent( boolean b ) /*-{ this.setTransparent( b ); }-*/; public native void render( String divId ) /*-{ this.render( divId ); }-*/; } ------------------------------------------------------------------------------------------- Widget ------------------------------------------------------------------------------------------- import java.util.ArrayList; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; public class FusionChartWidget extends Composite { public final static int TYPE_CYLINDER = 1; public final static int TYPE_PIE3D = 2; public final static int TYPE_GRID = 3; // default chart type private int chartType = TYPE_PIE3D; // simple panel to hold the chart private SimplePanel panel = null; private int width = 0; private int height = 0; private String dataUrl = null; private String containerDivId ; private String chartDivId; private ArrayList chartVariables = null; private boolean isTransparent; private class LabelValue { String label = null; String value = null; /* * @param label * @param value */ LabelValue(String l, String v) { label = l; value = v; } public String getLabel() { return label; } public String getValue() { return value; } } /* * @param chartType - Type of fusionchart to create * @param containerDivId - ID of the DIV that contains the chart * @param chartDivId - ID of the OBJECT or EMBED object to render the Flash chart * @param width width of object in pixels * @param height height of object in pixels */ public FusionChartWidget( int chartType, String containerDivId, String chartDivId, int width, int height ) { this.chartType = chartType; this.width = width; this.height = height; this.containerDivId = containerDivId; this.chartDivId = chartDivId; // initialize array this.chartVariables = new ArrayList(); // this simple panel holds the Flash OBJECT/EMBED object panel = new SimplePanel(); panel.getElement().setId(containerDivId); initWidget( panel ); } public void setDataUrl( String dataUrl ) { this.dataUrl = dataUrl; } public void addVariable( String label, String value ) { this.chartVariables.add( ( new LabelValue( label, value) ) ); } public void setTransparent( boolean b ) { this.isTransparent = b; } protected void initWidget( Widget widget ) { super.initWidget( widget ); } protected void onAttach( ) { super.onAttach(); FusionChartJS chart = null; switch ( chartType ) { case TYPE_CYLINDER: chart = FusionChartJS.getCylinderInstance( this.chartDivId, Integer.toString( width ), Integer.toString( height ) ); break; case TYPE_PIE3D: chart = FusionChartJS.getPie3dInstance( this.chartDivId, Integer.toString( width ), Integer.toString( height ) ); break; case TYPE_GRID: chart = FusionChartJS.getGridInstance( this.chartDivId, Integer.toString( width ), Integer.toString( height ) ); break; } chart.setDataUrl( dataUrl ); chart.setTransparent( isTransparent ); // pass all variables for(int i=0; i chart.addVariable(chartVariables.get(i).label, chartVariables.get(i).value); } chart.render( this.containerDivId ); } } ------------------------------------------------------------------------------------------- Sample Call ------------------------------------------------------------------------------------------- FusionChartWidget myGrid = new FusionChartWidget( FusionChartWidget.TYPE_GRID, "gridHolder", "myGrid", 244, 105 ); myGrid.setDataUrl("chartdata/data.xml"); myGrid.setTransparent(true); myGrid.addVariable("numberItemsPerPage", "10");