Can somebody post a working example of a Query.send(callback) method,
and a servlet which returns a datatable, which has a working
RefreshInterval?

i.e. If the datatable returned is full of random data, then the chart
should refresh with the new random data at the set refresh interval...

Thanks

On Aug 13, 10:05 am, Hazer <[email protected]> wrote:
> Hi,
>
> I'm not being very clear, sorry. Basically, all I want is to have my
> charts update automatically. As you know, there's 2 methods talking to
> each other here:
>
>         Client: Query.send(callback)
>
>         Servlet: generateTable(query, request)
>
> The generateTable sends a DataTable back to the callback correctly the
> first time. But nothing happens after this. Regardless of whether or
> not the DataTable produced by generateTable has changed, I would still
> expect the generateTable method to be called at the
> query.setRefreshInterval (5 seconds).
>
> I must be doing something wrong, because I can't see how the
> query.send can poll if the DataTable has changed, since generateTable
> is just a stupid method that returns a DataTable object whenever it is
> called.
>
> I don't even mind if the full dataTable is sent back to the callback
> every 5 seconds, I just want to see that it updates in realtime.
>
> Here are the important parts of my code:
>
> Servlet:
> public class FetchDataTable extends DataSourceServlet{
>     @Override
>     public DataTable generateDataTable(Query query, HttpServletRequest
> request) throws DataSourceException {
>         System.out.println("DataTableGenerator: [" + new Date() + "] -
> " + request.getRequestURL() + " - " + request.getQueryString());
>         DataTable dataTable = generator.buildDataTableFromDB();
>         return dataTable;
>     }
>     ...
>
> }
>
> Client:
>         final Runnable onLoadCallback = new Runnable() {
>             public void run() {
>                 final Visualization chart = ChartManager.buildChart
> (chartType, width, height, title);
>                 wrapper.addChild(chart);
>                 Query query = Query.create("http://localhost:8084/
> FetchDataTable?tqx=reqId:" + (Math.random() * 1000000)));
>                 query.setRefreshInterval(5);
>                 query.send(new Callback(){
>                     public void onResponse(QueryResponse response) {
>                         if (response.isError())
>                             SC.say("An error occured: " +
> response.getDetailedMessage());
>                         else
>                         {
>                             chart.draw(response.getDataTable
> (),ChartOptions.create(chartType, width, height, title));
>                             wrapper.unmask();
>                         }
>                     }
>                 });
>             }
>         };
>         // Load the visualization api, passing the onLoadCallback to
> be called when loading is done.
>         ChartOnlineAPI.loadAPI(chartType, onLoadCallback);
>
> On Aug 13, 10:17 am, VizWiz <[email protected]> wrote:
>
> > Hi,
>
> > I am not sure why you would like to change this behavior, however, there is
> > currently no api for changing it.
>
> > The code that handles this is in JsonRenderer.renderJsonResponse (lines
> > 120-128). It is open source, so you can change it as you like for your own
> > use and as long as it is in the confines of the code license.
>
> > Cheers,
> > VizWiz.
>
> > On Thu, Aug 13, 2009 at 9:46 AM, Hazer <[email protected]> wrote:
>
> > > I see. Thanks for that, so there must be code in the servlet which
> > > handles this "hasTheDataChanged" query.
>
> > > I have a Servlet which extends DataSourceServlet, so it only
> > > implements one method: generateTable. This method builds a dataTable
> > > object from a db backend. Is there another method I should be
> > > overriding to get the desired effect of a servlet response which says
> > > "Yes, the data has changed" or "No, the data is the same".
>
> > > Thanks very much for your help.
>
> > > On Aug 11, 1:33 pm, MC Get Vizzy <[email protected]> wrote:
> > > > On Tue, Aug 11, 2009 at 12:56 PM, Hazer <[email protected]> wrote:
>
> > > > > Hi, thanks for the response.
>
> > > > > But when you ask "has the underlying data changed", do you mean the
> > > > > remote dataTable to be fetched? How could the client know if the data
> > > > > has changed without sending the query at the refresh interval? Is
> > > > > there some sort of implicit "hasDataChanged" request sent before
> > > > > query.send is fired??
>
> > > > the data source is queried, and if the data source responds that the
> > > > underlying data has not changed, your callback is not called.
>
> > > > > thanks in advance!
>
> > > > > On Aug 9, 2:07 pm, MC Get Vizzy <[email protected]> wrote:
> > > > > > regarding the refresh interval, is it possible that the underlying
> > > data
> > > > > has
> > > > > > not changed?  if the data has not changed, your callback will not be
> > > > > called.
> > > > > > regarding the redraw, what you have should work -- let me know if 
> > > > > > you
> > > > > have
> > > > > > further questions.
>
> > > > > > On Tue, Aug 4, 2009 at 10:56 AM, Hazer <[email protected]> wrote:
>
> > > > > > > Hi,
>
> > > > > > > I have successfully created a PieChart which receives its 
> > > > > > > DataTable
> > > > > > > via the Query.send method. However, it does not fire this method
> > > after
> > > > > > > the first time.
>
> > > > > > >                Query query = Query.create("http://localhost:8084/
> > > > > > > FetchDataTable");
> > > > > > >                query.setRefreshInterval(5);
> > > > > > >                query.send(new Callback(){
> > > > > > >                    public void onResponse(QueryResponse response) 
> > > > > > > {
> > > > > > >                        if (response.isError())
> > > > > > >                            SC.say("An error occured: " +
> > > > > > > response.getDetailedMessage());
> > > > > > >                        else
> > > > > > >                        {
> > > > > > >                            dataTable = response.getDataTable();
> > > > > > >                            pie = new PieChart(dataTable,
> > > > > > > createPieChartOptions(300, 180, "My auto refresh pie chart"));
> > > > > > >                            pie.addSelectHandler
> > > > > > > (createPieChartSelectHandler(pie));
> > > > > > >                            hLayout.addMember(pie);
> > > > > > >                        }
> > > > > > >                    }
> > > > > > >                });
>
> > > > > > > I've got 2 questions really:
> > > > > > > 1) What is causing the above code to not fire the query.send every
> > > 5
> > > > > > > secs?
> > > > > > > 2) This onResponse creates a new pie chart and adds it to hLayout
> > > upon
> > > > > > > every successful response. I'm assuming the correct thing would be
> > > to
> > > > > > > call pie.draw(dataTable, createPieChartOptions(300, 180, "My auto
> > > > > > > refresh pie chart"))
> > > > > > > I also assume I shouldn't be creating a new PieChart in the
> > > > > > > onResponse, so it must already have been created, but how can I
> > > create
> > > > > > > it AND add it to my DOM before I have my first dataTable?
>
> > > > > > > Here's an attempt to create the "empty" pie chart beforehand:
>
> > > > > > >                pie = new PieChart();
> > > > > > >                pie.addSelectHandler(createPieChartSelectHandler
> > > > > > > (pie));
> > > > > > >                hLayout.addMember(pie);
>
> > > > > > >                Query query = Query.create("
> > > > > > >http://localhost:8084/FetchDataTable";);
> > > > > > >                query.setRefreshInterval(5);
> > > > > > >                query.send(new Callback(){
> > > > > > >                    public void onResponse(QueryResponse response) 
> > > > > > > {
> > > > > > >                        if (response.isError())
> > > > > > >                            SC.say("An error occured: " +
> > > > > > > response.getDetailedMessage());
> > > > > > >                        else
> > > > > > >                        {
> > > > > > >                            dataTable = response.getDataTable();
> > > > > > >                            pie.draw(dataTable,
> > > createPieChartOptions
> > > > > > > (300, 180, "My auto refresh pie chart"));
> > > > > > >                        }
> > > > > > >                    }
> > > > > > >                });
>
> > > > > > > ...but again, the query.send doesn't get called more than once. :(
--~--~---------~--~----~------------~-------~--~----~
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