Example Code

XY Chart with support for multiple curves

Code and Documents

Attachment

Overview


XY charts are an oft-requested feature in LabVIEW; the ability to append new data without needing the old data to redraw the curve is desirable for plotting multiple curves over time. I found the need for one in an application of mine, and based the design off of this Knowledge Base article: http://digital.ni.com/public.nsf/allkb/18B56D8556D44BF18625753D006EFF7C

Description

This VI takes a 1D array of clusters of 2 elements as an input. The first element of the cluster is taken to be X, and the second element is Y. Each element of the 1D array corresponds to one curve you wish to plot. The examples provided should demonstrate the usage.

The output can be connected directly to the XY Graph indicator from the Graphs pallette. You can set the history buffer size, clear the chart, and use the error cluster to enforce dataflow in your program. Each VI has its own pool of memory, so you can use it to create as many multi-curve XY charts as you need.

I know there are many other implementations out there, but I wanted to share mine. Constructive criticism welcome.

Steps to Implement or Execute Code


  1. Make sure you're using LabVIEW 2013 or later.
  2. Bundle your data into a cluster, and use the "Build Array" function to create an array for input.
  3. See examples for more usage.

Requirements

Software

  • LabVIEW 2013
  • Windows - only tested for this platform

Hardware

  • None

Additional Images or Video

Example usage, from example 2.

http://i.imgur.com/dnUMHF7.png

VI Snippet

XYsnippet.png

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
tst
Knight of NI Knight of NI
Knight of NI
on

I didn't look at the actual code, only at the snippet, so this is based on that:

One thing that's always a concern with these things is memory management, since the array has to be contiguous in memory. Here are some options for implementing this:

  1. Rotate the array. This has a problem in that it doesn't require an allocation, but it does move all the elements, which takes time.
  2. Do what you did. This will either require LV to continuously allocate and free memory as the array travels across the RAM or it will need to shift all the elements similar to option 1. I don't know which actually happens.
  3. Add additional shift registers for tracking where you are and do replace inplace. You then need to take the data out and reconstruct it using the right order. This requires at least double the amount of RAM, but I *think* LV can reuse the buffers on subsequent runs, so it should probably perform better.

I never actually checked how these different options behave.

Also, minor style point - I really don't like Insert into Array, because it tends to be ambiguous. Unless I'm inserting in the middle of an array (rare), I much prefer Build Array.


___________________
Try to take over the world!
Contributors