How to get a number on my dasboard instead of a string

Hello,

I can get data out of my database but when i display it in my gauge i get a string. How could i get a number instead of a string? Also im getting my data in a array out of my database.


image

While 'a picture is worth a thousand words' is true most of the time, in this case, a copy of your flow would give more information.

also what does the debug node show?

This is the output of my flow
image

[{"id":"434c8281.163c2c","type":"MSSQL","z":"c8a025bb.cf5478","mssqlCN":"302f4b9a.eb6754","name":"Database Plenion","query":"","outField":"payload","x":570,"y":140,"wires":[["c0c7cf9d.781f8","d49ed4b2.c82a18"]]},{"id":"302f4b9a.eb6754","type":"MSSQL-CN","z":"","name":"localhostpleniondata","server":"localhost","encyption":true,"database":"PlenionData"}]

and the export of the flow??

There is a flow there

What you added to that post only the mssql node not the complete flow.

It is indeed the full flow that i use

what you posted as your flow is only the mssql node. When you did the export, at the top of the window it has three choices

  • selected nodes
  • current flow
  • all flows
    the default is selected nodes, you should choose current flow
[{"id":"c8a025bb.cf5478","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"8095f328.b0aa7","type":"ui_gauge","z":"c8a025bb.cf5478","name":"","group":"dfaa887.1429078","order":1,"width":0,"height":0,"gtype":"gage","title":"New Client requests","label":"","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1200,"y":200,"wires":[]},{"id":"5699253a.ce38cc","type":"MSSQL","z":"c8a025bb.cf5478","mssqlCN":"565085c1.c65bcc","name":"Database Plenion","query":"","outField":"payload","x":770,"y":200,"wires":[["61840ed6.9a7a9","83a96980.17a7b8"]]},{"id":"5de0d118.7af75","type":"inject","z":"c8a025bb.cf5478","name":"Select statement New client requests","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"SELECT count(*) FROM Req WHERE Volgendestap_rqv = '33827'","payloadType":"str","x":430,"y":200,"wires":[["5699253a.ce38cc"]]},{"id":"61840ed6.9a7a9","type":"debug","z":"c8a025bb.cf5478","name":"Debug data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":140,"wires":[]},{"id":"83a96980.17a7b8","type":"function","z":"c8a025bb.cf5478","name":"","func":"/* //read payload\nvar stringValue = msg.payload;\n\n//convert string to float to 2 decimal places\nvar floatValue = parseFloat(stringValue).toFixed(2);\n\n//set and return payload\nmsg.payload = floatValue;\nreturn msg;*/\n\n\nmsg.payload = Number(msg.payload);\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":200,"wires":[["8095f328.b0aa7"]]},{"id":"dfaa887.1429078","type":"ui_group","z":"","name":"chart","tab":"8e6de17b.7c4dc","order":1,"disp":true,"width":"6","collapse":false},{"id":"565085c1.c65bcc","type":"MSSQL-CN","z":"","name":"DatabasePlenion","server":"10.100.0.100","encyption":true,"database":"PlenionData"},{"id":"8e6de17b.7c4dc","type":"ui_tab","z":"","name":"Dashboard Silicon","icon":"description","disabled":false,"hidden":false}]

The data from your database request is an array, containing one object but is formatted kind of bad way.

image

Object key is empty string.

You can get the value of course even if it is that strange formatted.

With function node you can parse the value like this.

msg.payload = msg.payload[0][""]
return msg;

But that data formatting looks to me bad enough. So maybe you can figure out why it is formatted that way.

2 Likes

Thanks! This is what i needed, yeah the data is formatted bad because in my query i use a count.

Of course in a function node... you could always use the Javascript Number() function to actually convert a string to a numeric valve. Just say this for reference. But in this case, the issue was bit more involved. :slight_smile:

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