Easy Chart Show/Hide Pens

I would like to be able to toggle the “enabled” field for each the pens configured in an Easy Chart via scripting. Basically, I have several groups of pens and would like to turn groups on and off depending on the value of a custom property. My goal is to have one trend screen open in one of 4 or 5 different configurations depending on the value of this custom property. Any suggestions?

I created buttons for each grouping of pens that I wanted to view. I also added a button to show all tags along able to be trended, but not have any of them selected. I don’t know if this is exactly what you are looking for, but it may be a place to start.

I have attached some screen shots showing the Ignition screen, the scripting behind the “Show All” Button and one of the group buttons.

The Text Label on each button is the name of the Tag Pen Group to be view.

Hope this helps.

Chris










2 Likes

This is unbelievably helpful. Thank you so much for taking the time to share it.

You’re welcome!

I’m just paying it forward.

1 Like

This is greatly useful, even 6 years after you created it, thanks!

Use it, improve it, repost it.

To pay this forward and increase functionality, I’ve added functionality as a toggle button. Add this script to a button action to toggle the pen group on/ off. Create a client tag to link the script toggle to.

# grab the tag pen datset for modification
chartdata = event.source.parent.getComponent('Easy Chart').tagPens

selgroup = {"HIDDEN":0,"ENABLED":1}
hidegroup = {"HIDDEN":1,"ENABLED":0}
newgroup = {"HIDDEN":0,"ENABLED":0}
# use button name as group name
selgroupname = event.source.text

row=0

x = system.tag.read('[client]Chart 1/Toggle1') #refer to a boolean client tag

if x.value is True: #toggles boolean client tag and makes pen group appear and enabled
# Check each new row in dataset
	for row in range(chartdata.rowCount):
		groupname = chartdata.getValueAt(row,"GROUP_NAME")
		#assign new parameters based on selected group
		if groupname == selgroupname: #groupname is equal to button selected
			displaygroup = system.dataset.updateRow(chartdata,row,selgroup)
			chartdata = displaygroup
		#else: # uncommentsection to hide other groups
			#	displaygroup = system.dataset.updateRow(chartdata,row,hidegroup)
			#	chartdata = displaygroup
			# update tag pen dataset in chart		
	event.source.parent.getComponent('Easy Chart').tagPens = displaygroup
	system.tag.write('[client]Chart 1/Toggle1', False)
else: #toggles boolean client tag and makes pen group disappear and disabled
	# Check each new row in dataset
	for row in range(chartdata.rowCount):
		groupname = chartdata.getValueAt(row,"GROUP_NAME")
		#assign new parameters based on selected group
		if groupname == selgroupname: #groupname is equal to button selected
			displaygroup = system.dataset.updateRow(chartdata,row,hidegroup)
			chartdata = displaygroup
		#else: # uncomment section to hide other groups
			#	displaygroup = system.dataset.updateRow(chartdata,row,hidegroup)
			#	chartdata = displaygroup
		# update tag pen dataset in chart		
	event.source.parent.getComponent('Easy Chart').tagPens = displaygroup
	system.tag.write('[client]Chart 1/Toggle1', True)
1 Like

Hi there i try running the below but i get
image

any ideas what i am doing wrong? Ignition 8.1.4

grab the tag pen datset for modification

chartdata = event.source.parent.getComponent(‘Easy Chart’).tagPens

selgroup = {“HIDDEN”:0,“ENABLED”:1}
hidegroup = {“HIDDEN”:1,“ENABLED”:0}
newgroup = {“HIDDEN”:0,“ENABLED”:0}

use button name as group name

selgroupname = selgroupname = event.source.text

row=0

for row in range(chartdata.rowCount):
groupname = chartdata.getValueAt(row,“GROUP_NAME”)
#assign new parameters based on selected group
if groupname == selgroupname: #groupname is equal to button selected
displaygroup = system.dataset.updateRow(chartdata,row,selgroup)
chartdata = displaygroup
else: # uncomment section to hide other groups
displaygroup = system.dataset.updateRow(chartdata,row,hidegroup)
chartdata = displaygroup

update tag pen dataset in chart

event.source.parent.getComponent(‘Easy Chart’).tagPens = displaygroup

@Onejk generally this means there is some type of syntax error probably improper indentation.

Very difficult as you haven’t used the preformatted text option to post your code. You can use this by placing three back ticks ``` before and after the code. You can also use the </> button. This will maintain the formatting and indentation of your code.

sorry about that let me try again

# grab the tag pen datset for modification
chartdata = event.source.parent.getComponent('Easy Chart').tagPens

selgroup = {"HIDDEN":0,"ENABLED":1}
hidegroup = {"HIDDEN":1,"ENABLED":0}
newgroup = {"HIDDEN":0,"ENABLED":0}
# use button name as group name
selgroupname = event.source.text

row=0

# Check each new row in dataset
for row in range(chartdata.rowCount):
	groupname = chartdata.getValueAt(row,"GROUP_NAME")
	#assign new parameters based on selected group
	if groupname == selgroupname: #groupname is equal to button selected
		displaygroup = system.dataset.updateRow(chartdata,row,selgroup)
		chartdata = displaygroup
	else: # uncommentsection to hide other groups
		displaygroup = system.dataset.updateRow(chartdata,row,hidegroup)
		chartdata = displaygroup
			# update tag pen dataset in chart		
event.source.parent.getComponent('Easy Chart').tagPens = displaygroup

No worries.

You are having a scope issue. The variable displaygroup is not defined outside of the if and else statements.

I would change your code slightly to avoid this, something like:

# grab the tag pen datset for modification
chartdata = event.source.parent.getComponent('Easy Chart').tagPens

selgroup = {"HIDDEN":0,"ENABLED":1}
hidegroup = {"HIDDEN":1,"ENABLED":0}
newgroup = {"HIDDEN":0,"ENABLED":0}
# use button name as group name
selgroupname = event.source.text

row=0

# Check each new row in dataset
for row in range(chartdata.rowCount):
	groupname = chartdata.getValueAt(row,"GROUP_NAME")
	#assign new parameters based on selected group
	if groupname == selgroupname: #groupname is equal to button selected
		chartdata = system.dataset.updateRow(chartdata,row,selgroup)
	else: # uncommentsection to hide other groups
		chartdata = system.dataset.updateRow(chartdata,row,hidegroup)
# update tag pen dataset in chart		
event.source.parent.getComponent('Easy Chart').tagPens = chartdata
1 Like

Note for the future: if you make a formatting or grammar or other minor error in your post, you can edit it instead of re-posting. (:

Oldie but a goodie. This saved me a bit of time. Thanks!