Change dashboard chart title dynamically

Hi everyone,
I'm desperately trying to dynamically set the title of a dashboard chart.
I have a dashboard with several charts that are periodically updated with data from a DB, everything works fine.

I would like to set the title of the chart with the information of the last update timestamp, something like:

Laser PowerMeter measure [W] @[2020-03-06 13:50:59]

First of all I've set the "Label" field in the "Edit chart" node GUI as:

Laser PowerMeter measure [W] @[{{msg.last_check}}]

and I've provided as input:

var alert_threshold_low = flow.get('alert_threshold_low');
var alert_threshold_high = flow.get('alert_threshold_high');

var data_name = []
var data_val = []

for (ind = 0; ind < 3; ind++)
{
    data_name[ind] = msg.payload[ind].topic
    data_val[ind] = msg.payload[ind].payload
}

msg.payload =   [{
                series: data_name,
                data: data_val
                }]
                
msg.ui_control = {"ymin":alert_threshold_low, "ymax":alert_threshold_high}

msg.last_check = flow.get("last_check");

return msg

Results:

  1. At first injection the title is correctly updated to:
    Laser PowerMeter measure [W] @[2020-03-06 13:50:59]
  2. But if I refresh the page the title goes back to the "unitialized" state:
    Laser PowerMeter measure [W] @[]

I've tryed the weirdest solutions for the title such as:

  1. Laser PowerMeter measure [W] @[{{flow.get(last_check)}}]
  2. Laser PowerMeter measure [W] @[{{context.flow.last_check}}]

with of course no results.

Setting the title directly from msg.ui_control its not possible directly. Maybe it can be achieved digging in the msg.ui_control.options fiels, nut I was not able to do that (source github).

Does exist some other solution or workaround?

Thanks

Sould be msg.ui_control.options.title.text
https://www.chartjs.org/docs/latest/configuration/title.html

Thanks for the super fast reply @hotNipi.

Unfortunately I'v digged too in chart.js documentation and I've tried

msg.ui_control = {
  "ymin": 18,
  "ymax": 26,
  "options": {
    "title": {
      "text": "xxxxxxxxx"
    }
  }
}

leaving the GUI title form empty, without any success.

Oh yes, the thing you want to change is the chart node's label.
I dont know if it has any dynamic control options, the config-fields document says NO.
@dceejay maybe can say something more solid about it...

it's fixed in master...

2 Likes

So the only way to change it is using the GUI editor?

I've tried also to insert in the GUI form:

Laser PowerMeter measure [W] @[{{msg.last_check}}]

it works when the node in injected, as I've said, but refreshing the page resets the msg.last_check parameter.

Currently yes.

As it is made possible already in git, you can install the dashboard from git.
Or you can wait for next release of dashboard....

Note - it still requires a refresh of the browser to update - it is not 100% dynamic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.