Reputation: 411
I am trying to plot data on a PDA that is being collected in real time via the bluetooth serial port using c# and windows mobile 5. I am having trouble plotting the data in such a way that it appears smooth. I have tried drawing a line from an array of points which worked but only really displayed discrete chunks of data. I found a similar solution on this forum in reference to ECG data, which also worked but again it showed some amount of data and then very visibly refreshed. I have tried drawing the points onto a bitmap and then painting the bitmap to make it smoother but again it isn't really fast enough.
What I would like to end up with is something that behaves like the CPU usage history graph in the windows task manager. A data point starts on the right hand side of the plot and moves smoothly across to the left. Is there a standard approach to a problem like this? I apologise if the question is a little vague but I don't want to spend ages trying different things if its a problem with a well known general solution.
Upvotes: 4
Views: 1096
Reputation: 67168
It kind of depends on how you want it to work visually. The CPU usage in Task Manager scrolls the entire chart right to left, and it is not at all smooth. It's refreshing (for me anyway) about once a second and when it refreshes, then entire chart "bumps" to the side.
I did something in the CF back in the 1.0 days as a test, and I opted to have the chart remain static and have the data lines continuually drawn left to right and when it reached the right edge, it would start drawing again back on the left, erasing the oldest chart data as it progressed (like an ECG does).
For that scenario, your bitmap is remaining largely unchanged, so you shouldn't be redrawing the entire thing. I did this by using a clipping resion that was basically a "vertical band" or rectangle the height of the chart but only, say, 10px wide. I redrew that band with the updated axis values so the only bits actually being redrawn is that small band. It also had the added benefit of doing the visible "erasing" the oldest data once I wrapped back to the start of the chart.
Upvotes: 1