I have an application where I have data stored in a database. This needs to be rendered on a web page( a jsp page) as a real time graph. I am using Server Side Events for sending data from the database to the client page every second. On the client, I am using flot charts to render a real time graph.
I am receiving the data from server correctly every second. However, the flot chart is not displayed correctly. It just shows a single straight line going up and down. Here is the code:
The event.data received as per console.log is like this :
The graph shows a moving plot of a straight line which is incorrect. Also, the graph is not plotting from 0 of x-axis which is where the first datapoint starts.
Does this look like a concurrency issue. That is setupEventSource function has eventsource.onmessage which gets invoked every second and updates the serverDataPoints array. On the other hand, getRandomData gets invoked every few milliseconds to copy the server data and display it on the graph. Both these are present within $(function().