Easy Chart, Tag Browse Tree and Data Types questions

I made a vision window with a easy chart and a tag browse tree and it still work nicely. However my tags that are historical are in data types. So when I add multiples of the same type of tag to the chart the pen names are the same other then a ignition adding a number. So my question is there a way a automatically add the name of the instance of the data type to the name of the pen in the easy chart? It would work if I could add part of the tag path as well. I know that in the designer you can change the name but I would like it to do this automatically in the client.

Also is there a way to grab the whole instance of the data types and add every historical tag to the chart, and having the pens named with the instance name or put into a different group?

Also Is there a way to add sub-plots automatically like real value goes to one plot and a bool value goes to a lower one automatically?

What happens now.
before1%20-%20Copy

What I would like to happen.
after1%20-%20Copy

I would be happy if the go in groups as well.
groups%20-%20Copy

Thank you for your time

You need to implement the onTagsDropped extension function on the easy chart to provide custom behavior. See this post for an example script: OnTagsDropped - Auto Axis

Thanks for your help, Its working somewhat. Just had a question for you. This is what I have so far. I do have the set up for chart defaults.

for path in paths:
newrow = default
newrow[0] = path.split(’/’)[-1]
newrow[1] = path
newrow[6] = self.autoColorList[tagpens.rowCount % len(self.autoColorList)]
newrow[13] = path.split(’/’)[-2]

tagpens = system.dataset.addRow(tagpens, tagpens.rowCount, newrow)
	
self.tagPens = tagpens

How do you write do look up what data type it is? So that I can move it to the right sub-plot.

Also how do you add the tag path to the right of the first “/”. In my example if I use this

path.split(’/’)[-2]

It give back “equ0” but not “equ0/integer”.

Thank you for your time.

The .split() method of strings in python yields an array of substrings. There won’t be any slashes in any of the substrings. You have to join the second-to-last and the last substring yourself. Python strings have a handy .join() method that can do this for you. And consider running .split() just once and holding the array in a temporary variable. Something like this:

parts = path.split('/')
....
newrow[13] = '/'.join(parts[-2:])

Note the slice operation in the last line that grabs the last two array elements.

1 Like

Thanks that works really well.

The only thing I need to know is to how to read a tag data type. I think I’m close but I cant seems to find anything about it.

tagtype = system.tag.read("%s.Type" % path)

if tagtype == “Boolean”:

try this:

tagtype = system.tag.read("%s.Type" % path).value

if tagtype == “Boolean”:

Remember that system.tag.read() returns a qualified value object so you must reference the value attribute of the qualified value.

Thanks for the info. Unfortunately it didn’t work. I’m going to keep tying to work at it.

The simplest way to get the type would be to use the instanceof function in Python, as long as you only care about float vs int vs boolean:

>>> isinstance(system.tag.read("[default]test 1").value, float)
True

float, int, and bool are all built-in classes/datatypes in Python; the Jython interpreter automatically turns float and double tag datatypes into Python’s float class; similarly, int and long are all int to Python.

Another option (not positive this works in 7.9, but is the syntax for 8):

>>> system.tag.read("[default]test.DataType").value
Int4

Where Int4 is an instance from the DataType enum; which you could also compare against using isinstance; something like:

from com.inductiveautomation.ignition.common.sqltags.model.types import DataType
isInteger = isinstance(system.tag.read("[default]test.DataType").value, DataType.Int4)

This is what I have so far. I have the set up the chart defaults, i just didn’t copy it.

for path in paths:

	newrow = default
	parts = path.split('/')
			
	newrow[0] = '/'.join(parts[-2:])
	newrow[1] = path
	newrow[6] = self.autoColorList[tagpens.rowCount % len(self.autoColorList)]
	newrow[13] = path.split('/')[-2]
	
	
	if system.tag.read("%s.DataType" %path).value == 'Boolean':
		newrow[3] = 'Bool'
		newrow[4] = 2
		newrow[14] = True
	
	tagpens = system.dataset.addRow(tagpens, tagpens.rowCount, newrow)
	
self.tagPens = tagpens

I’m using ignition 8.0.2. So I got the “system.tag.read(”[default]test.DataType").value" to work in the script console. However something not right with my “if” statement. When I use the “path” from the Easy Chart.

Edit:
So I was doing testing with the print command. I found out that
“system.tag.read(”%s.DataType" %path).value" work but only is the tag browse tree is set to real time tag tree, I believe its because the “path” is different when the tree is on Historical. But knowing this the if statement still doesn’t work.

for anyone else trying to get this to work, just figured it out:

  1. i’m using UDT structures and wanted the parent and child to show as pen tag names
  2. for ad-hoc tag dropping onto the chart, i wanted boolean tags to populate in a different subplot
	# Alter chart configuration  when dropping pens

	# Create the headers for dataset to write into tagPens on easy chart
	# headers = ["NAME", "TAG_PATH", "AGGREGATION", "AXIS", "SUBPLOT", "ENABLED", "COLOR", "DASH_PATTERN", "RENDER_STYLE", "LINE_WEIGHT", "SHAPE", "FILL_SHAPE", "LABELS", "GROUP_NAME", "DIGITAL", "OVERRIDE_AUTOCOLOR", "HIDDEN", "USER_SELECTABLE", "SORT_ORDER", "USER_REMOVABLE"]

	# get old pen data and append new info
	oldData = self.tagPens

	# get new info
	for path in paths:
		# get names for everything in the tag path
		closeBracketIndex = path.find("]")
		tagName = path[closeBracketIndex+1:]

		# get other custom configured tag pen data
		color = self.autoColorList[oldData.rowCount % len(self.autoColorList)]
		SubPlotNum = 1
		
		# set subplot option
		if isinstance(system.tag.read(path).value, bool):
			SubPlotNum = 2
			digital = "true"
		else: 
			SubPlotNum = 1
			digital = "false"

		# create the tag pen row 
		newData = system.dataset.addRow(oldData, [tagName,path,"MinMax","Default Axis",SubPlotNum,"true",color,"",1,1,0,"true","false","",digital,"false","false","true","false","true"])
				
	self.tagPens = newData
3 Likes