04-30-2014 01:45 AM
Hi
I would like to bind an object collection to my Graph. The binding should be dynamic, thats is, when I add an object to the collection the graph should be updated accordingly.
I have attached a code example. Questions:
1. Is there a way to map my properties (flow,head) to x/y coordinates. When I run the code the execution stops at sg.DataSource=olist
2. I will have many plots in the graph. How do I bind a collection to a certain plot?
3. Could i use a "list(of PLCResponse)" instead of an ObservableCollection. Whats the best approach here?
Thanks
/Axel
Sweden
Solved! Go to Solution.
04-30-2014 01:07 PM
1) For the graph to recognize your custom data type, you need to implement descriptor for that type. In this case, one that implements the IOpMultiDimensional
interface, like the attached PLCResponseDescriptor.vb
file.*
2) To supply data to a particular plot, you can either use the Data
collection directly (e.g. sg.Data(0) = olist0
to give data to the first plot, sg.Data(1) = olist1
for the second plot, etc); or use a data source containing multiple collections (e.g. sg.DataSource = { olist0, olist1, ... }
).
3) Using an observable collection is the simplest way to get the graph to re-draw when PLC items are added or removed.† Using a list or other collection would also work, but the graph will not automatically respond when the list is modified; instead, you would need to manually call Refresh
, or assign a new collection, for the graph to re-draw.
* – Measurement Studio does not currently support Decimal
values natively, so the descriptor converts the data into double
values for display by the graph.
† – The graph will only respond to changes to the collection itself, not to changes on the items in the collection (e.g. olist(0).Head = 1
will not cause the graph to re-draw). If you want the graph to automatically respond to item-level changes, you would want to implement an IOpObservable
descriptor for your OPoints
collection type, raising an event for both collection and item changes.
05-05-2014 04:09 AM
Thanks Paul. The descriptor works fine
I also tried to implement an IOpObservable descriptor but I could not make it work. Are both the descriptors required to make the Graph react on changes in my items?
You are also mentioning that I must raise an event. Do I have to implement this or is it performed by ValueObserver in some way?
I could not find any examples with this descriptor when searching the DotNet\Examples folder....
Regards
Axel
05-05-2014 10:22 AM
Implementing custom descriptors is a more advanced topic, and we have not created any examples for it yet.
For IOpObservable(Of OPoints)
in particular, the idea is to:
GetDimensionDataTypes
/DecomposeValues
/etc methods on the example PLCResponseDescriptor
to the GetDimensionDataTypes
/Decompose
/etc methods on a new OPointsDescriptor
, andGetValueObserver
, which would monitor a particular OPoints
instance through CollectionChanged
, as well as every PLCResponse
in the collection through PropertyChanged
.(The ObservedValueChanged
event on IValueObserver
was the event I was referring to earlier.)
05-06-2014 12:35 AM
Thanks. I will try this again.
/Axel