3

The MWE below should clearly demonstrate my problem. If I pass too large values, I get the error Dimension too large. <to be read again>. If I pass a command \list as the list, I get the errors

Package PGF Math: Unknown function 'Contribution' (in '(0) + ( 100/Contribution, 50/Fundraising, 5/Grants )').
Package PGF Math: You've asked me to divide `0.0' by `0', but I cannot divide any number by `0' (in '0.5*((0.0pt)/(0)*360+(0))+0.5*(0.0pt/(0)*360+(0))').
Arithmetic overflow. \pgfmathdivide@ ...\pgfmath@x by\c@pgfmath@counta

I feel like I'm trying to do simple things, but I couldn't find any solutions on the internet.

MWE

\documentclass{article}

\usepackage{pgf-pie}

\begin{document}

    % This works
    \begin{tikzpicture}
        \pie[
            sum = auto
        ]{
            100/Contribution,
            50/Fundraising,
            5/Grants
        }
    \end{tikzpicture}

    % This doesn't work
    \begin{tikzpicture}
        \pie[
            sum = auto
        ]{
            100000/Contribution,
            50000/Fundraising,
            5000/Grants
        }
    \end{tikzpicture}

    % This doesn't work either
    \def\list{
        100/Contribution,
        50/Fundraising,
        5/Grants
    }
    \begin{tikzpicture}
        \pie[
            sum = auto
        ]{\list}
    \end{tikzpicture}

\end{document}

2 Answers 2

1

PGF/TikZ works with dimensions in points (pt) and is constrained by TeX's internal dimension limits (maximum around 16384pt). Therefore, the correct solution is to divide all values by a common factor. As far as I know, PGF does not automatically expand macros inside \pie{...}. Use \edef or \expanded\pie:

\documentclass{article}
\usepackage{pgf-pie}

\begin{document}

\def\mydata{100/Contribution, 50/Fundraising, 5/Grants}
\begin{tikzpicture}
    \edef\temp{\noexpand\pie[sum=auto]{\mydata}} 
    \temp   
\end{tikzpicture}
% or
% \begin{tikzpicture}
%    \expanded{\noexpand\pie[sum=auto]{\mydata}}
% \end{tikzpicture}

\end{document}

enter image description here

1

A first solution uses the key before number with a command to multiply the values with 1000.

\documentclass[border=6pt]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}
\def\mycommand#1{\fpeval{#1*1000}}
\pie[
  before number=\mycommand,
  sum=auto
]{
  100/Contribution,
  50/Fundraising,
  5/Grants
}
\end{tikzpicture}
\end{document}

cannot-pass-command-with-large-values-as-list-to-pie-chart-using-pgf-pie-package_1

A second solution uses the wheelchart package, which I wrote. Then larger numbers can be used directly.

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\begin{document}
\begin{tikzpicture}
\wheelchart[
  counterclockwise,
  pie,
  slices style={\WCvarB,draw=black,thick,line join=bevel},
  start angle=0,
  wheel data=\WCvarA
]{%
  100000/blue!60/Contribution,
  50000/cyan!60/Fundraising,
  5000/yellow!60/Grants%
}
\end{tikzpicture}
\end{document}

cannot-pass-command-with-large-values-as-list-to-pie-chart-using-pgf-pie-package_2

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.