Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Good day, this is my first post.

I was trying to create a simple web page containing a line chart where the data on the chart will update every 1 second(via setInterval), Please take note that the data that is being shown in the chart came from the database and it's now working fine(the chart data is being updated every one second). However, I just noticed the if I scroll the page down, the scroll bar returns back at the top which is pretty annoying. My Question is, How can I prevent the scrollbar from returning back to top of the webpage while the data from the chart is updating. Below are my actual code. I hope someone can help me out.

Thanks a lot!

What I have tried:

$(document).ready(function(){

setInterval(function() { 
	reload_data();
}, 1000);

});

function reload_data(){
$("#myList").load("UpdateChart").fadeIn("fast");
}


/* FRONT End Codes */

<div id="page-content-wrapper">
    <div class="container-fluid">

        <span class="glyphicon glyphicon-nav" aria-hidden="true"><a href="#menu-toggle" class="btn btn-secondary" id="menu-toggle">x</a>  </span>

        <h1>Welcome!</h1>
        <div id="MyCharting">
            <div id="Chart1"></div><div id="Chart2"></div><div id="Chart3"></div>
            <div id="myList">
            </div>
        </div>
    </div>
</div>
Posted
Comments
Christiaan van Bergen 3-Apr-18 11:59am    
I cannot really tell why, but I can imagine that the gets a moment without data and therefor resets to a smaller size, making the scrollbar jump back. Maybe if you define the dimensions of that div, it will stay.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900