# [texhax] Pie chart

Herbert Voss Herbert.Voss at FU-Berlin.DE
Sat Oct 24 18:00:54 CEST 2009

Ulrich Lindberg Olsen schrieb:

> I have tried to follow one of the exmples in the documentation on
> pstricks. It's the one starting on page 277 on doing a pie chart. For
> some reason I can't get it to work.
>
> I have attached my .tex file.
>
> Can you please tell me why it isn't working?

out the definition of the macro between
\makeatletter
...
\makeatother
and use the optional argument of pstricks for the color names
(see example)

and you should have a look at pstricks-add, it has better support
for pie charts.

Herbert

\documentclass[11pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[dvipsnames,svgnames]{pstricks}
\usepackage{multido}
\usepackage{arrayjob}

\makeatletter
\def\PstPieChart#1#2#3#4{%
% #1 = Values, #2 = Labels, #3 = Styles, #4 = Starting angle
\pspicture(-2,-2)(2,2)
% To compute in \pst at dimd the sum of all the values
\pst at dimd=\z@
\Multido{\iNbValues=\z at +\@ne}{9999}{%
\csname check#1\endcsname(\multidocount)%
\ifemptydata
\multidostop
\else
\fi}
\degrees[\pst at number{\pst at dimd}]
% To compute the starting angle
\pst at dimh=\pst at dimd
\divide\pst at dimh by 360
\multiply\pst at dimh by #4
% Loop on slices
\multido{}{\iNbValues}{%
% Slice
\pst at dimg=\pst at dimh
\csname check#1\endcsname(\multidocount)%
\csname check#3\endcsname(\multidocount)%
\pswedge[style=\cachedata]{2}
{\pst at number{\pst at dimg}}{\pst at number{\pst at dimh}}
% Label
\divide\pst at dimg\tw@
\uput{2.2}[\pst at number{\pst at dimg}](0,0){%
\large\csname #2\endcsname(\multidocount)}}
\endpspicture}
\makeatother
\newarray{\Values}
\newarray{\Labels}
\newarray{\Styles}

\readarray{Values}{32.7 & 19.3 & 12.4 & 27.6 & 6.9}
% Don't leave blanks between labels and between styles!

\newpsstyle{}{}% For undefined styles
\newpsstyle{StyleHatchA}{fillstyle=crosshatch}
\newpsstyle{StyleSolidA}{fillstyle=solid,fillcolor=magenta}
\begin{document}