# How can I produce a 'ring (or wheel) chart' like that on page 88 of the PGF manual?

I really like the 'ring chart' or 'wheel chart' given as an example on page 88 of the PGF manual. It is like a pie chart, but with a label in the centre. Unfortunately, the manual doesn't give the source for that chart. Does anyone have an example? Thanks.

-
The PGF/TikZ-manual basically states in that section that pie charts (especially in 3D) and similar charts should be avoided in favor of tables or bar charts because they are clearer. This might be the reason no actual code is provided. However, you might want to check out the sources of the manual. Maybe you are lucky. –  Martin Scharrer May 10 '11 at 16:53
@Martin: Directly below the graphic, the manual also states: [This] graphic has about the same information density as the table (about the same size and the same numbers are shown). In addition, one can directly “see” that there are more good or very good ratings than bad ones. One can also “see” that the number of people who gave no rating at all is not negligible, which is quite common for feedback forms. –  Caramdir May 10 '11 at 16:57
@Caramdir: Yes, indeed, it states there that they are good for things which add up to 100%. But AFAIK this types of charts are overused. –  Martin Scharrer May 10 '11 at 17:02
Apropos pie charts: svott.com/mt/archives/pacman_piechart.jpg. –  Martin Scharrer May 10 '11 at 17:02
@Martin Or this one: stats.stackexchange.com/questions/423/… –  Sharpie May 10 '11 at 17:06

I am afraid that this is drawn completely manually. The relevant code is in texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-guidelines.tex (in TeX Live 2010). For convenience it is also listed below (with a preamble added). Making a library out of this might be a useful project.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\colorlet{good}{green!75!black}
\colorlet{neutral}{black!60}
\colorlet{none}{white}

\node[align=center,text width=3cm]{Ratings given by 50~participants};

\begin{scope}[line width=4mm,rotate=270]
\draw[good]          (-123:2cm) arc (-123:-101:2cm);
\draw[good!60!white] (-36:2cm) arc (-36:-101:2cm);
\draw[neutral]       (-36:2cm) arc (-36:36:2cm);

\newcount\mycount
\foreach \angle in {0,72,...,3599}
{
\mycount=\angle\relax
\divide\mycount by 10\relax
\draw[black!15,thick] (\the\mycount:18mm) -- (\the\mycount:22mm);
}

\draw (0:2.2cm) node[below] {ok'': 10 (20\%)};
\draw (165:2.2cm) node[above] {none: 20 (40\%)};
\draw (-111:2.2cm) node[left] {very good'': 3 (6\%)};
\draw (-68:2.2cm) node[left] {good'': 9 (18\%)};
\draw (65:2.2cm) node[right] {bad'': 8 (16\%)};
\draw (93:2.2cm) node[right] {very bad'': 0 (0\%)};
\end{scope}
\draw[gray] (0,0) circle (2.2cm) circle (1.8cm);
\end{tikzpicture}

\end{document}

-
Beat me to it by a couple of seconds :P –  Sharpie May 10 '11 at 16:57
@Sharpie: I was just going to post it as well :-) Here the general CTAN link for that file: mirrors.ctan.org/graphics/pgf/base/doc/generic/pgf/text-en/… –  Martin Scharrer May 10 '11 at 16:58
@Sharpie Beat me to. I've deleted mine as I didn't notice the "answer added" bar. –  Edd May 10 '11 at 17:01
Thanks to all - very useful. Yes, pie charts are over-used, but these are better than traditional ones for when there aren't many choices! –  moabi2000 May 11 '11 at 17:50

Oooh, too tempting! Even though pie/wheel charts are bad, here's a macro to automatically draw the wheel chart from the PGF manual.

This command:

\wheelchart{20/green/good,  10/yellow/medium, 9/red/bad, 5/white/neutral}


Yields this chart:

Here's the implementation:

\documentclass{article}
\usepackage{tikz}
\begin{document}

% Adjusts the size of the wheel:

% The main macro
\newcommand{\wheelchart}[1]{
% Calculate total
\pgfmathsetmacro{\totalnum}{0}
\foreach \value/\colour/\name in {#1} {
\pgfmathparse{\value+\totalnum}
\global\let\totalnum=\pgfmathresult
}

\begin{tikzpicture}
% The text in the center of the wheel

% Calculate the thickness and the middle line of the wheel

% Rotate so we start from the top
\begin{scope}[line width=\wheelwidth,rotate=90]

% Loop through each value set. \cumnum keeps track of where we are in the wheel
\pgfmathsetmacro{\cumnum}{0}
\foreach \value/\colour/\name in {#1} {
\pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}

% Calculate the percent value
\pgfmathsetmacro{\percentage}{\value/\totalnum*100}
% Calculate the mid angle of the colour segments to place the labels
\pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}

% This is necessary for the labels to align nicely
\pgfmathparse{
(-\midangle<5?"south":
(-\midangle<85?"south west":
(-\midangle<105?"west":
(-\midangle<175?"north west":
(-\midangle<185?"north":
(-\midangle<265?"north east":
(-\midangle<275?"east":
(-\midangle<355?"south east":"south")
)
)
)
)
)
)
)
} \edef\textanchor{\pgfmathresult}

% Draw the color segments. Somehow, the \midrow units got lost, so we add 'pt' at the end. Not nice...

% Draw the data labels
\node at (\midangle:\outerradius + 1ex) [inner sep=0pt, outer sep=0pt, ,anchor=\textanchor]{\name: \value\ (\pgfmathprintnumber{\percentage}\%)};

% The 'spokes'
\foreach \i in {0,...,\value} {
}

% Set the old cumulated angle to the new value
\global\let\cumnum=\newcumnum
}

\end{scope}

@koppor: This happens because : is made active by babel. It works if you set \catcode:=12\relax`. –  Jake May 19 '12 at 21:10