Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Expression manager color table according to calculation

  • Laurauab
  • Laurauab's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 months ago #226806 by Laurauab
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.2.11+220124
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hello,

I need to include a table in my pdfreport and I would like to know if it is possible to change the background color of a cell based on the result of a mathematical calculation. The calculation would be {100-(v221+v222-2)*(100/8)}, where v221 and v222 are variables from the associated survey.

Would it be something like this?

          </td>
             <td {if(100-(v221+v222-2)*(100/8)lt12.5, style="background-color:green",
                  if(100-(v221+v222-2)*(100/8)lt25, style="background-color:yellow",
                  if(100-(v221+v222-2)*(100/8)gt25, style="background-color:red"
                   )))}>
          </td>

Thanks so much in advance,
Laura"
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226810 by Joffm
Without having a look at the rest (lack of time)
your syntax is wrong
You know the IF-statement is like this: if(condition==TRUE,"Do this","Do that")
so your "style" has to be surrounded by quotes, like
 {if(100-(v221+v222-2)*(100/8)lt12.5,' style="background-color:green"',...

And as the calculation is always the same you may do it in an equation "eqCalc" before
 {if(eqCalc lt 12.5,' style="background-color:green"',...

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Laurauab
  • Laurauab's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 months ago - 3 years 2 months ago #226812 by Laurauab
Thank your for your response Joffm.

By just surrounding with quotes the "style", it's not working (it turns red...)

 


Thank you for your time
Last edit: 3 years 2 months ago by Laurauab.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226817 by tpartner
Simplify it (line-breaks inserted for clarity):

Code:
<td style="background-color:{if(100-(v221+v222-2)*(100/8) lt 12.5, 'green',
              if(100-(v221+v222-2)*(100/8) lt 25, 'yellow',
              if(100-(v221+v222-2)*(100/8) gt 25, 'red', 'transparent')))}">
</td>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Laurauab

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226820 by Joffm
Hi,
as I said, I only looked at your syntax, not at the logic.

But you misunderstood.

I wrote

so your "style" has to be surrounded by quotes

Your style was
style="background-color:green"
 and surrounded by quotes it is
' style="background-color:green"',
Because you can't nest quotes you have to use single quotes to surround double quotes and viceversa.
As you see in tpartners example.

But beware: The inline editor sometimes gets confused about this. So it is better to use the HTML source editor.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Laurauab

Please Log in to join the conversation.

  • Laurauab
  • Laurauab's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 months ago #226821 by Laurauab
It worked!!!!!
Thank you soooooo much!!!!

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 2 months ago #226835 by DenisChenu
Don't use question text but dedicated Pdf content.

1: No HTML editor
2: No xss

gitlab.com/SondagesPro/ExportAndStats/pd...6d2b64881162e6907617

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose