|
Performance Optimizations Required |
Posted by Holger on Apr-04-2017 19:45 |
|
I am trying to use the ChartDirector control to visualize real time process data - just like in your realtime demo. However, since I need to use multiple instances, the UserInterface becomes unresponsive. After profiling I found out, that ChartDirector itself seems to run non-related operations in the UI-Thread while executing ChartDirector.BaseChart.makeImage(). Would it be possible to seperate UI-related and non-related code, asynchronously executing business logic while using the UI only for GDI operations? Thanks, Holger. |
Re: Performance Optimizations Required |
Posted by Peter Kwan on Apr-05-2017 03:36 |
|
Hi Holger,
Only the WinChartViewer and ViewPortControl is UI related. Everything in ChartDirector is not UI related. So you can put the charting code from "new XYChart(.....)" to "makeImage" in another thread. The only part is in the GUI thread is set the Image to the WinChartViewer in the GUI thread.
//In non-GUI thread
XYChart c = new XYChart(.....);
Image myChartImage = c.makeImage();
//////////////////////
.....
//In GUI thread
myChartViewer.setImage(myChartImage);
However, because you try the above, may be you can inform me of your usage (how many charts, the size of the chart in pixels, the update rate, how are the charts updated, etc). From our experience, in most realtime chart applications, the user interface can remain responsive by ensuring there is a time gap between chart updates.
For example, suppose your realtime charts are updated by a timer once per second. When the timer ticks, your code updates 20 charts on the screen. In this case, the user interface may be not responsive because it takes time to update 20 charts, and during that time, no other user interface events (mouse actions) can occur.
To make the user interface responsive, one way is to structure the update as follows:
(a) Set the timer to 5ms or even less.
(b) When the timer ticks, check if there is any chart that needs update. For example, you may use 20 variables to store the last update time of the 20 charts. The code can check if the last update time for a chart is more than 1 second to determine if a chart needs update.
(c) The trick is, each time the timer ticks, it can only update at most one chart. If there are other charts that need to be updated, they have to wait for the next tick (5ms later). That means there must be at least a 5ms gap between udpating each chart when other user interface event can occur.
Hope this can help.
Regards
Peter Kwan |
|