Optimizing Speed and Performance of a Graph Control
Optimizing the Speed of a Graph Control
Smooth Updating
When you enable smooth updating, the graph updates first to an off-screen buffer and then to the screen. Smooth updating improves performance in the following ways:
- Eliminates flashing associated with plotting large plots.
- Optimizes speed when you use graph cursors.
- Optimizes speed when a graph is updated after it has been overlapped or hidden.
Smooth updating has the following disadvantages:
- Initial plotting speed is slower.
- Memory usage increases.
LabWindows/CVI automatically disables smooth updating of the graph when you make the color of the plot background transparent or when a visible item overlaps the plot area.
To enable smooth updating, use the following function:
SetCtrlAttribute (panelHandle, graphCtrl, ATTR_SMOOTH_UPDATE, 1);
ATTR_SMOOTH_UPDATE slows the initial graphing of a plot because the graph updates to the off-screen buffer before plotting to the screen. However, when you move or close a window that covers the graph, ATTR_SMOOTH_UPDATE lets LabWindows/CVI refresh the graph quickly because the plots already exist in the off-screen buffer.
Autoscaling
When you enable autoscaling, LabWindows/CVI recalculates the limits of the axes and remaps the existing graph plots with every new plot. As the number of existing plots on a graph increases, try to minimize scaling adjustments because the time necessary to recalculate and remap all the existing plots increases. You can minimize delays by disabling autoscaling, thereby preventing the recalculation and remapping of the graph plots. To disable autoscaling, SetAxisScalingMode with the axisScaling parameter set to VAL_MANUAL or VAL_LOCK.
Anti-Aliasing
Anti-aliasing causes plots to draw more smoothly, but the plotting speed is slower. By default, graphs do not draw anti-aliased plots. To enable anti-aliasing, use the following function:
SetCtrlAttribute (panelHandle, graphCtrl, ATTR_ENABLE_ANTI_ALIASING, 1);
![]() |
![]() |
Anti-aliasing disabled | Anti-aliasing enabled |
Redrawing the Plot Area
Graphs can refresh data in the following ways: redraw the plot area immediately, redraw the plot later, or not to redraw at all.
// Draw immediately
DeleteGraphPlot (panelHandle, graphCtrl, -1, VAL_IMMEDIATE_DRAW);
// Redraw later
DeleteGraphPlot (panelHandle, graphCtrl, -1, VAL_DELAYED_DRAW);
...
RefreshGraph (panelHandle, graphCtrl);
// Do not redraw
DeleteGraphPlot (panelHandle, graphCtrl, -1, VAL_NO_DRAW);
The preferred way to delete a plot and then plot a new one is to set refresh to VAL_DELAYED_DRAW when deleting, then plot the new plot. When you do this and enable smooth updating, you eliminate screen flashing and increase the speed of the update.
If you redraw later, LabWindows/CVI does not redraw the plot area until you perform one of the following operations:
- Rescale the graph.
- Change almost any graph attribute.
- Expose the plot area after hiding or overlapping it.
- Enable ATTR_REFRESH_GRAPH through SetCtrlAttribute.
- Call RefreshGraph.
- Add a new plot while ATTR_REFRESH_GRAPH is enabled.
- Call DeleteGraphPlot with refresh set to VAL_IMMEDIATE_DRAW.
- Move the cursor.
ATTR_REFRESH_GRAPH determines whether LabWindows/CVI draws new plots on a graph control immediately. When the program builds a multiplot image for which only the final appearance is of interest, disable ATTR_REFRESH_GRAPH before you plot, and enable it after you finish plotting. That way, LabWindows/CVI redraws the graph only once, instead of each time you add a plot. Speed increases derived from using ATTR_REFRESH_GRAPH are even more noticeable when you also enable smooth updating. Plots that you add while ATTR_REFRESH_GRAPH is disabled are held in pending status. Pending plots appear only after you call RefreshGraph or when you enable ATTR_REFRESH_GRAPH.
Optimizing Memory Usage
You can optimize memory usage by disabling ATTR_COPY_ORIGINAL_DATA and setting ATTR_DATA_MODE to VAL_DISCARD, but the savings are not significant in comparison to the overall amount of memory that LabWindows/CVI uses.
ATTR_SMOOTH_UPDATE saves an off-screen bitmap of the graph. You can save memory by disabling this attribute.
Use ATTR_DATA_MODE to retain or discard scaled plot data for new plots you add. Changing the attribute does not affect existing plots. You can save memory by setting ATTR_DATA_MODE to VAL_DISCARD, but that approach has the following disadvantages:
- When you disable ATTR_SMOOTH_UPDATE and set ATTR_DATA_MODE to discard, you get the following results:
- The plot does not appear on the printout when you call PrintPanel or PrintCtrl.
- The plot disappears from the screen when the graph is redrawn for any reason.
- When you enable ATTR_SMOOTH_UPDATE and set ATTR_DATA_MODE to discard, you get the following results:
- The plot does not appear on the printout when you call PrintPanel or PrintCtrl with ATTR_BITMAP_PRINTING set to FALSE.
- The plot disappears from the screen when the graph is rescaled.
The graph can rescale for the following reasons:
- You call SetAxisScalingMode.
- You change ATTR_XMAP_MODE or ATTR_YMAP_MODE.
- You add a new plot when autoscaling is enabled and the minimum or maximum values change.
- You change graph attributes that affect the size of the plot area.
![]() |
Note You cannot delete plots that you add to a graph while ATTR_DATA_MODE is set to VAL_DISCARD because the plot functions do not return plot handles. The graph behaves as if the plot does not exist. |
The ATTR_COPY_ORIGINAL_DATA attribute determines whether the graph control keeps its own copy of the plot data. When you disable ATTR_COPY_ORIGINAL_DATA, the graph control maintains a pointer to the original array data you originally passed to the plotting function. If you change the original data or deallocate the array, either the graph displays incorrect data or an invalid pointer error occurs. ATTR_COPY_ORIGINAL_DATA affects only graph plots that are associated with arrays, such as PlotWaveform and PlotXY. The graph control uses the original data only when the graph is rescaled.
ATTR_COPY_ORIGINAL_DATA is valid only if you set ATTR_DATA_MODE to retain data.