4

I have three pie charts for which I only want to create one legend. For this purpose, only the third diagram contains a legend. But my third diagram contains only one value. To create the legend, I have zeroed all the values that appear in the three pie charts in the third chart. The result then looks similar to the first figure.

\documentclass{article}

\usepackage{pgf-pie}

\begin{document}

\begin{tikzpicture}
\pie[pos={0,0},radius=1.5,sum=auto,text=]{22/Apple pie ,5/Cheesecake}
\pie[pos={4,0},radius=1.5,sum=auto,text=]{17/Apple pie,9/Cheesecake,1/Raspberry pie}
\pie[pos={8,0},radius=1.5,sum=auto,text=legend] {27/Apple pie,0/Cheesecake,0/Raspberry pie}
\end{tikzpicture}

\end{document}

Result: Result

Is it possible to display only values greater than 0 in the pie chart? I would like to get a result similar to the one in the second figure. I would prefer not to change the order of the diagrams.

Desired is: Desired

1 Answers1

6

You can use the before number hook for that. This is what gets executed before the number.

\documentclass{article}

\usepackage{pgf-pie}

\begin{document}

\begin{tikzpicture}
\def\printonlypositive#1{\ifnum#1>0
#1
\fi}
\pie[pos={0,0},radius=1.5,sum=auto,text=]{22/Apple pie ,5/Cheesecake}
\pie[pos={4,0},radius=1.5,sum=auto,text=]{17/Apple pie,9/Cheesecake,1/Raspberry pie}
\pie[pos={8,0},radius=1.5,sum=auto,text=legend,
before number=\printonlypositive] {27/Apple pie,0/Cheesecake,0/Raspberry pie}
\end{tikzpicture}
\end{document}

enter image description here

A somewhat more robust version thereof that also works with noninteger numbers is

\documentclass{article}

\usepackage{pgf-pie}

\begin{document}

\begin{tikzpicture}
\def\printonlypositive#1{\ifdim#1pt>0pt
#1
\fi}
\pie[pos={0,0},radius=1.5,sum=auto,text=]{22/Apple pie ,5/Cheesecake}
\pie[pos={4,0},radius=1.5,sum=auto,text=]{17/Apple pie,9/Cheesecake,1/Raspberry pie}
\pie[pos={8,0},radius=1.5,sum=auto,text=legend,
before number=\printonlypositive] {27/Apple pie,0/Cheesecake,0/Raspberry pie}
\end{tikzpicture}
\end{document}