Keeping the same Trend every time I switch windows

I am trying to display a historical trend in a window. Every time I switch windows and return to the same window, I want to display the same historical trend that I had selected before switching windows and not the predefined trend . Can someone give me a hint about it? For your information I have used a Easy chart object. here is the link:

If you’re using the Vision Ad Hoc Trend Chart, I would suggest creating a Dataset client tag and a Dataset custom property on the window that is Bidirectionally bound to the client tag you created.

Then you’d add a propertyChange script to the Easy Chart object that runs on the “tagPens” property change and pushes the tagPens data into your custom property, which in turn would write to the tag. Example:

if event.propertyName == 'tagPens':
	event.source.parent.pathsDataset = event.source.tagPens

Where the pathsDataset is the custom property on the window.
(Note: I’d suggest grabbing your custom property from the property picker on the binding window to ensure that the path to the custom property is accurate.)

The last thing you’d need to do is push the data back into the tagPens data when the window opens. You can do this on an internalFrameActivated script on the window. Example:

# Ignition 8.0
system.gui.getParentWindow(event).getComponentForPath('PathToEasyChart').tagPens = system.tag.readBlocking(["[client]Trending/Persistent Tag Pens"])[0].value

# Ignition 7.9
system.gui.getParentWindow(event).getComponentForPath('PathToEasyChart').tagPens = system.tag.read("[client]Trending/Persistent Tag Pens").value

This should allow you to maintain the same trend throughout your client session.

Thanks for your answer. I will test yours suggestion ASAP.
Thanks

Hi KMuldoon;
Here what I did:

  1. I’ve created a tag:
    image

  2. I created a Custom property:


    which is biding to my tag:

  3. I’ve made the script in the window


    4.Finally, in internalframeactive

But, now NOT graphic are load:

Here is a picture of the bouton Load (after your suggest):

and before:
image

Here is te code inn the bouton Load:

database = “bdd_eurofloat”
hasCharts = 1
try:
chartCount = system.db.runPrepQuery("SELECT COUNT(*) FROM saved_graphs ",, database)
except:
hasCharts = 0

if not hasCharts or chartCount[0][0]<1:
system.gui.messageBox(“Aucun graphique enregistre n’existe actuellement. Utilisez le bouton d’enregistrement pour stocker le graphique actuel.”)
else:
database = “bdd”
username = system.security.getUsername()

names = []
funcs = []

privateNames = []
#privateFuncs = []

create = 0

try:
	charts = system.db.runPrepQuery("SELECT id, title FROM saved_graphs WHERE username = ?", [username], database)
	for row in charts:
		#cNames = ["Load", "Delete"]
		cNames = ["Charger"]
		if event.source.parent.databaseType == 'bdd':
			rowId=row["ID"]
		else:
			rowId=row["id"]
		def load(event, id=rowId):
			import system
			info = system.db.runPrepQuery("SELECT title, tagpens, axes FROM saved_graphs WHERE id = ?", [id], database)
			if len(info):
				chart = event.source.parent.getComponent('Easy Chart')
				chart.title = info[0][0]
				chart.tagPens = system.dataset.fromCSV(info[0][1])
				chart.axes = system.dataset.fromCSV(info[0][2])
				chart.updateMinMaxAvg()
		if event.source.parent.databaseType == 'bdd_eurofloat':
			rowId=row["ID"]
			rowTitle=row["TITLE"]
		else:
			rowId=row["id"]
			rowTitle=row["title"]
		def delete(event, id=rowId, title=rowTitle):
			import system
			if system.gui.confirm("Voulez-vous vraiment supprimer le graphique '%s'?" % title):
				system.db.runPrepUpdate("DELETE FROM saved_graphs WHERE id = ?", [id], database)
		cFuncs = [load]
	#	privateNames.append(rowTitle)
	#	privateFuncs.append([cNames, cFuncs])	
except:
	create = 1

publicNames = []
publicFuncs = []

