Example Code

LabVIEW - Apply Plot Names to Legend

Code and Documents

Attachment

Download All

Overview
This LabVIEW example shows how you can programmatically apply plot names to a graph or a chart.

 


Description
This is often a requirement when writing raw values to the display - rather than having the default "Plot 0.. Plot 1.." you can apply descriptive names to your legend.

The example uses property nodes and presents three simplistic SubVIs which are used to apply the plot names, resize the legend and reposition on the right-hand-side of the Waveform Chart/Graph.

There is great scope for expansion with this however I hope this demonstrates some core principles.

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  • Download and unzip the attachment to your computer
  • Open the project
  • Open the VI "Update Graph Chart Test.vi"
  • Run the VI

 

Additional Information or References
VI Block Diagram of "Update Graph Chart Test.vi"

 Block Diagram.png

 

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


Regards,

Peter D

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

Comments
NI-hilator
Member
Member
on

Thanks! Kudos! This is a nice set of vis. There is only one quirk I found. If the graph palette, scale legend, cursor legend or scroll bars are visible the plot legend will be position to the right of the furthest of these. In most cases I like the graph tool on the right, just below the legend.  I discovered the Pallete.Visible property and added it to the property nodes in the Reposition Legend.vi.  For the resizing to work properly you must put the Pallete.Visibile element above the other .Visible elements in the first property node.  I would have attached the updated vi but can't seem to add file attachments to this post.

Be sure to make the change for both cases.

NI-hilator
Member
Member
on

I've been using these vis for some time and seemed to work ok.  Recently, however, it "suddenly broke".  I started getting Error 1077 "Property Node (arg 1) in Update GraphChart LegendText.vi->UpdateGraphChartLegend.vi Property Name: Active Plot."  The only change is that I've updated to Labview 2013 (and in hindsight perhaps how I was using it).  I found that the number of rows in the legend (legnumrows property) must be set prior to setting the active plot.  What this means is that Update GraphChart LegendSize.vi must be called before Update GraphChart Legend.vi. i.e. swap vis in steps 3 & 4. This never showed up before because my default graph had, lets say 5 plots in the legend and I had never sent it more that 5 plot names so the legend always sized down.  Recently I started to use this with more simultaneous plots thus flushing this out.  Hope this helps out someone else!