1

I am trying to display pie diagrams in QGIS 3.4. Lets say filling the whole circle would be 100%. If my data does not reach 100% in sum, I want the missing % to be empty or transparent.

Currently QGIS always fills the whole circle. Its expecting that the sum of my data is always 100%.

Here is an example:

Value_A;Value_B;Value_C;NoDataValue;Total
0,1;0,25;0,4;0,25;1
0,25;0,1;0,4;0,25;1
0;0;0,25;0,75;1
0,1;0;0;0,9;1
0,4;0,4;0;0,2;1

NoData is always 1-Sum(Value_A;Value_B;Value_C) and total is always 1.

Displaying Value_A, Value_B and Value_C in QGIS now looks like this:

enter image description here

So I was trying to add NoData and displaying it transparent. But transparent colors are not possible in QGIS diagrams. So it looks like this:

enter image description here

Basically I want to display the white areas transparent.

Is there some way (not necessarily by using transparent colors or diagram function) to achieve this task using QGIS 3.4? Using diagram size as %-sum is not an option in my case.

2
  • 1
    You actually can choose a transparent color using the transparency (a) parameter in rgba or #RRGGBBAA color format. But the diagram feature ignores the a parameter and makes it opaque. This would be a good feature request.
    – csk
    Sep 26 '19 at 17:08
  • A feature request has been submitted here github.com/qgis/QGIS/issues/34177
    – MrXsquared
    Jan 31 '20 at 13:24
2

Make a separate symbology layer for each wedge of the pie diagram. Use geometry generator symbology layers with the wedge_buffer(center,azimuth,width,outer_radius) function. This function has several parameters:

  • center - center point (origin) of buffer. Must be a point geometry.
    • This parameter will be the same for every symbol layer.
    • Use centroid($geometry) to place the pie chart over the centroid of your geometry.
    • Or, use translate( centroid($geometry), dx, dy) to offset the pie chart from the centroid by dx and dy (define the dx and dy parameters as you want).
  • azimuth - angle (in degrees) for the middle of the wedge to point.
    • For the first symbology layer, use "Value_A"*180
    • For the second layer, use "Value_A"*360 + "Value_B"*180
    • For the third layer, use "Value_A"*360 + "Value_B"*360 + "Value_C"*180
  • width - buffer width (in degrees). Note that the wedge will extend to half of the angular width either side of the azimuth direction.
    • For the first symbology layer, use "Value_A"*360
    • For the second layer, use "Value_B"*360
    • For the third layer, use "Value_C"*360
  • outer_radius - outer radius for buffers
    • This parameter will be the same for every symbol layer.
    • Use a numerical value, 1/2 of however wide you want the diagram to be.
    • If you want variable-sized diagrams, add a "diagram_size" field to the attribute table, and use "diagram_size" for the outer_radius parameter.

I found one glitch: if the width parameter is exactly 180 degrees, the wedge will be reversed. The workaround is to wrap the width parameter in a conditional statement that substitutes 179 when it's exactly 180, like this: if( width = 180, 179, width)

example: if("Value_A"*360 = 180, 179, "Value_A"*360)

So the complete geometry generator expressions will be as follows:

wedge_buffer(centroid($geometry), "Value_A"*180, if("Value_A"*360 = 180, 179, "Value_A"*360), 100000)

wedge_buffer(centroid($geometry), "Value_A"*360 + "Value_B"*180, if("Value_B"*360 = 180, 179, "Value_B"*360), 100000)

wedge_buffer(centroid($geometry), "Value_A"*360 + "Value_B"*360 + "Value_C"*180, if("Value_C"*360 = 180, 179, "Value_C"*360), 100000)

buffer(centroid($geometry), 100000)

The final symbol layer is a simple circular buffer. Place this layer at the bottom of the stack, so it fits behind the wedge buffers. Make its fill transparent. This eliminates the need for the NoData field. Or if you prefer, you can made another wedge buffer with the NoData field.

enter image description here

Here's what my final pie chart looks like. The geometry generator pie chart is in the centroid of the polygon. The original pie chart diagram is in the upper right. I chose matching colors for the corresponding data fields. Notice that the geometry-generated pie chart is the mirror image of the diagram.

enter image description here

The legend/table of contents shows the settings for the original diagram. The geometry generated chart will not be explained in the legend.

1

You could construct the diagram from scratch using geomtry-generator. This would be some work to do. Without going in details, it could work like this: first make_circle( make_point ($x,$y),10) - creating a circle centered at the relevant point and with a radius of 10 - or use the value of a field. Second: create segments of your circle: subtract a circle-segment from the whole circle. Do that by creating a triangle that overlays your circle, with one point at the center of the circle, a second point straight above (same x, higher y value) and the third point projected from the center of the circle with a distance (lenght) bigger than circle-radius and bearing (angle) depending on the value of your data - this is the angle in radians form the top of the circle clockwise.

Depending on your data, could look someting like this:

difference (
( make_circle( make_point ($x,$y),( "your_value_1"),10)),


( make_triangle( 
 make_point ($x,$y),
 make_point ($x, ($y+40)),
(project(  make_point( $x,$y), 400, -(radians(360*"your_value_2"/100 ))))
)))

Of course, you should adapt this to your needs. You than can change the color of the object created with geometry-generator with data-driven override and use a color gradient from opaque to transparante, depending on the data.

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.