[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{pst-grad}
\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
\advance\pst at dimd by \cachedata\p@
\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)%
\advance\pst at dimh by \cachedata\p@
\csname check#3\endcsname(\multidocount)%
\pswedge[style=\cachedata]{2}
{\pst at number{\pst at dimg}}{\pst at number{\pst at dimh}}
% Label
\advance\pst at dimg\pst at dimh
\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!
\readarray{Labels}{1997&1998&1999&2000&2001}
\readarray{Styles}{StyleGradientA&StyleGradientB&%
StyleGradientC&StyleGradientD&StyleGradientE}
\newpsstyle{}{}% For undefined styles
\newpsstyle{StyleGradientA}{%
fillstyle=gradient,gradbegin=LightBlue,gradend=NavyBlue}
\newpsstyle{StyleGradientB}{%
fillstyle=gradient,gradbegin=Pink,gradend=red}
\newpsstyle{StyleGradientC}{%
fillstyle=gradient,gradbegin=PaleGreen,gradend=ForestGreen}
\newpsstyle{StyleGradientD}{%
fillstyle=gradient,gradbegin=LemonChiffon,gradend=Gold}
\newpsstyle{StyleGradientE}{%
fillstyle=gradient,gradbegin=lightgray,gradend=black}
\newpsstyle{StyleHatchA}{fillstyle=crosshatch}
\newpsstyle{StyleSolidA}{fillstyle=solid,fillcolor=magenta}
\begin{document}
\psset{gradmidpoint=1}%
\PstPieChart{Values}{Labels}{Styles}{0}
%\hspace{1.5cm}
%\Styles(5)={StyleHatchA}
%\Values(6)={8.3}\Labels(6)={2002}\Styles(6)={StyleSolidA}
%\PstPieChart{Values}{Labels}{Styles}{180}
\end{document}
More information about the texhax
mailing list