Example Code

Clearing Charts and Graphs Programmatically

产品和环境

本部分要求填写创建该范例所需的产品和操作系统。

如要下载NI软件(包括以下所示产品),请访问ni.com/downloads

    软件

  • LabVIEW

代码和文档

添加附件

Overview

Sometimes you want to retain data in your charts and graphs, sometimes you don't. This example shows how to optionally clear a chart or graph at Run-Time.

 

Description

This VI demonstrates the use of property nodes to clear a chart or a graph.  The user selects whether or not he wants the chart or graph to be cleared by pressing the button on the front panel.  The case structures allow the choice to be implemented.  The two for loops in the middle of the code generate the data to be plotted.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

1. Run the VI a few times and notice that the data is appended to the chart or graph.

2. Press the buttons below the chart and graph displays.

3. Run the VI again and notice that the previous data in the chart and graph was cleared before plotting the new data.

 

Additional Information or References

 

The chart and graph have different properties that must be set in order to clear the display.  Chart = History Data property; Graph = Value property

Also note that, since graphs don't have a history buffer, they always "clear". New data simply replaces old data. This example simulates a buffer by loading the old graph value at the beginning of each new call in an array, then appending the generated data to the array and displaying it in the graph.

 

To "clear" the graph in this example, all you really need to do is to write an empty array to the "Value" property node of the graph. However, it can take some time to send the new data to the graph after pressing the button. Therefore, it is recommended to use some Dataflow dependencies to force the "clearing" to happen at the beginning of the program.

 Clearing Charts & Graphs.PNG

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

NI社区“代码范例交流区”(Example Code Exchange)中的代码范例已获得MIT许可