Bit of an odd question but I had to make some changes to a db reference. Which worked fine however, now when I bind a sparkline to the desired ranges the little green background isn't showing up but if I hard code the number into there it does. I noticed when I bind the db reference it returns the number in green characters. However, if I hard code a number it shows up in yellow and when I do it that way the sparkline functions correctly. Here is a picture to illustrate what I mean. You see desiredHigh and Low showing up in green.
![binding](https://global.discourse-cdn.com/inductiveautomation/original/3X/9/b/9bad06c94c66e68b3195e03307624e9f7dcd5b6c.png)
Anyone know how I can fix this
This is a hint as to what type the internal JSON element is.
Green means "this is a string", even if it looks like a number.
Yellow means "this is a number".
Is there any way I can force it to a number
Can you show your binding?
If it's e.g. a named query binding, it's going to be whatever your column type is.
If you want to coerce it to a number, the best place to do that is in your SQL query, but if you can't do that for whatever reason you could add a transform that uses the toDouble
expression function.
Basically I do the binding in a tag. Its a simple select * from table. And then this is the binding:
tag('[OPC1]dbTables/current/Table1')[0,21]
Digression: If you're not assembling a dynamic tag path, you don't need (and shouldn't use) the tag
expression function - just put the path you want to reference in curly braces and it'll be automatically read/subscribed to:
{[OPC1]dbTables/current/Table1}[0,21]
That aside, the column type in your dataset will be whatever the column type is coming back as from the DB.
So, again - the best option is to fix it in the DB. If it's coming back as a string, that strongly suggests the DB's column type is string, which is basically always wrong for numeric data.
The second best option is to coerce in your query, so instead of SELECT *
use SELECT x, y, someCoercionFunctionToFloat(z) as z
.
The third best (also known as worst option
) is to update your expression to do explicit coercion:
toDouble({[OPC1]dbTables/current/Table1}[0,21])
2 Likes
Ok this makes perfect sense. Thank you. I will make my corrections