3

So basically I want to label my values in a specific color. They are all in the same shapefile which makes it complicated.

E.g:

  • if value is 10, it should appear in blue

  • if value is 15, it should appear in green

  • if value is 25, it should appear in red

How can I do that?

10

If you right-click your layer and go to:

Properties > labels

Use the Show labels for this layer option, select the field to label with and then click the data-defined button for the Color section as shown below:

Properties for labels

Then enter an expression like:

CASE 
WHEN "Field" = 10 THEN color_rgb(0, 0, 255) 
WHEN "Field" = 15 THEN color_rgb(0, 255, 0)
WHEN "Field" = 25 THEN color_rgb(255, 0, 0)
END

Click Apply then OK and hopefully you should see your labels with different colours:

Result


Tested on QGIS 2.16.1-Nødebo.

  • @Philipp - Most welcome, hope it was helpful :) – Joseph Nov 11 '16 at 11:32
  • Just one more question, if i have a range, lets say from 10 to 14 and i want to color the whole range to blue. How do i adapt it to the formula? – Philipp Nov 11 '16 at 11:58
  • @Philipp - Use something like WHEN "Field" >= 10 AND "Field" <= 14 THEN color_rgb(0, 0, 255) . – Joseph Nov 11 '16 at 12:00
  • it works, awesome!! – Philipp Nov 11 '16 at 12:03
  • @Philipp - Nice one! =) – Joseph Nov 11 '16 at 12:04
3

If you want to change any more than the color your best bet would be Rule based labeling, though for a single value you are better off using expressions for that specific value as already mentioned.

Rule based labelling screen

From memory this method has also been around for longer than expressions in data definitions and so should work further back in versions. Though someone please correct me if my memory is off there.

  • Indeed, rule-based labelling is a lot more simpler to use when setting additional properties. +1! – Joseph Nov 11 '16 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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