Thanks VizGuy.  That sounds simple enough and it works for a while -- 
but after calling draw() a few times, the gauges disappear.

Here is my sample app using the 5 gauges like those from the Showcase.  
Am I doing something wrong?  or is there a bug in the Viz library?

package com.company.gaugetest.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.visualization.client.AjaxLoader;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.Gauge;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GaugeTest implements EntryPoint
{
    private Gauge gauge;
    private Gauge.Options options;
   
    public void onModuleLoad()
    {
        Runnable onLoadCallback = new Runnable() {

            public void run()
            {
                RootPanel rootPanel = RootPanel.get();

                options = Gauge.Options.create();
                options.setWidth(400);
                options.setHeight(240);
                options.setGaugeRange(0, 24);
                options.setGreenRange(0, 6);
                options.setYellowRange(6,12);
                options.setRedRange(12, 24);
               
                final DataTable data = getData();
               
                Timer timer = new Timer() {

                    public void run()
                    {
                        // Randomly pick one gauge to update with a 
random number.
                        int index = Random.nextInt(4);
                        int num = Random.nextInt(24);
                        data.setValue(index, 1, num);
                        GWT.log("Next for " + index + " is " + num, null);
                       
                        gauge.draw(data, options);
                    }
                   
                };
   
                gauge = new Gauge(data, options);
                rootPanel.add(gauge);

                timer.scheduleRepeating(2000);
            }
           
        };
       
        AjaxLoader.loadVisualizationApi(onLoadCallback, Gauge.PACKAGE);
    }

    private DataTable getData()
    {
        final DataTable data = DataTable.create();
        data.addColumn(ColumnType.STRING, "Task");
        data.addColumn(ColumnType.NUMBER, "Hours per Day");
       
        data.addRows(5);
        data.setValue(0, 0, "Work");
        data.setValue(0, 1, 11);
        data.setValue(1, 0, "Eat");
        data.setValue(1, 1, 2);
        data.setValue(2, 0, "Commute");
        data.setValue(2, 1, 2);
        data.setValue(3, 0, "Watch TV");
        data.setValue(3, 1, 2);
        data.setValue(4, 0, "Sleep");
        data.setValue(4, 1, 7);
       
        return data;
    }
}

VizGuy wrote:
> This can be done easily.
>
> All you have to do is to call the draw() function of the same chart 
> again, with a new data. This will cause the needle to move to the new 
> place.
>
> Notice that if you are using a query to get the data from a remote 
> data source, you can set the query to have a refresh interval and so 
> it will automatically send for a new data and if it was changed, the 
> function that you originally set to be called when the query is back, 
> we be called again.
>
> Regards,
> VizGuy
>
>
> On Tue, Jan 13, 2009 at 9:34 AM, TomHj <[email protected] 
> <mailto:[email protected]>> wrote:
>
>
>     I'm investigating whether I can use the Google Visualization API with
>     the GWT wrapper within my GWT app to display a dashboard of gauges.
>     The gauges would display things like memory utilization, disk usage,
>     etc.  I need to be able to update the gauges on the fly (so the
>     needles are repositioned without redrawing the entire gauge).
>
>     I can't tell if the Gauge visualization supports that updating to
>     reflect new data.  If so, how is it done?
>
>     thanks,
>     Tom
>
>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to