LabVIEW Graphs, Charts, Arrays and Clusters
LabVIEW Graphs, Charts, Arrays and Clusters
Introduction
In this homework, you will learn about the differences and similarities
between graphs and charts and when to use each. You will also write
simple VIs to incorporate arrays and clusters in LabVIEW as a means of
combining data.
Objective
Learn the difference between a chart and a graph.
Theory
LabVIEW Graphs, Charts, Arrays, and Clusters
Introduction
In this section you will learn about graphs and charts, their similarities and
differences, and when to use each. You will also study arrays and clusters,
two ways to group data.
Graphs and Charts
Graphs and charts differ in the way they display and update data. VIs with
graphs usually collect the data in an array and then plot the data to the
graph, which is similar to a spreadsheet that first stores the data then
1
generates a plot of it. In contrast, a chart appends new data points to those
already in the display. On a chart, you can see the current reading or
measurement in context with data previously acquired.
The graphs and charts located on the Controls»Graph palette include the
following types:
• Plot Legend—Defines the color and style of the plot(s). Resize the
legend to display multiple plots.
• Scrollbar (chart only)—Scrolls through the data in the chart. Use the
scroll bar to view data that the buffer does not currently display.
2
Arrays
You can build arrays of numeric, Boolean, path, string, waveform, and
cluster data types. Consider using arrays when you work with a collection
of similar data and when you perform repetitive computations. Arrays are
ideal for storing data you collect from waveforms or data generated in
loops, where each iteration of a loop produces one element of the array.
Indexes
To locate a particular element in an array requires one index per
dimension. In LabVIEW, indexes let you navigate through an
array and retrieve elements, rows, columns, and pages from an
array on the block diagram.
Examples of Arrays
An example of a simple array is a text array that lists the nine
planets of our solar system. LabVIEW represents this as a 1D array
of strings with nine elements.
3
A more complex example of an array is a graph represented as an
array of points where each point is a cluster containing a pair of
numerics that represent the X and Y coordinates.
For example, a chessboard has eight columns and eight rows for a
total of 64 positions. Each position can be empty or have one chess
piece. You can represent a chessboard as a 2D array of strings.
Each string is the name of the piece that occupies the
corresponding location on the board, or an empty string if the
location is empty.
4
front panel, then place a string constant, numeric constant, or
cluster constant in the array shell. You can use an array constant as
a basis for comparison with another array.
If you try to display a column or row that is out of the range of the
array dimensions, the array control is dimmed to indicate that there
is no value defined, and LabVIEW displays the default value of the
data type. The default value of the data type depends on the data
type of the array.
Use the Positioning tool to show more than one row or column at a
time.
Array Functions
5
Use the Array functions located on the Functions»Array palette to
create and manipulate arrays, such as the following tasks:
• Split arrays.
You can access more than one element, or subarray (row, column,
or page) with these functions by using the Positioning tool to
manually resize the function. When you expand one of these
functions, the functions expand in increments determined by the
dimensions of the array wired to the function.
The index inputs you wire determine the shape of the subarray you
want to access or modify. For example, if the input to an Index
Array function is a 2D array and you wire only the row input, you
extract a complete 1D row of the array. If you wire only the
column input, you extract a complete 1D column of the array. If
you wire the row input and the column input, you extract a single
element of the array. Each input group is independent and can
access any portion of any dimension of the array.
6
Clusters
Bundling several data elements into clusters eliminates wire clutter on the
block diagram and reduces the number of connector pane terminals that
subVIs need. The connector pane has, at most, 28 terminals. If your front
panel contains more than 28 controls and indicators that you want to use
programmatically, group some of them into a cluster and assign the cluster
to a terminal on the connector pane.
Although cluster and array elements are both ordered, you must unbundle
all cluster elements at once rather than index one element at a time. You
also can use the Unbundle By Name function to access specific cluster
elements. Clusters also differ from arrays in that they are a fixed size. Like
an array, a cluster is either a control or an indicator. A cluster cannot
contain a mixture of controls and indicators.
Most clusters on the block diagram have a pink wire pattern and data type
icon. Clusters of numerics, sometimes referred to as points, have a brown
wire pattern and data type icon. You can wire brown numeric clusters to
Numeric functions, such as Add or Square Root, to perform the same
operation simultaneously on all elements of the cluster.
7
To wire clusters, both clusters must have the same number of elements.
Corresponding elements, determined by the cluster order, must have
compatible data types. For example, if a double-precision floating-point
numeric in one cluster corresponds in cluster order to a string in the other
cluster, the wire on the block diagram appears broken and the VI does not
run. If numerics of different representations, LabVIEW coerces them to
the same representation.
8
Homework Procedure
Part 1. Temperature Monitor VI
Complete the following steps to build a VI that uses a While Loop and a
waveform chart to acquire and display data.
1. Open a new VI.
b. Type Power inside the label and click outside the label or click
the Enter button on the toolbar.
d. Type Temperature History inside the label and click outside the
label or click the Enter button.
e. The waveform chart legend labels the plot Plot 0. Use the
Labeling tool to triple-click Plot 0 in the chart legend, type Temp,
9
and click outside the label or click the Enter button to relabel the
legend.
h. Label the y-axis Temp (Deg F) and the x-axis Time (sec).
6. Wire the block diagram objects as shown in the previous block diagram.
10
7. Save the VI as Temperature Monitor.vi.
9. Use the Operating tool to click the vertical toggle switch and turn it to
the ON position.
The section of the block diagram within the While Loop border, or
subdiagram, executes until the specified condition is TRUE. For example,
while the switch is on (TRUE), the Thermometer VI takes and returns a
new measurement and displays it on the waveform chart.
11. Click the vertical toggle switch to stop the acquisition. The condition
is FALSE, and the loop stops executing.
12. Format and customize the X and Y scales of the waveform chart.
a. Right-click the chart and select Y Scale»Formatting from the
shortcut menu. A dialog box appears.
b. Click the Scale Style icon and select different styles for the y-
axis. You also can select different mapping modes, grid options,
scaling factors, and formats and precisions.
c. Select the options shown in the previous dialog box and click the
OK button.
11
13. Right-click the waveform chart and select Data Operations»Clear
Chart from the shortcut menu to clear the display buffer and reset the
waveform chart. If the VI is running, you can select Clear Chart from the
shortcut menu.
b. Use the Operating tool to click the vertical toggle switch and
turn it to the ON position.
16. Use the Operating tool to click the vertical switch to stop the
acquisition. The switch changes to the OFF position and changes back to
ON after the conditional terminal reads the value.
12
a. Place the Wait Until Next ms Multiple function located on the
Functions»Time & Dialog palette. This function makes sure that
each iteration occurs every half-second (500 ms).
19. Try different values for the numeric constant and run the VI again.
13
Part 2. Temperature Analysis VI
In Part 2, you will use charts, graphs, arrays, and clusters to build a VI that
measures temperature every 0.25 s for 10 s. During the acquisition, the VI
displays the measurements in real time on a waveform chart. After the
acquisition is complete, the VI plots the data on a graph and calculates the
minimum, maximum, and average temperatures. The VI displays the best
fit of the temperature graph.
1. Open a new VI and build the following front panel using the following
tips.
• Use the Positioning tool to resize the plot legend of the waveform graph.
• Use the Labeling tool to rename Plot 0 to Temp and Plot 1 to Fitted.
• Set the point style of the waveform graph Temp plot to a small square.
14
• Do not create the Mean, Max, and Min indicators yet.
15
g. Place the Bundle function located on the Functions»Cluster
palette. Press the <Ctrl> key while you drag the function to copy it.
This function assembles the plot elements into a single cluster.
The elements include the initial x value (0), the .x value (0.25), and
the y array of temperature data. The .x value of 0.25 is required so
that the VI plots the temperature array points every 0.25 s on the
waveform graph.
The graph displays both the temperature data and best fit curve of the
temperature waveform.
5. Try different values for the polynomial order constant on the block
diagram and run the VI again.
6. Change the appearance of plots by modifying the plot styles and fill
styles.
a. Right-click the Temp plot display in the plot legend and select
Common Plots»Scatter Plot from the shortcut menu, the top
middle option.
b. Right-click the Fitted plot display in the plot legend, select Bar
Plots from the shortcut menu, and select the second option in the
middle row.
16
Part 3. Find Mid Value VI
Add the two arrays, calculate the size of the final array, and
extract the middle value from the final array.
17