ChartWrapper with nonzero RefreshInterval creates new queries when the .draw() method is called

66 views
Skip to first unread message

channa

unread,
Oct 27, 2016, 6:58:59 AM10/27/16
to Google Visualization API
Hello,

I have several ChartWrapper instances each connected to a data source with a nonzero refresh interval.  I draw the charts once on load and everything works fine.  I want to allow the user input to modify the refresh interval dynamically.  From the chartwrapper documentation I got the idea that it should be possible by calling 

my_chart_wrapper.setRefreshInterval(new_interval);
my_chart_wrapper
.draw()

However, when I do that, the original query seems to continue and I end up with a new query with its own refresh interval set.  This quickly becomes a problem. I realized that this happens generically when .draw() is called regardless of whether or not a new refresh interval is set.  Is there a way to redraw the chart after updating the refresh interval and aborting the original query? It doesn't seem obvious from the exposed API.  I noticed that there is a .clear() method, which is undocumented, but that doesn't do the trick either.

thanks,

Chad

Daniel LaLiberte

unread,
Oct 27, 2016, 11:32:13 AM10/27/16
to Google Visualization API
Hi Chad,

Thanks for your report.

Sounds like you have found a bug, and from the looks of the code, I suspect this has been around for a long time.   clear() should certainly reset everything, but even just changing the refresh interval and drawing again ought to be enough.  There should at least be a way to stop the refreshing, which would then provide another way to work around the otherwise uninterruptible extra refreshing.

The refreshing is actually being done by the internal refresh interval on the Query, and for Query by itself, it appears that changing the refresh interval should work properly.  So if you want to work around this, try setting up your own query and then pass each DataTable to your ChartWrapper.  

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/89974a7a-02d0-419e-b588-1066f8152ada%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Chad Hanna

unread,
Oct 27, 2016, 11:42:50 AM10/27/16
to google-visua...@googlegroups.com
Hi Daniel,

Thanks for confirming this. I thought I might need to rework things to use lower level classes.  It would be wonderful if this could be fixed in ChartWrapper since I plan to make a lot of charts and ChartWrapper is otherwise entirely adequate and makes for simpler code.  Is there any chance it could be fixed in the coming weeks, months, years?

Thanks again,

Chad

On Thu, Oct 27, 2016 at 11:32 AM, 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com> wrote:
Hi Chad,

Thanks for your report.

Sounds like you have found a bug, and from the looks of the code, I suspect this has been around for a long time.   clear() should certainly reset everything, but even just changing the refresh interval and drawing again ought to be enough.  There should at least be a way to stop the refreshing, which would then provide another way to work around the otherwise uninterruptible extra refreshing.

The refreshing is actually being done by the internal refresh interval on the Query, and for Query by itself, it appears that changing the refresh interval should work properly.  So if you want to work around this, try setting up your own query and then pass each DataTable to your ChartWrapper.  
On Thu, Oct 27, 2016 at 6:58 AM, channa <chad.r...@gmail.com> wrote:
Hello,

I have several ChartWrapper instances each connected to a data source with a nonzero refresh interval.  I draw the charts once on load and everything works fine.  I want to allow the user input to modify the refresh interval dynamically.  From the chartwrapper documentation I got the idea that it should be possible by calling 

my_chart_wrapper.setRefreshInterval(new_interval);
my_chart_wrapper
.draw()

However, when I do that, the original query seems to continue and I end up with a new query with its own refresh interval set.  This quickly becomes a problem. I realized that this happens generically when .draw() is called regardless of whether or not a new refresh interval is set.  Is there a way to redraw the chart after updating the refresh interval and aborting the original query? It doesn't seem obvious from the exposed API.  I noticed that there is a .clear() method, which is undocumented, but that doesn't do the trick either.

thanks,

Chad

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

Daniel LaLiberte

unread,
Oct 27, 2016, 11:55:00 AM10/27/16
to Google Visualization API
It doesn't appear to be difficult to fix, and it is a rather serious problem when it occurs, akin to an infinite loop.  So I would expect to address it relatively soon.

On Thu, Oct 27, 2016 at 11:41 AM, Chad Hanna <chad.r...@gmail.com> wrote:
Hi Daniel,

Thanks for confirming this. I thought I might need to rework things to use lower level classes.  It would be wonderful if this could be fixed in ChartWrapper since I plan to make a lot of charts and ChartWrapper is otherwise entirely adequate and makes for simpler code.  Is there any chance it could be fixed in the coming weeks, months, years?

Thanks again,

Chad
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsubscr...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

channa

unread,
Nov 3, 2016, 12:54:16 PM11/3/16
to Google Visualization API
Hi Daniel,

I am trying to work around this bug and was wondering if you or anyone could offer a bit of advice.  Ideally, I would like to implement my own ChartWrapper class that supports the minimum feature set I need so that I have an easy code change to make once the class is fixed upstream.  I started to try to do this using the QueryWrapper class, but I am beginning to think that might also not be the best idea.  Does anyone have any advice on this?

thanks in advance,

Chad


