Skip to content

Instantly share code, notes, and snippets.

Created Jan 8, 2016
Embed
What would you like to do?
Mmh… Delicious cake
\documentclass[tikz]{standalone}
\begin{document}
\def\angle{0}
\def\radius{3}
\newcount\ind \ind=-1
\begin{tikzpicture}
\foreach \percent/\name/\color in {
46.6/Chrome/blue,
24.6/Internet Explorer/red,
20.4/Firefox/green,
5.1/Safari/purple,
1.3/Opera/orange,
2.0/Other/yellow%
} {
\ifx\percent\empty\else % If \percent is empty, do nothing
\global\advance\ind by 1 % Advance list index
% Draw angle and set labels
\draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius) arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
\node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\%};
\node[pin=\angle+0.5*\percent*3.6:\name] at (\angle+0.5*\percent*3.6:\radius) {};
\pgfmathparse{\angle+\percent*3.6} % Advance angle
\xdef\angle{\pgfmathresult} % and store in \angle
\fi
};
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment