Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join this live chat April 6, 10AM EST - QlikView to Qlik Sense REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
kamber_tamedia
Contributor III
Contributor III

Convert strings into RGB

Hi all,

Need some help on a tricky problem

Basically we have a bar chart which is dynamically when it comes to the dimension:

DimensionFilterTable:

LOAD * INLINE [

    TableSelection, DimDisplayName   

    dim1, Country

    dim2, Ciy

    dim3, Seller

  ];

In the table we're working with a calculated dimension:

=$(=TableSelection)

So far it works perfect. But now I want to use different colors for the different dimension elements - the normal approach doing this in the loading script is not really useful because this DimensionFilterTable is flexible. My idea was now to somehow generate RGB depending on the string:


 

ElementColor
Exa1red()
Exb2green()
sdfblack()
Exa1

red()

Any idea? No script code should be used because it would mean to specify all the times the flexible dimensions and its elements with color codes. Something like this...but qlikish


Hash string into RGB color - Stack Overflow

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Uhm, wow. I hope you didn't spend much time on putting that monster together.

Perhaps this will work too:

hsl(

  FieldIndex('$(TableSelection)',[$(TableSelection)])/FieldValueCount('$(TableSelection)'),

  0.5,

  0.5

  )

But imho a better idea is to load a table with colors like this one: List of Crayola crayon colors - Wikipedia‌. You could use the index value of the dimension to pick the color from the color table with the same index value.


talk is cheap, supply exceeds demand

View solution in original post

7 Replies
Gysbert_Wassenaar

Which color should be assigned to which dimension value? Is there a logic or do you simply want a random color assigned, any color will do as long as it is a color and each dimension value gets its own unique color?


talk is cheap, supply exceeds demand
marcus_sommer
MVP & Luminary
MVP & Luminary

Maybe this is helpful: Colors in charts.

- Marcus

swuehl
MVP
MVP

" the normal approach doing this in the loading script is not really useful because this DimensionFilterTable is flexible"

if this is your primary concern, you should be able to direct QV to the correct color code field (e,g. following Henric's blog post Marcus referenced) based on the dimension used with a similar approach you are using for the dimension:

DimensionFilterTable:

LOAD * INLINE [

    TableSelection, DimDisplayName , DimColorCodeField

    dim1, Country, CountryColor

    dim2, Ciy, CityColor

    dim3, Seller, SellerColor

  ];


=$(=Only(DimColorCodeField))




kamber_tamedia
Contributor III
Contributor III
Author

Exactly - at the end we're displaying always the same points on a map but the different classifications of the elements should be seenable with a different color. The classification is in different dimensions...

Guess I found an easy solution:

hsl(

  (

  mod((ord(mid(Hash128(Dim1),3,1)) + (((ord(mid(Hash128(Dim1),2,1)) + (((ord(mid(trim(Hash128(Dim1)),len(trim(Hash128(Dim1)))-1,1)) + ((0 << 5) - 0)) << 5) - (ord(mid(trim(Hash128(Dim1)),len(trim(Hash128(Dim1)))-1,1)) + ((0 << 5) - 0)))) << 5) - (ord(mid(Hash128(Dim1),2,1)) + (((ord(mid(trim(Hash128(Dim1)),len(trim(Hash128(Dim1)))-1,1)) + ((0 << 5) - 0)) << 5) - (ord(mid(trim(Hash128(Dim1)),len(trim(Hash128(Dim1)))-1,1)) + ((0 << 5) - 0)))))),100)

) /100

,

mod(ord(mid(Hash128(Dim1),5,1)),10)/10,mod(ord(mid(Hash128(Dim1),8,1)),10)/10)

Where Dim1 is replacable by the $(TableSelection).

@Marcus / Stefan: This means I have:

a) always the same color for the different elements

or

b) I need to create a color mapping first with looping trough the elements

kamber_tamedia
Contributor III
Contributor III
Author

Result:

2016-11-20 16_25_13-QlikView x64 Personal Edition - [E__4_Temp_qlik_dsfsdf.qvw_].png

Gysbert_Wassenaar

Uhm, wow. I hope you didn't spend much time on putting that monster together.

Perhaps this will work too:

hsl(

  FieldIndex('$(TableSelection)',[$(TableSelection)])/FieldValueCount('$(TableSelection)'),

  0.5,

  0.5

  )

But imho a better idea is to load a table with colors like this one: List of Crayola crayon colors - Wikipedia‌. You could use the index value of the dimension to pick the color from the color table with the same index value.


talk is cheap, supply exceeds demand

View solution in original post

kamber_tamedia
Contributor III
Contributor III
Author

Ok wow - that's a lot smarter

Thanks, works like a charm.