I have a layer with a timestamp column. I want the color of the labels with the same hour to be identical. I used this:
CASE
WHEN hour("time") = 9 THEN color_rgb(rand(0, 255), rand(0, 255), rand(0, 255))
WHEN hour("time") = 10 THEN color_rgb(rand(0, 255), rand(0, 255), rand(0, 255))
WHEN hour("time") = 11 THEN color_rgb(rand(0, 255), rand(0, 255), rand(0, 255))
WHEN hour("time") = 12 THEN color_rgb(rand(0, 255), rand(0, 255), rand(0, 255))
END
But it generates random colors for all labels as in the image.
I could use the following expression, but I want it to be random. I don't want to specify a different color for each hour manually.
CASE
WHEN hour("time") = 9 THEN '255,0,0'
WHEN hour("time") = 10 THEN '0,255,0'
WHEN hour("time") = 11 THEN '0,0,255'
WHEN hour("time") = 12 THEN '0,255,255'
END
How can I make the color of the label in each rectangle (in the first image) the same, but random? I hope there is a shorter way. The column includes other hours as well.
Best Answer
hour("time")
, Color ramp: 'Random colors'@symbol_color
for the color data-defined override