What we would like to do is select as many numeric labels on a window screen (the background color will change to be ‘highlighted’ by use of the mouse pressed event handler script), then click a button that would add the selected label value paths to a pop up chart to trend.
I’ve searched already for some ideas, but not sure they are want I want or able to understand them well enough. There’s some nicely made examples like “click to graph” from some years ago, and a “Better Graphs” that someone built.
Since we are using templates and UDT’s in a very dynamic project, what I’m thinking is we need to pass the tag path somehow from the “selected” labels into a chart to populated the pens. The selected labels will have a unique background color when selected, which may help identify in the script.
Does someone have some example codes that my help? Thanks.
I would use a couple custom properties on each numeric label that is graphable. One would be a boolean, “toGraph” perhaps, that holds your selected status. Your background would be driven from this boolean. The second custom property would be some form of graph configuration pointer. If you are mixing database pens and tag history pens, I would create a DB table holding all possible pen definitions, like the Click-to-graph setup, including a flag for what type of pen to use. If you are only using tag history, you could simplify–maybe even only using a custom string property holding the tag name in history provider format.
In any case, your “Open Graph” button would loop through all the components in your window, pick out all graphable components that have “toGraph” turned on, and assemble all of the pen information into the necessary
tagPens dataset formats. (And turn off the
toGraph boolean on the way by.) Then open a generic graphing popup window that has
tagPens as root container properties (bound to the EasyChart), passing the constructed datasets in the openWindow() call.
This gives some good pointers. I was able to work the “toGraph” boolean part. For now, I can just work on using tag history for simplicity, is there some sample coding to get me started? I’m not familiar with and finding it difficult to get started in what syntax to use to get all the proper data. I’ve been referencing the system.dataset index, but not sure what to use. Also, is there some examples in looping though components in a window?
Ok, just tag history is simpler. So the 2nd custom property would be something like “graphTagPath”. Assuming your button and all labels are in the window’s root container, you’d get a list of tag paths like this (button actionPerformed event):
root = event.source.parent
tagList = 
for comp in root.components:
# Use getattr to either retrieve the property or fake a "False" if not present
if getattr(comp, 'toGraph', False):
# Reset the toGraph property while looping
comp.toGraph = False
At this point, you have a list of tag paths to graph, much like you’d have if you wrote your own onTagsDropped event handler. There are various examples of that here on the forum.
In this case, instead of assigning the result dataset directly to the EasyChart tagPens property, you’d pass it to the charting popup window, relying on a binding to deliver it to the chart.
I got a little further, how do I bind it to the chart on the popup window? So I wouldn’t be using the cell update binding with the tagPens property or any property on the EasyChart, just a custom property on the root container of the popup window? Would that custom property be graphTagPath or tagList? Also, how do the pens on the chart populate dynamically? Thanks
You have to construct a tagPens dataset from your tagList as if it were the paths supplied to a onTagsDropped event handler.
The popup’s root container property would be a
tagPens dataset, and that property on the actual chart would be bound to it. That binding will populate the chart after the popup opens.
Sorry for my lack of scripting knowledge…Is there any examples or resources in showing how to construct a tagPens dataset? I can search on the forum and help manual to find bits and pieces, but not sure on how to do what I’m looking for.
Did you follow my search link? The very first result has a detailed example.
You’ll probably want to create an axis for each discreet engineering units as well so that tags with the same units display with their own axis.
If you look at your EasyChart component properties and open up the datasets for the tagPens and the axes - these are what you need to recreate in script using lists and then converting to datasets using
system.dataset.toDataSet before writing them back to the chart datasets.
Is this possible to create this same functionality in perspective?