# Custom Chart how to get CTX variables?

**URL:** <https://forums.losant.com/t/custom-chart-how-to-get-ctx-variables/4769>\
**Category:** Help\
**Tags:** custom-chart-block\
**Created:** [October 12, 2022, 11:11am UTC](https://forums.losant.com/t/custom-chart-how-to-get-ctx-variables/4769 "2022-10-12T11:11:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [October 12, 2022, 11:11am UTC](https://forums.losant.com/t/custom-chart-how-to-get-ctx-variables/4769/1 "2022-10-12T11:11:48Z")

</div>

Hi there,  
reading the documentation

> - `ctx.<variableName>` - The value of any [context variable](https://docs.losant.com/dashboards/context-variables/) on your dashboard.

but how do I reference it in the JS code?

In the provided example:

```auto
var ctx = document.getElementById('myChart').getContext('2d')

```

ctx refers to the canvas not the actual context variables.

Cheers.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [October 12, 2022, 2:47pm UTC](https://forums.losant.com/t/custom-chart-how-to-get-ctx-variables/4769/2 "2022-10-12T14:47:17Z")

</div>

You are conflating [JavaScript’s `getContext()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext) for HTML canvas elements with Losant dashboard context. The two concepts are unrelated despite sharing a similar name.

The example content when you first add a Custom HTML Block to a dashboard illustrates pretty well how to read the values of queries, dashboard context variables, and the dashboard object itself, both on initial mount and on value changes (emitted through events.

`DashboardBlock.input.ctx.<ctxVariableName>` will give you the value of a given context variable on initial mount, and those same values are exposed as the argument to events emitted by the dashboard - such as …

```javascript
DashboardBlock.on('change', (event) => {
  console.log(event.ctx.<variableName>);
});
```
