How about conditional colors for a data point based on a range? I’m working on an app ratings dashboard, so the range would be between 1 - 5 stars going from Red to Green.
measure: your_1_to_5_measure {
type: average
sql: ${name_of_field} ;;
html:
{% if value < 2.5 %}
<p style="color: red; text-align:center">{{ rendered_value }}</p>
{% else %}
<p style="color: green; text-align:center">{{ rendered_value }}</p>
{% endif %};;
}
I’m assuming this measure is an average.
…you could also do something like this if you want a range of colors
measure: your_1_to_5_measure {
type: average
sql: ${retail_price} ;;
html:
<p style="color:
{% if value < 2 %}red
{% elsif value < 3 %}pink
{% elsif value < 4 %}lightgreen
{% else %}green
{% endif %}
; text-align:center">{{ rendered_value }}</p>
;;
}
HTML ignores whitespace so you can put the logic right inside the style tag.
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.