Pass segment values to DB2 chart widget

I’ve read in the documentation on the DB2 Gauge widget where you can pass the segment values via msg.ui_update.sectors using an array: [{ "start": 0, "color": "green"}, { "start": 5, "color": "skyblue"}]

I’m using a Change widget to pass other dynamic properties but can’t seem to get the segment values to work. What value type do I use for the array? Also, I need to pass this array where I’m using flow vars:

[{ "start": flow.PAVoltage.low, "color": "yellow"}, { "start": flow.PAVoltage.hi, "color": "red"}]

Can you show us where you read that? The help text says that it should be msg.ui_update.segments and the data should be `[{ "from": 0, "color": "green"}, { "from": 5, "color": "skyblue"}]

Or perhaps you are not using the core DB2 gauge but the classic gauge. If so then feed the message you are sending into a degug node set to Output Complete Message and show us what it contains.

For accessing flow variables you should use flow.get(), so for that case it should possibly be [{ "start": flow.get("PAVoltage").low, "color": "yellow"}]

I’m using the DB2 Classis Gauge. I’m reading the documentation at this link:
@colinl/node-red-dashboard-2-ui-gauge-classic
Under section Dynamic Properties, Sectors

When I use “flow.get("PAVoltage").low” in the Change widget to set msg.ui_update.sectors, which type of value do I select it is? It does not work if I select String, JSON or J:?

In the change node select J: and to use a flow context var use

$flowContext("PAVoltage")

There is a list of available functions in the JSONata editor dialogue

Since the flow vars are PAVoltage.low and PAVoltage.hi, should I use $flowContext(“PAVoltage.low”) instead?

Yes, try it.

Or you can assign a var to the context object

($PAVoltage := $flowContext("PAVoltage);
    [
        { "start": $PAVoltage.low, "color": "yellow"},
        { "start": $PAVoltage.hi, "color": "red"}
    ]
)

I don't use JSONata except for very simple operations, so I would do it in a Function node using

msg.ui-update = [{ start: flow.get("PAVoltage").low, color: "yellow"},...]

@E1cid … ok I confirmed with Debug widget I am successfully passing the array to the Gauge widget but for some d**m reason it is not using it.

{"valueDecimalPlaces":"1","min":0,"sectors":[{"start":10.5,"color":"yellow"},{"start":15,"color":"red"}],"max":17}

What’s even more strange is in the above array… the min and max values are being displayed but the array and valueDecimalPlaces are not.

Should the sectors start at 0. @colin is the author/maintainer of the node, so he's the man who should know.

I was trying to keep it simple (lol) by using the Change widget but have no objection switching to the Function. Any idea why the valueDecimalPlaces is not being accepted (displays 2 digits)?

Try it with a number instead of a string, though it was sloppy of me if I don't allow a string.

If your brain can cope with JSONata then that is fine. Mine can't easily which is why I generally use functions.

Also make sure you are using the latest version of the node (1.4.0)

@Colin confirmed I am running v1.4.0… ok I’m having major brain farts today… here is the code in my Function

let sector1 = flow.get("PAVoltage.low");
let sector2 = flow.get("PAVoltage.hi");
let msg.ui_update = {};

msg.ui_update.valueDecimalPlaces = 1;
msg.ui_update.min = 0;
msg.ui_update.max = 17;
msg.ui_update.sectors = [
    { "start": sector1, "color": "yellow" },
    { "start": sector2, "color": "red" }
];
return msg;

When I run this, I’m now getting TypeErrors on all the ui_update. What am I overlooking?

Take off the let. msg already exists
msg.ui_update = {}

Also generally you don't need semicolons on the end of lines. They don't do any harm though, just wear on the fingers and keyboard.

If it still doesn't work feed the output into a debug node set to Output Complete message and show us what it says. Expand the objects in there.

Ok here is the output from Debug

{
"topic":"RAD/334/+13.8A",
"meter":4,
"payload":13.49,
"_msgid":"a6fc84d983db3836",
"ui_update":{
"valueDecimalPlaces":1,
"min":0,
"max":17,
"sectors": [{"start":10.5,"color":"yellow"},{"start":15,"color":"red"}]
}
}

Using this output, the gauge widget does display min & max but the sectors and decimal places are not being shown correctly

I guess me using semicolons shows how long I’ve been using NR :joy:

@Colin … on a somewhat related subject. In the documentation concerning Configuration, Sectors, it states that

The colours may be recognised names such as "red" or "skyblue" or may be numerically specified

Where do you enter the color names? When I click on the color on the left, I’m only able to enter RGB values