When updating a chart with Ajax, how can I prevent the page to scroll up back to the chart being updated?

403 views
Skip to first unread message

David Vallee

unread,
Oct 1, 2011, 5:41:32 AM10/1/11
to Google Visualization API
So I have an ajax call every seconds, grabbing some json data, and I
have some setValues to update the datatable with the json data. At the
moment I update the chart with the draw method, the page scrolls back
to the chart being updated. How can I prevent this behavior?

Julian King

unread,
Oct 2, 2011, 5:17:00 PM10/2/11
to google-visua...@googlegroups.com
Two things, first are you using the GoogleVisualizationsForDotNet that I published on code.google.com?  If not then i can't vouch for anyone else's implementation of google charts.  If you are using my wrapper class then the behavior you describe sounds like a postback?  I have a chart refreshing though AJAX and the page doesn't scroll.

If it is my chart wrapper please send sample code.



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




--
Best Regards,

Julian King
(206) 697-4663
hool...@gmail.com

Riccardo Govoni ☢

unread,
Oct 3, 2011, 4:42:23 AM10/3/11
to google-visua...@googlegroups.com
Hi David,
can you provide some extra info about the visualization you're using and/or an example page showing the problem?

I created this quick example: http://jsfiddle.net/7JLQ3/1/ that contains a chart placed in the middle of a very long page, updating every 5 seconds. I can't reproduce your problem: when the chart redraws the scrolling position is unaffected.

-- R.

Terry Slack

unread,
Feb 25, 2014, 5:11:45 PM2/25/14
to google-visua...@googlegroups.com, battl...@gmail.com
I to have this behaviour....when I update my chart, the page is scrolled to the top and also in my case, to the left.  Any thoughts.  


On Monday, 3 October 2011 02:42:23 UTC-6, Riccardo Govoni ☢ wrote:
Hi David,
can you provide some extra info about the visualization you're using and/or an example page showing the problem?

I created this quick example: http://jsfiddle.net/7JLQ3/1/ that contains a chart placed in the middle of a very long page, updating every 5 seconds. I can't reproduce your problem: when the chart redraws the scrolling position is unaffected.

-- R.

On 2 October 2011 23:17, Julian King <hool...@gmail.com> wrote:
Two things, first are you using the GoogleVisualizationsForDotNet that I published on code.google.com?  If not then i can't vouch for anyone else's implementation of google charts.  If you are using my wrapper class then the behavior you describe sounds like a postback?  I have a chart refreshing though AJAX and the page doesn't scroll.

If it is my chart wrapper please send sample code.
On Sat, Oct 1, 2011 at 2:41 AM, David Vallee <dav...@gmail.com> wrote:
So I have an ajax call every seconds, grabbing some json data, and I
have some setValues to update the datatable with the json data. At the
moment I update the chart with the draw method, the page scrolls back
to the chart being updated. How can I prevent this behavior?

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

For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

--
Best Regards,

Julian King
(206) 697-4663
hool...@gmail.com

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

asgallant

unread,
Feb 25, 2014, 5:29:28 PM2/25/14
to google-visua...@googlegroups.com, battl...@gmail.com
Can you post your code or a link to the page?

David Manz

unread,
Aug 3, 2015, 6:59:04 PM8/3/15
to Google Visualization API, battl...@gmail.com
Riccardo,

I modified your example to illustrate a similar problem that I have been having.  The main differences are that I am using a Table, I am reusing the Table and DataTable instead of starting anew each time I redraw, and I am redrawing in response to the click of a link instead of an Ajax request.  I did also remove the hard-coded dimensions on the chart.

You'll notice that when you click the update link at the bottom of the example, the screen scrolls so that the link is no longer in view.


David


On Monday, October 3, 2011 at 3:42:23 AM UTC-5, Riccardo Govoni ☢ wrote:
Hi David,
can you provide some extra info about the visualization you're using and/or an example page showing the problem?

I created this quick example: http://jsfiddle.net/7JLQ3/1/ that contains a chart placed in the middle of a very long page, updating every 5 seconds. I can't reproduce your problem: when the chart redraws the scrolling position is unaffected.

-- R.

On 2 October 2011 23:17, Julian King <hool...@gmail.com> wrote:
Two things, first are you using the GoogleVisualizationsForDotNet that I published on code.google.com?  If not then i can't vouch for anyone else's implementation of google charts.  If you are using my wrapper class then the behavior you describe sounds like a postback?  I have a chart refreshing though AJAX and the page doesn't scroll.

If it is my chart wrapper please send sample code.
On Sat, Oct 1, 2011 at 2:41 AM, David Vallee <dav...@gmail.com> wrote:
So I have an ajax call every seconds, grabbing some json data, and I
have some setValues to update the datatable with the json data. At the
moment I update the chart with the draw method, the page scrolls back
to the chart being updated. How can I prevent this behavior?

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

For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

--
Best Regards,

Julian King
(206) 697-4663
hool...@gmail.com

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

David Manz

unread,
Aug 4, 2015, 11:02:45 AM8/4/15
to Google Visualization API, battl...@gmail.com
The problem shows up when you are scrolled down near the bottom of the page.  When the redraw occurs, the table momentarily disappears causing the page to be shortened, the window to scrolls up by an amount equal to the height of the table that just disappeared, and when the table reappears, the window does not return to its previous scroll position.

I am going to try coming up with a workaround that involves wrapping the table in an element that will hold the place for the table while it disappears and is redrawn. 

David Manz

unread,
Aug 4, 2015, 11:36:39 AM8/4/15
to Google Visualization API, battl...@gmail.com
Here's my example modified with the workaround.  I just wrap the table with another div and set its height be to the same of the table's height once the table has been rendered.

https://jsfiddle.net/eg9a6noy/

Problem solved.

PMax

unread,
Jan 23, 2019, 2:10:09 PM1/23/19
to Google Visualization API
Cheers, this worked. For me I changed it by setting the DIV to 100% Height in CSS with no Java involved. Not sure if that is best practice, but works well in my situation.
Reply all
Reply to author
Forward
0 new messages