try:
	charts = system.db.runPrepQuery("SELECT id, title FROM saved_graphs WHERE username IS NULL", [], database)
	for row in charts:
		#cNames = ["Load", "Delete"]
		cNames = ["Charger"]
		if event.source.parent.databaseType == 'bdd':
			rowId=row["ID"]
		else:
			rowId=row["id"]
			def load(event, id=rowId):
				import system
				info = system.db.runPrepQuery("SELECT title, tagpens, axes FROM saved_graphs WHERE id = ?", [id], database)
				if len(info):
					chart = event.source.parent.getComponent('Easy Chart')
					chart.title = info[0][0]
					chart.tagPens = system.dataset.fromCSV(info[0][1])
					chart.axes = system.dataset.fromCSV(info[0][2])
					chart.updateMinMaxAvg()
			if event.source.parent.databaseType == 'bdd':
				rowId=row["ID"]
				rowTitle=row["TITLE"]
			else:
				rowId=row["id"]
				rowTitle=row["title"]
			def delete(event, id=rowId, title=rowTitle):
				import system
				if system.gui.confirm("Voulez-vous vraiment supprimer le graphique '%s'?" % title):
					system.db.runPrepUpdate("DELETE FROM saved_graphs WHERE id = ?", [id], database)
			cFuncs = [load]
			publicNames.append(rowTitle)
			publicFuncs.append([cNames, cFuncs])
except:
	create = 1
	
names.append("Public")
funcs.append([publicNames, publicFuncs])
#names.append(username)
#funcs.append([privateNames, privateFuncs])

menu = system.gui.createPopupMenu(names, funcs)
menu.show(event, 0, 28)

Have you give some clue about this problem?

thanks!

It looks like where you're populating the publicNames and publicFuncs, there's an indenting error.

Blockquote
def load(event, id=rowId): <=== Right here onward

If you just move that entire section one indentation less to look like this,

publicNames = []
publicFuncs = []

try:
	charts = system.db.runPrepQuery("SELECT id, title FROM saved_graphs WHERE username IS NULL", [], database)
	for row in charts:
		#cNames = ["Load", "Delete"]
		cNames = ["Charger"]
		if event.source.parent.databaseType == 'bdd':
			rowId=row["ID"]
		else:
			rowId=row["id"]
		def load(event, id=rowId): # <===  Correction starts here
			import system
			info = system.db.runPrepQuery("SELECT title, tagpens, axes FROM saved_graphs WHERE id = ?", [id], database)
			if len(info):
				chart = event.source.parent.getComponent('Easy Chart')
				chart.title = info[0][0]
				chart.tagPens = system.dataset.fromCSV(info[0][1])
				chart.axes = system.dataset.fromCSV(info[0][2])
				chart.updateMinMaxAvg()
		if event.source.parent.databaseType == 'bdd':
			rowId=row["ID"]
			rowTitle=row["TITLE"]
		else:
			rowId=row["id"]
			rowTitle=row["title"]
		def delete(event, id=rowId, title=rowTitle):
			import system
			if system.gui.confirm("Voulez-vous vraiment supprimer le graphique '%s'?" % title):
				system.db.runPrepUpdate("DELETE FROM saved_graphs WHERE id = ?", [id], database)
		cFuncs = [load]
		publicNames.append(rowTitle)
		publicFuncs.append([cNames, cFuncs])
except:
	create = 1

you should start seeing the popup menu from button again.

Hi KMuldoon,
I’ve made your suggestion, here is a screenshot:

But the result is the same: NO trend load:

You will have another suggestion. Appreciate your help. Thank you

It looks like you moved over the whole section. Here’s what yours currently looks like.

Here’s the area I’d like to try and shift to see if it corrects the issue.

So after shifting, it should look like this.

I think this is happening because on line 64, the databaseType is being checked if it’s ‘bdd’. If it is ‘bdd’ then lines 68 through 89 will not be called, so the popup menu’s publicNames and publicFuncs will always be empty.

Hi KMuldoon,
I have made some modifications in the script as you said, however the selected trend was not maintained. So looking in detail, I have realized that an internal custom property was empty. So when I bind it to the correct expression, everything worked. Here is a screenshot:


And:

Now, the graph is maintained but not the name associated with each graph. I suppose I must do something similar to the mechanism that you have already explained to me. I will try and keep you informed.

I really appreciate your help, your solution is correct. Thanks again.