# Keeping the same Trend every time I switch windows

**URL:** <https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296>\
**Category:** General Discussion\
**Created:** [July 2, 2020, 1:57pm UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296 "2020-07-02T13:57:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Icom](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@Icom](https://forum.inductiveautomation.com/u/Icom)\
**Post date:** [July 2, 2020, 1:57pm UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/1 "2020-07-02T13:57:22Z")

</div>

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:

> **[Ignition Exchange](https://inductiveautomation.com/exchange/92/overview)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

---

<div class="post-metadata">

**Author:** ![KMuldoon](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@KMuldoon](https://forum.inductiveautomation.com/u/KMuldoon)\
**Post date:** [July 2, 2020, 3:55pm UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/2 "2020-07-02T15:55:53Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/6/469f5e672c142e13ad0a61c977eca15260ec6137.png)

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:

```auto
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:

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![Icom](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@Icom](https://forum.inductiveautomation.com/u/Icom)\
**Post date:** [July 3, 2020, 1:12pm UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/3 "2020-07-03T13:12:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Icom](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@Icom](https://forum.inductiveautomation.com/u/Icom)\
**Post date:** [July 4, 2020, 4:17am UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/4 "2020-07-04T04:17:10Z")

</div>

Hi KMuldoon;  
Here what I did:

1. I’ve created a tag:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e2f73966882747d63bbf088a4bf49acfce4f9cb6.png)

2. I created a Custom property:  

3. I’ve made the script in the window  

But, now NOT graphic are load:

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/f/ef8e83fdb2b12c9c4204b3050b41e8dbaf9da153.png)

and before:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4d362dcf559d6bda1ec08176614318d8880cc0cb.png)

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!

---

<div class="post-metadata">

**Author:** ![KMuldoon](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@KMuldoon](https://forum.inductiveautomation.com/u/KMuldoon)\
**Post date:** [July 8, 2020, 6:46pm UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/5 "2020-07-08T18:46:47Z")

</div>

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,

```auto
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.

---

<div class="post-metadata">

**Author:** ![Icom](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@Icom](https://forum.inductiveautomation.com/u/Icom)\
**Post date:** [July 9, 2020, 8:34am UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/6 "2020-07-09T08:34:48Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e023704c183c8d214c7f73972f926a045287774a.png)

But the result is the same: NO trend load:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/2556f30c6962e139bfcb5b58ab7ebbd10b407949.png)

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

---

<div class="post-metadata">

**Author:** ![KMuldoon](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@KMuldoon](https://forum.inductiveautomation.com/u/KMuldoon)\
**Post date:** [July 9, 2020, 4:37pm UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/7 "2020-07-09T16:37:13Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/b/0bbe5fce44e4135d355930e800a7121e95f999a3.png)

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/9/a9db762b04961b5ecede192ecddffb12a6c8258a.png)

So after shifting, it should look like this.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e354473a63745873d297e55ce962c74c45710bee.png)

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.

---

<div class="post-metadata">

**Author:** ![Icom](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@Icom](https://forum.inductiveautomation.com/u/Icom)\
**Post date:** [July 10, 2020, 11:31am UTC](https://forum.inductiveautomation.com/t/keeping-the-same-trend-every-time-i-switch-windows/36296/8 "2020-07-10T11:31:27Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3c8d7d8d61ea9c7cf31a41e8e8377c23bd8379aa.png)  
And:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/1/71f40ea8668f628a0a9b94a2b671ff0e1a32b64f.png)

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.
