clearChart() fails on Material Bar Chart

54 views
Skip to first unread message

Steve Davies

unread,
Mar 15, 2018, 8:27:44 AM3/15/18
to Google Visualization API
Hi,

I'm having trouble with clearChart() - It works fine on my "core" Pie, Bar and Column charts, but on the Material Bar chart, it seems to do some sort of broken half-clear, and generally errors shortly afterwards.

It is easily demonstrated by loading the JSFiddle provided on the Google dev docs page, and using it to call clearChart() manually on the console. To find the JSFiddle, look for the link in the docs here:


Thanks for any suggestions, pointers or fixes :)

Regards,
Steve

Steve Davies

unread,
Mar 16, 2018, 8:01:07 AM3/16/18
to Google Visualization API
Might it be possible to work around this by calling clearChart() and then destroy any left-over DOM elements from the report?

Just wondering how valid that might prove to be or whether this will cause any obvious issues?

Thanks,
Steve

Daniel LaLiberte

unread,
Mar 16, 2018, 9:06:55 AM3/16/18
to Google Visualization API
Hi Steve,

I tried adding clearChart() calls to one of the JSFiddles, and it seems to work fine.  I call it just before redrawing, when you push any of the format buttons:  https://jsfiddle.net/1eu7rkvr/1/
Could you show how you were doing it that caused errors?

--
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/40b0dfb1-669a-45d1-a983-09dd4748938e%40googlegroups.com.

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



--

Steve Davies

unread,
Mar 16, 2018, 10:48:03 AM3/16/18
to Google Visualization API
Okay, interesting, so after the clearChart() if you _reuse_ the same chart object it seems to work, but if you (for example) wanted to replace the barchart with a Piechart, you would need to delete the old chart object and create a new one.

Try clicking the Delete button on this version of the fiddle:


If you have the console up you'll also see a backtrace/error if you mouse-over the "deleted" graph when an even fires that accesses the cleaned up data.

Cheers,
Steve


On Friday, 16 March 2018 13:06:55 UTC, Daniel LaLiberte wrote:
Hi Steve,

I tried adding clearChart() calls to one of the JSFiddles, and it seems to work fine.  I call it just before redrawing, when you push any of the format buttons:  https://jsfiddle.net/1eu7rkvr/1/
Could you show how you were doing it that caused errors?

On Fri, Mar 16, 2018 at 8:01 AM, Steve Davies <ste...@ipcortex.co.uk> wrote:
Might it be possible to work around this by calling clearChart() and then destroy any left-over DOM elements from the report?

Just wondering how valid that might prove to be or whether this will cause any obvious issues?

Thanks,
Steve

On Thursday, 15 March 2018 12:27:44 UTC, Steve Davies wrote:
Hi,

I'm having trouble with clearChart() - It works fine on my "core" Pie, Bar and Column charts, but on the Material Bar chart, it seems to do some sort of broken half-clear, and generally errors shortly afterwards.

It is easily demonstrated by loading the JSFiddle provided on the Google dev docs page, and using it to call clearChart() manually on the console. To find the JSFiddle, look for the link in the docs here:


Thanks for any suggestions, pointers or fixes :)

Regards,
Steve


--

Daniel LaLiberte

unread,
Mar 16, 2018, 11:13:01 AM3/16/18
to Google Visualization API
Yes, clearChart() doesn't actually delete the display of a previously rendered chart, although perhaps it should since you can no longer interact with it, or programmatically do anything with the chart object except to draw another rendering of the chart.

--
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.

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

Steve Davies

unread,
Mar 16, 2018, 11:16:53 AM3/16/18
to Google Visualization API
The non-material (Pie) charts seem to clear up their displays fully, which is where I got the expectation that they would all do so.


On Friday, 16 March 2018 15:13:01 UTC, Daniel LaLiberte wrote:
Yes, clearChart() doesn't actually delete the display of a previously rendered chart, although perhaps it should since you can no longer interact with it, or programmatically do anything with the chart object except to draw another rendering of the chart.

[snip]

Daniel LaLiberte

unread,
Mar 16, 2018, 11:27:35 AM3/16/18
to Google Visualization API
OK, I guess that is a bug specifically for the material charts.  This might apply to other non-corecharts as well.   

As you can probably tell, support for clearChart() evolved over the years, and most applications have no need for it at all, so it hasn't been well tested.

--
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.

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

Steve Davies

unread,
Mar 16, 2018, 12:48:45 PM3/16/18
to Google Visualization API
Looks like we should be able to work around it by killing the left-over DOM elements ourselves, and/or reusing the chart object where practical.

Thanks for the feedback
Steve
Reply all
Reply to author
Forward
0 new messages