Site menu:

Cyclocross For Roadies: How and Why to Get Started - Buy Now!

Site search

Categories

QGIS Diagrams – Pie Charts for Symbols!

QGIS has a great feature that allows you to create pie charts for feature symbols! I have known about it for a while, but never really had the opportunity or reason to play with it. However, this post on gis.stackexchange.com prompted me to take a look. Here’s a quick summary of how the ‘Diagrams’ functionality works in case you’re like me and haven’t had time to check it out! It’s easy to do, and works pretty well!

As an example, I created a random sample dataset with some fictitious data. It contained three points, and the attribute table looked like this:

Attribute Table

Attribute Table

To create a diagram symbol, go to the properties for the layer in question, and click the “Diagrams” tab at the top, then check off “Display Diagrams” and set Diagram type to “Pie Chart.” You can also use “Text Diagram” but that’s another post!

You can set either a fixed size, or scale the size of the charts to an attribute value range. This is useful if you are wanting to use the size of the symbol to indicate a value, and the ‘slices’ to indicate percentages. In my case, I set the size to ’23’ and set it to scale between 0 and 30mm. This is arbitrary in my case, but you can play with it using your own data to see what works best for you.

At the bottom under “Attributes,” select each attribute you want to form a ‘slice’ of the pie, and click the ‘+’ on the right. Then select the next value, and click ‘+.’  Repeat until you are finished adding all values. In my case, I added attributes A, B, C, and D. I didn’t want to use the ID, so I left it out. You can set individual colours for each ‘slice’ here by double clicking the colour in the table. Here’s what my settings looked like:

Pie Chart Settings

Pie Chart Settings

and here’s here what the final product looks like:

Final Result

Final Result

This is already a great tool, and with a few more enhancements, it will be a fantastic tool! What enhancements you wonder? A couple that immediately come to mind are the ability to label ‘slices’ with either their attribute value, or their percentage, and the ability to remove all borders (in the above example, ‘Pen Width’ is set to 0, but it still shows a border. Weird.)

What features would you like to see?

Comments

Comment from Anna
Time November 3, 2011 at 6:38 am

My question is how to display legend of the diagram symbols in composer?

Comment from darrencope
Time November 3, 2011 at 6:45 am

Good catch Anna! I don’t currently see a way to do that. Its certainly one for the wish list! I guess you’ll have to screenshot an example and insert it as an image in over top of the legend for the time being….unless someone knows a better way?

Pingback from DARREN COPE » 2011 – The Year in Review
Time February 21, 2012 at 9:45 pm

[…] QGIS Diagrams – Pie Charts for Symbols! […]

Comment from mike
Time February 28, 2012 at 7:25 am

what about when you have lots of pies so some would be on top of each other, only some of them display and its not clear which ones its going to display

Comment from darrencope
Time February 29, 2012 at 6:01 pm

Hi Mike. Good question. I believe QGIS will treat the ‘pies’ as any other label, and resolve conflicts the same way; in other words, choose one more or less arbitrarily. I guess the only thing you could do is make the pies smaller to help alleviate this problem?

Comment from Ian Kirk-Ellis
Time September 19, 2012 at 9:28 am

The easiest way to get a key is to use “snipping tool” in Windows 7 (or similar) to grab the image from within the ‘Diagrams’ tab, this can then be added to the composer as an image.

Comment from franchina
Time November 28, 2012 at 3:35 am

i want to do georeference correctly may i know what is the calculation

Comment from franchina
Time November 28, 2012 at 3:38 am

i want to do cartographic mapping in qgis may i know what to do?

Comment from darrencope
Time November 28, 2012 at 5:05 pm

franchina: A quick Google search should provide what you need. For example, to georeference, here’s an example. “Cartographic Mapping” is a pretty broad, vague statement, so you’d have to narrow your question down considerable for anyone to help.

Pingback from DARREN COPE » 2012 – The Year in Review
Time February 3, 2013 at 4:17 pm

[…] QGIS Diagrams – Pie Charts for Symbols! […]

Comment from Munlin
Time April 30, 2013 at 6:21 am

I am also getting same problem like Anna.
Can anyone resolve it.

Comment from darrencope
Time April 30, 2013 at 6:39 am

Munlin: as per the reply to Anna, it doesn’t seem like there’s a way–try the screenshot method mentioned above.

Comment from CharlesG
Time May 27, 2013 at 9:56 am

Thanks for the post! I’ve been experimenting with diagrams and have noticed a couple of things: 1) it helps to create another column in the attribute table for scale since not all the features may have all the attributes and 2) experiment with the placement of the charts. If they overlap, some of them may not appear. I think this is what happened to me. When I have the charts as “overpoint,” one of my pie charts disappears but when I have it as “free,” it reappears.

Comment from darrencope
Time May 28, 2013 at 7:11 am

Thanks CharlesG; yes, those are great tips! ‘Free’ will allow the label renderer to attempt to move the pie charts around to avoid overlapping, while ‘over point’ will just hide them if they overlap.

Comment from Ashutosh Saxena
Time June 26, 2013 at 1:14 am

Thanks for the post !Well I have just started with QGIS and suffered this problem of only some pie charts being displayed in the image that is made from the composer, the only way to go about it is to simply change the FIXED SIZE of the pie chart circle from mm to the MAP SCALE, and fit the chart at whatever size you want. The problem is removed. But cannot understand why enabling ON THE FLY isn’t doing that when mm scale was being used??

Comment from Nhu
Time January 14, 2014 at 2:21 pm

i’m having quite a time with my pie charts. after merging two layers, the diagrams only show up on one. in fact, it doesn’t emerge at all on one of the layers (alone) what are some possible issues?

Comment from darrencope
Time January 14, 2014 at 4:52 pm

Hi Nhu. Can you explain a bit more? What do you mean by merging two layers? Are you trying to label two layers that overlap? If so, the label conflict detection is likely only showing one of the layers, which may explain your problem.

Comment from Nicole Sigaud
Time May 22, 2014 at 8:08 pm

I’d like to see how I could add a circle sector with 120º, with transparency of, say, 60%, with its vertex in a certain lat/long point. Also, there should have the center angle axis directed to a specific direction. The scope is to plot the transmission range of a cell phone antenna having its azimuth. Is it possible?

Comment from darrencope
Time May 28, 2014 at 7:20 am

Nicole; the Pie Chart labels aren’t likely the best way to do what you are hoping. Take a peek at this post: http://gis.stackexchange.com/questions/25575/how-can-i-create-sectors-for-telecom-towers to see if it helps at all.

Comment from scoop
Time October 17, 2014 at 7:12 am

Is there any way to add stippled or crosshatch fills to the pie chart instead of grey scale or colours. I cannot see how to prepare a map with pie charts which is suitable for publication in black an white. Unfortunately I have more than 3 attributes (black, white and grey) although not in the same pie chart

Comment from darrencope
Time October 20, 2014 at 7:29 am

Unfortunately I don’t see a way to add fill patterns to the pie charts–hopefully that enhancement will come soon. Perhaps you could suggest it as a new feature!

Comment from kilolima
Time November 4, 2014 at 11:36 pm

It’s not clear in qgis, but labelling needs to be enabled in order to get the diagrams to show up. Another poorly documented feature in qgis!

Write a comment





Bookshelf 2.0 developed by revood.com

More in GIS (12 of 33 articles)


As we all know, there's almost always more than one way to do something! In a previous post (QGIS Trace ...