Package for pie charts

I want to create a pie chart in LaTeX. Do you know a package which manages that? I tried datatool which uses tikz as backend but seems to be unusable due to mysterious floating point errors.

-
I recommend asking about the problems with datatool. –  Will Robertson Nov 21 '10 at 3:21
This is really a non-answer, so I’ll just add it as a comment: I strongly recommend not creating a pie chart at all; there are far better alternatives. See the article ‘Save the Pies for Dessert’ at perceptualedge.com/articles/08-21-07.pdf for a thorough discussion. –  Karl Ove Hufthammer Dec 14 '11 at 10:39
@KarlOveHufthammer A pie chart has two advantages: people like it and you can see with one glance whether the pieces of the pie add up to 100%. All other charts force me to start my own calculation, instead of listening to the speech. –  Keks Dose May 21 at 9:39

Use the package pgf-pie, which is not on CTAN, but on Google Code.

\begin{tikzpicture}
\pie{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}


Note however that there are conflicts with this package and any other package that introduces the command \text—e.g.: amstext. In order to mediate these effects edit pgf-pie.sty, replacing all occurrences of: \text with: \textASDF.

-
The latest version of the package doesn't seem to redefine \text. –  Torbjørn T. Nov 21 '12 at 7:05
This is a great package! The manual is really clear and easy. What a pity that this package is not on CTAN. –  Keks Dose May 21 at 9:42

An piechart example with pgf/tikz from texample.net by Robert Vollmert is a good starting point. I'll just quote it here for completeness:

% Pie chart
% Author: Robert Vollmert
\documentclass{article}

\usepackage{calc}
\usepackage{ifthen}
\usepackage{tikz}
\begin{document}
\newcommand{\slice}[4]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult

% slice
\draw[thick,fill=black!10] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;

% outer label
\node[label=\midangle:#4] at (\midangle:1) {};

% inner label
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
\pgfmathparse{max(\temp,-0.5) + 0.8}
\let\innerpos\pgfmathresult
\node at (\midangle:\innerpos) {#3};
}

\begin{tikzpicture}[scale=3]

\newcounter{a}
\newcounter{b}
\foreach \p/\t in {20/type A, 4/type B, 11/type C,
49/type D, 16/other}
{
\setcounter{a}{\value{b}}
\slice{\thea/100*360}
{\theb/100*360}
{\p\%}{\t}
}

\end{tikzpicture}

\end{document}


which looks like

-
This is a good start. I would like to be able to enter 49.5 instead of 49 percent as well as be able to set the colors. –  The Dude Sep 30 '11 at 17:07

Here's an example taken from the datatool manual:

\documentclass{article}

\usepackage{datapie}

\begin{filecontents}{test.csv}
Name,Quantity
"Apples",30
"Pears",25
"Lemons,Limes",40.5
"Peaches",34.5
"Cherries",20
\end{filecontents}

\begin{document}

\begin{figure}[htbp]
\centering
\DTLpiechart{variable=\quantity,outerlabel=\name}{fruit}{%
\name=Name,\quantity=Quantity}
\caption{A pie chart}
\end{figure}

\end{document}


-

Run with xelatex

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{bera}

\begin{document}

\begin{pspicture}(-3,-3)(3,3)
\psChart[userColor={red!30,green!30,blue!40,gray,cyan!50,
\psset{nodesepA=5pt,nodesepB=-10pt}
\ncline{psChartO1}{psChart1}\nput{0}{psChartO1}{1000 (34.5\%)}
\ncline{psChartO2}{psChart2}\nput{150}{psChartO2}{500 (17.2\%)}
\ncline{psChartO3}{psChart3}\nput{-90}{psChartO3}{600 (20.7\%)}
\ncline{psChartO4}{psChart4}\nput{0}{psChartO4}{450 (15.5\%)}
\ncline{psChartO5}{psChart5}\nput{0}{psChartO5}{150 (5.2\%)}
\ncline{psChartO6}{psChart6}\nput{0}{psChartO6}{200 (6.9\%)}
\bfseries%
\rput(psChartI1){Taxes}\rput(psChartI2){Rent}\rput(psChartI3){Bills}
\rput(psChartI4){Car}\rput(psChartI5){Gas}\rput(psChartI6){Food}
\end{pspicture}

\end{document}


-