Image color based on value from a dataset

Hi All, I am sure this has been addressed somewhere on the forum, but I didn’t find it…

I have a container with various controls in it. There is a dataset also associated with the container, with about 20 columns (just one row). I would like to use the value in one column (age) to change the color of an image in the container, but I don’t seem to be able to bind to a specific cell in the dataset through the property binding – property screen. I get an error "Property ‘dsTankData[0,15]’ not defined or not bindable for component ‘cnt801’. I browsed to Root Container.cnt801.dsTankData from within the property binding pop up, then added “[0,15]” after that to signify the first row, 15th column, just as one would do in a script module. No luck.

Next I tried to use an expression thusly: I created an integer dynamic property on the container, then tried to assign its value to the 0,15 of the dataset. I simply typed {Root Container.cnt801.dsTankData}[0,15]. The error this time was "The type of this expression (Object) is not assignment-compatible with the type of the property you are binding to (Integer).

I also looked at using dynamic styles (is that what they are called?) but had no luck with the same kind of binding…

Hmmm. What did I miss? TIA David

You were so close. Use the expression binding on the dynamic property, and cast it to an integer, like this:

toInt({Root Container.cnt801.dsTankData}[0,15])

You can then use another binding or the Styles feature to affect a color.


Now, to change the ‘tank color’ property of my tank, I tried:

if({Root Container.cnt801.intAge}>21,“0,124,0,255”,“0,0,0,0”)

but it didn’t like what it saw to be a string. Actually what I would like to do is if intAge is >25, make it black, between 17 and 25 make it yellow, and between 13 and 17 make it green.

I thought in the worst case a switch statement with all the possible values for intAge listed might work, but it seems messy, and there will inevitably be an intAge that isn’t caught… Thanks.

If you want to use an Expression binding you’ll have to use the Color

if({Root Container.cnt801.intAge}>21,color(0,124,0,255), color(0,0,0,0)) 

You probably want to use styles - that will allow you to control all properties with flexible states. In your example you only have to create states for 0 (white), 13 (green), 17 (yellow), and 25 (black).

If the driving property values aren’t flexible enough, create an integer dynamic property bound to an expression that encapsulates your logic.


It’s the casting that’s messing you up! “0,255,0,255” is not recognized as a color in the expression language so you have to cast it like this:if({Root Container.cnt801.intAge}>21,color(0,124,0,255),color(0,0,0,0))
Now if you like to read EVERY post on the forums (but I’ll just copy it here), there’s one about using a switch statement and binEnum() to get statements into your expression.

switch( binEnum({value}>25, {value}>17, {value}>13) 1,2,3, color(0,0,0,255), //black color(255,255,0,255), //yellow color(0,255,0,255), //green color(255,255,255,255)) //default
Or, like Nathan said as I was typing this, you could use styles.

Hi Robert: That was what I was thinking of. I tried the following:

switch( binEnum({Root Container.cnt801.intAge}>25, {Root Container.cnt801.intAge}>17, {Root Container.cnt801.intAge}>13) 1,2,3 color(0,0,0,255), //black color(255,255,0,255), //yellow color(0,255,0,255), //green color(255,255,255,255))

but got a syntax error on Token: ‘Integer const’ (line 5, char 1)
which is the line with 1,2,3 on it…

I tried the styles part, but where I hit a snag was that the hierarchy of objects is as follows: Root Container>>cnt801>>imgTank. I am trying to change the Tank Color property based on the value of intAge. However, intAge is on the cnt801 container, and is not available as a driving property for imgTank – for that my only choices were ‘Capacity’, ‘Data Quality’ and ‘Value’…

So, I am happy to use the switch statement above, but any advice as to why that syntax error… thing occurred?? thanks.


You are missing a comma.

binEnum({Root Container.cnt801.intAge}>25,
{Root Container.cnt801.intAge}>17,
{Root Container.cnt801.intAge}>13)

1,2,3, //<— here after the 3

color(0,0,0,255), //black
color(255,255,0,255), //yellow
color(0,255,0,255), //green
If you want to use the intAge in your style, you can just make another dynamic property and bind it to the one on the container.

Thanks. Two missing commas, actually.

Here is the correct snippet:

  binEnum({Root Container.cnt801.intAge}>25, 
          {Root Container.cnt801.intAge}>17, 
          {Root Container.cnt801.intAge}>13) 

1,2,3,  //<--- here after the 3 

color(0,0,0,255),           //black 
color(255,255,0,255),       //yellow 
color(0,255,0,255),         //green 

Styles are mo’ betta - really!

Ack! Don’t use a switch expression to bind a color to a number. Even Styles is overkill for this. Just bind the color to the number using a property binding - there is a nice number-to-color translation map there for you!