Custom Chart how to get CTX variables?

Hi there,
reading the documentation

but how do I reference it in the JS code?

In the provided example:

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

ctx refers to the canvas not the actual context variables.


You are conflating JavaScript’s getContext() method 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 …

DashboardBlock.on('change', (event) => {