On Thursday, October 27, 2016 at 11:55:00 AM UTC-4, Daniel LaLiberte wrote:
It doesn't appear to be difficult to fix, and it is a rather serious problem when it occurs, akin to an infinite loop.  So I would expect to address it relatively soon.
On Thu, Oct 27, 2016 at 11:41 AM, Chad Hanna <chad.r...@gmail.com> wrote:
Hi Daniel,

Thanks for confirming this. I thought I might need to rework things to use lower level classes.  It would be wonderful if this could be fixed in ChartWrapper since I plan to make a lot of charts and ChartWrapper is otherwise entirely adequate and makes for simpler code.  Is there any chance it could be fixed in the coming weeks, months, years?

Thanks again,

Chad
On Thu, Oct 27, 2016 at 11:32 AM, 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com> wrote:
Hi Chad,

Thanks for your report.

Sounds like you have found a bug, and from the looks of the code, I suspect this has been around for a long time.   clear() should certainly reset everything, but even just changing the refresh interval and drawing again ought to be enough.  There should at least be a way to stop the refreshing, which would then provide another way to work around the otherwise uninterruptible extra refreshing.

The refreshing is actually being done by the internal refresh interval on the Query, and for Query by itself, it appears that changing the refresh interval should work properly.  So if you want to work around this, try setting up your own query and then pass each DataTable to your ChartWrapper.  
On Thu, Oct 27, 2016 at 6:58 AM, channa <chad.r...@gmail.com> wrote:
Hello,

I have several ChartWrapper instances each connected to a data source with a nonzero refresh interval.  I draw the charts once on load and everything works fine.  I want to allow the user input to modify the refresh interval dynamically.  From the chartwrapper documentation I got the idea that it should be possible by calling 

my_chart_wrapper.setRefreshInterval(new_interval);
my_chart_wrapper
.draw()

However, when I do that, the original query seems to continue and I end up with a new query with its own refresh interval set.  This quickly becomes a problem. I realized that this happens generically when .draw() is called regardless of whether or not a new refresh interval is set.  Is there a way to redraw the chart after updating the refresh interval and aborting the original query? It doesn't seem obvious from the exposed API.  I noticed that there is a .clear() method, which is undocumented, but that doesn't do the trick either.

thanks,

Chad

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.



--

Daniel LaLiberte

unread,
Nov 3, 2016, 1:26:18 PM11/3/16
to Google Visualization API
It might not be worth the trouble to implement your own ChartWrapper, and I'm not sure it is possible to do that well enough, depending on your needs.  I have checked in a fix for this bug, and I expect I will have to update v45 for another more serious reason, so you should see this in a week or two.

But in the short term, rather than replacing the ChartWrapper entirely, I would recommend just replacing its use of the refreshInterval on the query that you provide it.  Just set up your own Query, handle the response, set the ChartWrapper's dataTable, and draw() again.  

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsubscr...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

channa

unread,
Nov 3, 2016, 9:07:12 PM11/3/16
to Google Visualization API
Hi Daniel,

Thanks for letting me know that it will be sorted in a few weeks!  I went ahead and implemented a bare minimum ChartWrapper class so that I can minimize code changes (just a find and replace) once it is fixed upstream.  Forgive my javascript.  This is my first time really using it :)  I have verified that this works as I would hope and doesn't create new queries each time draw() is called.

function ChartWrapper(obj) {

        this.chartType = obj.chartType;
        this.dataSourceUrl = obj.dataSourceUrl;
        this.query = obj.query;
        this.query_object = null;
        this.refreshInterval = obj.refreshInterval;
        this.options = obj.options;
        this.containerId = obj.containerId;
        this.container = document.getElementById(this.containerId);

        command = "this.chart = new google.visualization." + this.chartType  + "(this.container)";
        eval(command);

        this.clear = function() {
                this.query_object && this.query_object.abort();
                this.chart.clearChart();
        }

        this.draw = function() {
                this.query_object && this.query_object.abort();
                this.query_object = new google.visualization.Query(this.dataSourceUrl + "&tq=" + this.query);
                this.query_object.setRefreshInterval(this.refreshInterval);
                var queryWrapper = new QueryWrapper(this.query_object, this.chart, this.options, this.container);
                queryWrapper.sendAndDraw();
        }

        this.setRefreshInterval = function (refreshInterval) {
                this.refreshInterval = refreshInterval;
                this.query_object.setRefreshInterval(this.refreshInterval);
        }
}


To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

Daniel LaLiberte

unread,
Nov 4, 2016, 10:54:59 AM11/4/16
to Google Visualization API
Your ChartWrapper looks like it could work, though it is order dependent on first calling draw() before setRefreshInterval() can be called, and draw() assumes there is a query.   So just a note for anyone else thinking of using this code, it might not work for you.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsubscr...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

channa

unread,
Aug 29, 2018, 4:52:56 PM8/29/18
to Google Visualization API
Hi Daniel,

Can you comment on whether or not the bug identified in this thread will be fixed in the next release?

Thanks,

Chad
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

Daniel LaLiberte

unread,
Aug 30, 2018, 8:59:01 AM8/30/18
to Google Visualization API
The bug I mentioned was probably fixed in version 45.2. which is also 'current' at this time.  Please try it and let me know.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.



--

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/wyYZue6b1iE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages