Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
kanhomcake
Contributor III
Contributor III

Bar Chart - Set Text Color Based on Background Color or Vice Versa


hi Community,

I want to set Text Color of bar chart conditionally based on the Background Color of the bar chart. For example, if the Background Color is black the Text Color should be white, or if the Background Color is yellow the Text Color should be black. Basically, I want to set the Text Color to be in-contrast with the Background Color.

Anyone knows how to do it, please kindly share your stuff.

Many thanks in advance for any reply

Regards,

WV

8 Replies
jvishnuram
Partner - Creator III
Partner - Creator III

Hi Veera,

You can achieve this in the text color option in the chart priperties., PFA hope it will helps you.

datanibbler
Champion
Champion

Hi Wannita,

just make the text_colour dependent of the same expressions as the background_colour - using the property_dialog, as Vishnu suggested. I would suggest setting those things in the expression_properties, not on the "colours" tab - makes no difference for yourself, but if you have all settings "in one place", it makes your entire qvw easier for others to understand...

kanhomcake
Contributor III
Contributor III
Author

yes, but how can you get the Background Color value to make the condition? Example below

if (BackgroundColor() = black(), white(), blue())

Do you know any function that returns the Background Color of the chart?

datanibbler
Champion
Champion

Hi Wannita,

there is no such function to my knowledge. As I said, just copy-paste the conditions you have for the background and where you have BLACK(), just enter WHITE() - that way, when the conditions make the background_colour turn black, they will at the same time make your text_colour turn white 😉

tresesco
MVP
MVP

So your background color is dynamic. And possibly that is based on some condition, say condition1. If so, you can always use that condition (condition1) to set the text color. Right?

kanhomcake
Contributor III
Contributor III
Author

hi DataNibbler, I don't have conditions for the background color. The color is dynamic as per set on Colors tab.

kanhomcake
Contributor III
Contributor III
Author

hi tresesco, yes my background color is dynamic but without condition. My background color is as per settings in Colors tab.

kanhomcake
Contributor III
Contributor III
Author

hi Vishnu, your example is based on Expression value. What I would like to have is the Text Color based on the background color of the bar.