Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the legend item of a plot

Solved!
Go to solution

Is there a way to get a reference to the legend item of a plot?

 

Thanks,

 

Andy

0 Kudos
Message 1 of 8
(4,875 Views)

Greetings,

What type of graph you are using to display your plot?

 

 

Product Support Engineer
National Instruments
0 Kudos
Message 2 of 8
(4,864 Views)

ScatterGraph

0 Kudos
Message 3 of 8
(4,862 Views)

I might not completely understand what you're trying to do. However, it seems to me that when I drop a Scattergraph on my form and then drop a Legend on the form, I can access the legend like any other object via its name. IE MyLegend.Property=ValueForProperty.

 

Is that helpful? If not, can you provide more information about what you're trying to do?

 

 

Product Support Engineer
National Instruments
0 Kudos
Message 4 of 8
(4,853 Views)

I want a reference through the ScatterPlot object. In other words, if I have a reference to a ScatterPlot object at runtime, I now have to search the legend.legenditems collection for the plot's legend item. It would have been nice if I could reference directly the legend item tied to a plot--if there is one. Ie. ScatterPlot.LegendItem.

 

The workaround is to search the legend items for the legend item corresponding to the plot.

 

Andy

0 Kudos
Message 5 of 8
(4,843 Views)
Solution
Accepted by topic author SomeGreatAliasGoesHere

Hi Andeezle, from ScatterPlot you cannot get the LegendItem directly.

 

If you do not want to do the search in the Legend in the list, then you can do the following work around.

 


public class MyLegendItem : LegendItem
{
public MyLegendItem()
{
//Hook onto the property changed event.
PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged); }
void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { // IF the property changed was Source then set the legend to the MyPlot.LegendItem.
if (e.PropertyName == "Source") { ((sender as LegendItem).Source as MyPlot).LegendItem = sender as LegendItem; } } } // My derived scatter plot class that exposes Legend property
public class MyPlot : ScatterPlot { public MyPlot() { } private LegendItem legend = null; public LegendItem LegendItem { get { return legend; } set { legend = value; } } }

 

Message 6 of 8
(4,827 Views)

Don't know much about scatter graph.

0 Kudos
Message 7 of 8
(4,808 Views)

Greetings,

Did you have any specific questions about Scatter Graphs?

Product Support Engineer
National Instruments
0 Kudos
Message 8 of 8
(4,798 Views)