2

I would like to do labelling like this (3 rows):

   Location_name
   Time
   People

My csv has 5 features

   Location_name      Time   AM/PM   People  A/K

Based on the value of "AM/PM", I want the "Time" has different colors; based on "A/K" values, I want the "People" had different colors.

Can someone help?

1 Answer 1

4

You can do this with rule-based labeling

Select the layer properties of the layer that you are labeling and select the Labels tab. At the top, select Rule-based labeling and add a rule for each label (location, time, people). If you want to display a label for every item in the table, just don't add a filter to the rule.

rule based labeling

You will need to play with the placement properties of each label to position the labels such that they aren't right on top of each other. In my example I used an arbitrary distance of 5 just to make sure that the labels weren't on top of each other.

label placement

To get the custom coloring, go to the Text tab when editing the rule, and select the drop down next to the color and select Edit...

enter image description here

In the Expression String Builder that comes up you can put in an expression like the following

if("t/f"='t', color_rgb(0,0,255), color_rgb(255,255,0))

In this example, I have a column that is named "t/f" and contains a string value of 't' or 'f'. If the column value is 't', then the text is colored as blue, and otherwise is colored as yellow.

I did this to a sample layer where I had random values of t or f to colorize the strings. Display string is either red or green, and second display string is blue or yellow.

end result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.