From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph and legend binding easiest way

Hi!

 

I would like to display multiple plot on my graph, with a name for each which should be present on the Legend. I have a  ObservableCollection<ChartCollection<long>>  for my data, and a ObservableCollection<string> for my signal names. I am ready to convert any construct to any other.

Please give me an example with the intended, and easiest way to create a data binding!

 

 <ni:Graph x:Name="UCGraph"
            	DataSource="{Binding  ???}" />                   
               

<ni:Legend x:Name="UCLegend"                                   
                                   ItemsSource="{???}"                                   
                                   ItemBackground="{???}"  />
0 Kudos
Message 1 of 8
(5,524 Views)

I think the PlotsSource attached property from the question Wpf Graph Binding and defining Axes and Plots only in ViewModel would match what you are looking for here. Then the legend would work as usual ({Binding ElementName=UCGraph} to display all children in the graph, or with Path=AllPlots to show just the plots).

~ Paul H
Message 2 of 8
(5,473 Views)

Do I understand it correctly, that there is no built in, out of the box solution for this? It seems like a pretty standard usecase. How is the Graph object intended to be used?

0 Kudos
Message 3 of 8
(5,468 Views)

Generally speaking, the graph is data-focused, so you can use binding to populate a graph with data, and set the DefaultPlotRenderers used to display data. Without declaring any plots, the graph will still display all the data provided.


However, as you have found, the only way to associate the displayed data with a name in a legend is to use a plot. I have created a task to look into improving this in the future. It would be helpful to know if the PlotsSource approach makes the most sense to you, or if an alternative would be better (such as setting a name on the chart collection that is used to populate the plot label).

~ Paul H
0 Kudos
Message 4 of 8
(5,455 Views)

For me the most simple solution would be to be able to bind the data and the names to two separate properties of the graph. Let's say:

 

Plots = "{Binding myPlots}" Labels={"Binding myLabels"},

 

and if you bind your Legend to the graph it takes the names from Labels

0 Kudos
Message 5 of 8
(5,440 Views)

With the GraphExtension class how can I add the names for the plots?

0 Kudos
Message 6 of 8
(5,434 Views)

Also, I have the AllPlots property filled now, which is read only. How can I change settings on my plots now? What do I have to do to have the Plots properety filled? The graph class ducumentation doesnt' even have Plots or AllPlots listed:

http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/409fa0dc/

 

I am starting to get really anoyed with Measuremnt Studio. 😞

 

 

0 Kudos
Message 7 of 8
(5,403 Views)

First, sorry for the confusion, but the help you linked to is for the Windows Forms graph base class, not the WPF Graph control.

 

Most of our documentation effort has been spent on top-level types and concept topics like How to Plot and Chart with the Measurement Studio WPF Graph Control, so the documentation for individual members like Plots and AllPlots is a little sparse. To summarize:


  • Plots is the user-configurable collection where you can associate scales, labels, and renderers with the corresponding items in your data.
     
  • AllPlots includes both user-configured plots and also any automatically-generated plots.

In other words, if you gave the graph five chart collections, but only specified three plots, then the graph will automatically generate additional plots to display the remaining data (if you always have the same number of plots as data items, then AllPlots will always have the same elements as Plots).

 


Coming back to your questions, to populate Plots you will either need code behind to add elements to the collection, or use a solution like PlotsSource that will automatically populate the collection based on the source it is bound to.

 

To use PlotsSource with a collection of only plot labels, you will need some way to convert between a string label and a plot. You could change your model to expose plots instead of labels, create an IValueConverter to convert the collection of labels to a collection of plots, or edit the GraphExtensions implementation to set synchronizer.ItemConverter = label => new Plot(label).

~ Paul H
Message 8 of 8
(5,370 Views)