Stacked Easy Charts and Tag Browse Tree

I want to have two or more stacked Easy Charts that share the same time axis and allow pens to be dragged in from the Tag Browse Tree to any of the charts. I can't use sub plots because they only allow tags to be added to the first plot from the Browse Tree.

I thought I would use two separate Easy Charts but the Pens Control box resizes depending on the tags added and this resizes the chart area so that it no longer matches the other chart. I don't want to hide the Pen Control box because I want operators to be able to hide or remove pens as needed.

Any tips?

Use subplots. Override the onTagsDropped method to handle the pen placement yourself.

2 Likes

I have recently done this exact thing. I used a template repeater to hold the charts. I stored each chart to a udt tag and each repeaters template data to tags as well. I used a Tree View instead of the Tag Tree object and wrote custom functions to load the tags into the charts. Syncing the times is the hardest part as you need to write the times out to the repeater Template Parameters and then handle the property change on the chart template itself. If you receive the change on the originating chart, you don't want to fire it's property change again. This is not an easy task.

Not true, you just have to override the onTagsDropped method as @pturmel says.

Subplots is definitely the way to go.

Thanks everyone! I guess my next task is to figure out how to override methods in Ignition...

It's easy. Just right click on the chart and select scripting. Then, enable the onTagsDropped extension function.
image

You will need to develop a script that looks something like this:

#def onTagsDropped(self, paths):
	def setColor(row):
		colors = ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'brown', 'cyan', 'magenta']
		colorIndex = row % len(colors)
		return colors[colorIndex]
	def setPlot():
		WEIGHT = 1
		OVERRIDE_BACKGROUND = True
		BACKGROUND_COLOR = system.gui.color(setColor(self.subplots.rowCount))
		subplotData = [WEIGHT, OVERRIDE_BACKGROUND, BACKGROUND_COLOR]
		self.subplots = system.dataset.addRow(self.subplots, self.subplots.rowCount, subplotData)
	def setTag(path):
		NAME = path.split('/')[-1]
		TAG_PATH = path
		AGGREGATION_MODE = 'MinMax'
		AXIS = 'Default Axis'
		SUBPLOT = self.tagPens.rowCount
		ENABLED = True
		COLOR = system.gui.color(setColor(self.tagPens.rowCount + 1))
		DASH_PATTERN = ''
		RENDER_STYLE = 1
		LINE_WEIGHT = 1
		SHAPE = 0
		FILL_SHAPE = True
		LABELS = False
		GROUP_NAME = ''
		DIGITAL = False
		OVERRIDE_AUTOCOLOR = True
		HIDDEN = False
		USER_SELECTABLE = True
		SORT_ORDER = ''
		USER_REMOVEABLE = False
		tagData = [NAME, TAG_PATH, AGGREGATION_MODE, 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_REMOVEABLE]
		self.tagPens = system.dataset.addRow(self.tagPens, self.tagPens.rowCount, tagData)
	newPlot = []
	for path in paths:
		setPlot()
		setTag(path)
1 Like

Wow, thanks so much guys. I'll have a play over the next few days and let you know how I get on.

1 Like

Thanks again for this. I tweaked the code @justinedwards.jle posted and now the chart checks the data type of the pens as they are dropped and puts Booleans on sub plot 2 and everything else on the sub plot 1. Works great :slight_smile:

def onTagsDropped(self, paths):
		
	def setColor(row):
		colors = ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'brown', 'cyan', 'magenta']
		colorIndex = row % len(colors)
		return colors[colorIndex]
	
	def setTag(path):
		NAME = path.split('/')[-1]
		TAG_PATH = path
		AGGREGATION_MODE = 'MinMax'
		AXIS = 'Default Axis'
		tagValue = system.tag.read(path).value
		dataType = type(tagValue).__name__
		if dataType == "bool":
			SUBPLOT = 2
		else:
			SUBPLOT = 1
		ENABLED = True
		COLOR = system.gui.color(setColor(self.tagPens.rowCount + 1))
		DASH_PATTERN = ''
		RENDER_STYLE = 1
		LINE_WEIGHT = 1
		SHAPE = 0
		FILL_SHAPE = True
		LABELS = False
		GROUP_NAME = ''
		DIGITAL = False
		OVERRIDE_AUTOCOLOR = True
		HIDDEN = False
		USER_SELECTABLE = True
		SORT_ORDER = ''
		USER_REMOVEABLE = True
		tagData = [NAME, TAG_PATH, AGGREGATION_MODE, 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_REMOVEABLE]
		self.tagPens = system.dataset.addRow(self.tagPens, tagData)
	
	for path in paths:
		setTag(path) 
2 Likes