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 :
[{"data":1.075095},{"data":1.031029},{"data":0.91654},{"data":0.748307},{"data":0.549199}....,{"data":0.012224}]
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().
Thank you for your help in advance.