# Example: Pie chart with colors

Published 2014-07-29 | Author: Henri Menke

With this pie chart, we can define a list of colors which is used for the pieces. A counter cycles through the list for choosing the color, it restarts after the list ended.

The annotation is done using the pin element.

This example was written by Henri Menke answering a question of Sascha on TeXwelt.de.

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% Pie chart with colors
% Author: Henri Menke
\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\def\angle{0}
\def\cyclelist{{"orange","blue","red","green"}}
\newcount\cyclecount \cyclecount=-1
\newcount\ind \ind=-1
\begin{tikzpicture}[nodes = {font=\sffamily}]
\foreach \percent/\name in {
46.6/Chrome,
24.6/Internet Explorer,
20.4/Firefox,
5.1/Safari,
1.3/Opera,
2.0/Other
} {
\ifx\percent\empty\else               % If \percent is empty, do nothing
\ifnum3<\cyclecount                 % If cyclecount is larger than list
\global\cyclecount=0              %   reset cyclecount and
\global\ind=0                     %   reset list index
\fi
\pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
\edef\color{\pgfmathresult}         %   and store as \color
% Draw angle and set labels
\node[pin=\angle+0.5*\percent*3.6:\name]
\xdef\angle{\pgfmathresult}         %   and store in \angle
\fi
};
\end{tikzpicture}
\end{document}