# Global name 'chart' is not defined

**URL:** <https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 30, 2023, 9:24pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801 "2023-06-30T21:24:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Roberto\_Canales](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jose\_Roberto\_Canales](https://forum.inductiveautomation.com/u/Jose_Roberto_Canales)\
**Post date:** [June 30, 2023, 9:24pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/1 "2023-06-30T21:24:01Z")

</div>

I am having problems trying to trigger a data source through a button event to load different data to a chart.how to reference the time chart component and fill it according to the button clicked

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/a/ca841b58350a908828aaf3e4cfe03ed9271b7187.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/4/348fb718ffb7f0974697c5827caa3b5f4c49f320.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c543584a825f06245112687b7e6a0ed2886ed9b9.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 30, 2023, 9:37pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/2 "2023-06-30T21:37:33Z")

</div>

It's not clear what your "Week" button is supposed to do. If the Configure Script Action screen grab is the button event then it just runs the same query every time.

What are you hoping it will do?  
Shouldn't the query be modified with a parameter?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 1, 2023, 6:30pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/3 "2023-07-01T18:30:28Z")

</div>

Instead of getting and setting the data from the button, you can bind the chart's data to the named query, set it not poll, and use the button instead to refresh the chart's data binding (`chart.refreshBinding('props.data')`). Not always what you want, but sounds like it's what you might be after here. Not sure why you're getting the variable error though.. Can you paste the actual error with full context?

---

<div class="post-metadata">

**Author:** ![Jose\_Roberto\_Canales](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jose\_Roberto\_Canales](https://forum.inductiveautomation.com/u/Jose_Roberto_Canales)\
**Post date:** [July 3, 2023, 4:00pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/4 "2023-07-03T16:00:46Z")

</div>

> [@Transistor](#):
>
> It's not clear what your "Week" button is supposed to do. If the Configure Script Action screen grab is the button event then it just runs the same query every time.
> 
> What are you hoping it will do?  
> Shouldn't the query be modified with a parameter?

Hi.  
Each button should update the graph with a different query, per day, per week and per month,  
they are two tables with completely different structures, that's why I don't use the parameter, I will use it when filtering the 4 options that I have on the left side.

---

<div class="post-metadata">

**Author:** ![Jose\_Roberto\_Canales](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jose\_Roberto\_Canales](https://forum.inductiveautomation.com/u/Jose_Roberto_Canales)\
**Post date:** [July 3, 2023, 4:11pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/5 "2023-07-03T16:11:02Z")

</div>

Hi.

the button actually goes in the top menu, I have the structure defined as shown on the left side, i check the documentation:  
[https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods](https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods)

this is the error that I get:  
line 3, in runAction NameError: global name variable is not defined ignition

I will try to do what you said

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 3, 2023, 10:15pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/6 "2023-07-03T22:15:55Z")

</div>

Oh, so you just typed that `self.getSibling` part, you didn't use the property selector to select it? If the chart and button components are in different views, then you can't get object references to the other. You'll need to send a message to the other view using `system.perspective.sendMessage`, and have a message handler on a component in your other view to then modify the chart

---

<div class="post-metadata">

**Author:** ![Jose\_Roberto\_Canales](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jose\_Roberto\_Canales](https://forum.inductiveautomation.com/u/Jose_Roberto_Canales)\
**Post date:** [July 4, 2023, 8:27pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/7 "2023-07-04T20:27:04Z")

</div>

Both are inside the same view but in different containers

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 5, 2023, 12:29pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/8 "2023-07-05T12:29:02Z")

</div>

> [@Jose\_Roberto\_Canales](#):
>
> but in different containers

In the screen grab you posted it shows them in the same container. Now you're saying that they are in different containers. The same code will not work in both structures.

Show the actual structure and code that is producing this error, and if you didn't use the property selector to get the correct path to the component, do that.

---

<div class="post-metadata">

**Author:** ![Jose\_Roberto\_Canales](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jose\_Roberto\_Canales](https://forum.inductiveautomation.com/u/Jose_Roberto_Canales)\
**Post date:** [July 5, 2023, 10:42pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/9 "2023-07-05T22:42:26Z")

</div>

I refer to the FlexContainers, in the same way I could already make the change, now I will only configure a script that receives a parameter and can update the graph.

def runAction(self, event):  
self.view.getChild("root/CenterFlexContent/FlexContainer\_1/MainTimeSeriesChart").props.title.text = 'Weekly OEE'  
data = system.db.runNamedQuery("WeekOEE")  
self.view.getChild("root/CenterFlexContent/FlexContainer\_1/MainTimeSeriesChart").props.series[0].data = data

Tank you.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 5, 2023, 10:51pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/10 "2023-07-05T22:51:42Z")

</div>

When posting code, select the code and use the \</\> button to format it. Hit the pencil icon below your post and try it out.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 5, 2023, 10:55pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/11 "2023-07-05T22:55:52Z")

</div>

> [@Jose\_Roberto\_Canales](#):
>
> I refer to the FlexContainers, in the same way I could already make the change

I’m sorry, but this doesn’t make any since to me.

Is this script that you provided also resulting in an error? If so what is the full error trace?

---

<div class="post-metadata">

**Author:** ![Jose\_Roberto\_Canales](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jose\_Roberto\_Canales](https://forum.inductiveautomation.com/u/Jose_Roberto_Canales)\
**Post date:** [July 5, 2023, 11:26pm UTC](https://forum.inductiveautomation.com/t/global-name-chart-is-not-defined/75801/12 "2023-07-05T23:26:35Z")

</div>

No, this script works fine.
