Windchill Business Analytics: Programming Journal
Part 07: Auto Updating Displayed Data
Last Updated: August 21, 2016
No that I have an HTML page displaying data to the user, I want to make sure that data keeps up to date. I need a way to update and display new data. I don't want the user to have to refresh the webpage and I don't want the entire page to refresh on its own. I just want each individual section that is displayed to update without flashing the user from a page refresh. AJAX will help me get there.
First, the C# modifications to ad dynamic data to the XML file.
First, the C# modifications to ad dynamic data to the XML file.
The above code now reads the SQL queries values and manipulates each of them +-100 before writing the results to the XML file. Now that my XML is loading changing data every time, I need my web page to read and update the data as well.
Changes/Additions:
Issues:
- I've added a myTimer function which calls the getData() function every 5 seconds.
- I had to move the data,addRow() portion outside of the because it would keep appending rows to the existing data instead of replacing the contents of each cell. Obviously, this needs to be modified further to be dynamic with the data but I manually set it to 12 because I know how many rows there are this time.
- In place of the previous add.Row() section, I've changed it to use the .setCell() function. The data now gets overwritten each time the getData() function is called. Now more additional rows are created.
- Finally, set the myTimer() function to call the getData() function so that the data is loaded.
Issues:
- The legend redraws along with the data every time. Even if the data does not change, you will see the legend perform a slow flash just because you redrew the chart.
- One solution is to simply not use the Google Charts legend and build your own in a standard html table.
- Another way to slow the flashing would be to check if any of the data changed from the last read and only redraw the chart if a change it detected. A simple single variable set the 0 that changes on any of the comparisons would do.