There's a nice answer to a pie chart question over here. I tried to bend it to my needs but found some aspects difficult. Specifically:

  • I'd like to be able to manually adjust the labels.

    • Rather than adding the degree labels (\newcommand{\degre}{$^\circ$}, I assume), I just want to be able to write something in manually, like a year or date or note or the variable name for instance.

    • I'd liked to have the option of replacing the percentage labels with something else too, like the actual value shown in the legend perhaps.

    • And finally, the numbers aren't formatted nicely. For instance, the value 1236 should ideally be written as 1,236.

Is this kind of customization possible? There are various similar questions about other pie chart designs, but this design is a bit different to most I've seen. Anyway the current code is below.

PS: I kept getting lost in it, so to make reading a bit quicker and easier, I've set: \begin{document} through \end{document} in bold, and:
value list={149/A,1236/R+L+D,740/N+F,346/C,75/E} in italics, so you can identify it at a glance.





        dc tag/.style={align=center},
        dc legend/.style={align=left,anchor=west},
        dc sector/.style={fill=\Cj,line join=round}

        % list of \Name/Value
        value list/.store in=\Value@list,
        % circular : 360 - semi circular 180
        angle max/.store in=\Angle@max,
        angle max=360,
        % radius of the diagram
        radius/.store in=\R@dius,
        % composition of the legend
        % \V value
        % \N name
        % \P percent
        % \A angle
        % \Cj color
        legend/.store in=\L@gend,
        % location of the legend
        legend location/.store in=\Legend@Loc,
        legend location={($(\R@dius,\R@dius)+(.5,-.5)$)},   
        % poisition of the node in the sector
        % 0 center, 1 on the edge, 1.++ external
        factor/.store in=\F@ctor,
        % composition of the node in the sector
        tags/.store in=\T@gs,
        % correction of round errors in percents
        percent corr/.store in=\C@rrP,
        percent corr=,
        % correction of round errors in angles
        angle corr/.store in=\C@rrA,
        angle corr=,
        % individual shift
        shift sector/.store in=\Shift@j,
        shift sector=,
        % more nodes in the sectors, or new legeng
        sup loop/.store in=\Sup@Loop,
        sup loop=,
        % code of the diagram
        % Calculation of the sum
        \foreach \i/\y in \Value@list {\xdef\S@m{\S@m+\i}}  

        % beginning of the first sector

        % main loop
        \foreach \V/\N [count=\j from 0] in \Value@list {%

        % calculation of the current angle

        % superior limit of the sector
        \pgfmathsetmacro\@ngleB{\@ngleA+\A} ;

        % mean angle
        \pgfmathsetmacro\MedA{(\@ngleA+\@ngleB)/2} ;        

        % color

        % individual shift

        % drawing of the sector
        \draw[dc sector,shift={(\MedA:\Sh@ft)}] (0,0)
            -- (\@ngleA:\R@dius) arc (\@ngleA:\@ngleB:\R@dius)
                node[midway] (DC\j) {} -- cycle ;

        % low limit of the next sector
        \xdef\@ngleA{\@ngleB} ;

        % current percent correction

        % current angle and corection

        % the sector node
        \DiagNode[dc tag]{\F@ctor} {\T@gs} ;

        % the legend
        \draw[fill=\Cj] (0,-.5*\j)
                rectangle ++(.25,.25) ++(0,-.15)
                node[dc legend] {\strut\L@gend} ;

        % some more stuff
        \Sup@Loop ;

        } % end of diagram code

% Node on the \j sector
\newcommand{\DiagNode}[2][]{\node[#1] at ($(0,0)!#2!(DC\j)$)}


    % style options
    dc sector/.append style={shift={(\MedA:5pt)}}, % shift all sectors
    dc dtag/.append style={},
    dc legend/.append style={text width=2cm, align=right},
    every pin/.style={fill=\Cj,draw=\Cj!50!black,thick},
    % diagram options
    value list={149/A,1236/R+L+D,740/N+F,346/C,75/E},
    angle max=180,             % semi-circular
    angle corr={0,1,0,0,0},    % correct round angle error
    legend=\N\ :\hfill \V,     % custom legend
    percent corr={0,-1,0,0,0}, % correct round percent error
    shift sector={0,0,.3,0,0}, % shift individual sector
    tags=\P,                   % custom sector nodes
    sup loop={% custom features :       
        %\DiagNode{1.1} {\N};  % some other sector nodes
        % or something else
        \node[pin=\Pinj:\A] at (DC\j) {}  ;
    diagram] ;

  • Straight up solutions are welcome, but what would be really nice is if you could also explain a little bit about how it works, so anyone reading can maybe solve similar problems on their/my own in the future. Teach a man to fish and all that. No pressure though, just a suggestion.
    – voices
    Apr 9 '19 at 10:59

First of all, please limit your scope of question to one at a time. In my opinion, your questions has sub-questions ;).

Having said that I think you can simply use pgf-pie to achieve your first two parts:

    \pie[ sum =1000 , after number =$^\circ$, radius
    =2,  text = legend]{200/A+B+C , 500/E+G+H, 300/F }

and for the 3rd part, I leave it to the tikzperts :).

enter image description here

Just make the sum=2000 and you get a semi-circle as in

    \pie[ sum =2000 , after number =$^\circ$, radius
    =2,  text = legend]{200/A+B+C , 500/E+G+H, 300/F }

enter image description here

  • Everything has subquestions, it depends how you slice it. I was trying to be thorough is all. But at it's core, it's simply about exerting control over the textual elements of a graph. If it helps, think of it as "how can we customize the various texts of this pie chart?" or something like that. That said, this actually looks pretty nice. Can it do the extra labels though, and half pies (semi-circles) too? I have no need for displaying degrees either. but keep this up, it's still nice information.
    – voices
    Apr 9 '19 at 12:33
  • 2
    Please check updated answer. It can do many things ;). Apr 9 '19 at 12:48

Customization pie chart with plain TikZ. The code is long, but mostly done by copy-paste. You can shorten the code with foreach. I am willing to explain more if asked.

enter image description here

% for legends
\draw[fill=#1] (-.2,-.2) rectangle (.2,.2);

(0,0)     pic[fill=red!50]{box}
          node[right=2mm]{E :}
          +(0:2.8) node[left]{75}
++(90:.6) pic[fill=yellow!50]{box} 
          node[right=2mm]{C :}
          +(0:2.8) node[left]{346}
++(90:.6) pic[fill=teal!50]{box}                  
          node[right=2mm]{N+F :}
++(90:.6) pic[fill=orange!50]{box} 
          node[right=2mm]{R+L+D :}
          +(0:2.8) node[left]{1236}
++(90:.6) pic[fill=blue!50]{box} 
          node[right=2mm]{A :}
          +(0:2.8) node[left]{149};

\def\r{5} % radius of the pie chart

% each scope is a shifted piece of the pie
(0:\r) arc(0:11:\r)--(0,0)--cycle;
\draw[gray!50] (5.5:\r) 

(11:\r) arc(11:99:\r)--(0,0)--cycle;
\draw[gray!50] (55:\r) 
node[below left,black]{$48\%$}--+(40:1) 

(99:\r) arc(99:99+52:\r)--(0,0)--cycle;
\draw[gray!50] (125:\r) 
node[below right,black]{$29\%$}--+(150:1) 

(151:\r) arc(151:151+24:\r)--(0,0)--cycle;
\draw[gray!50] (165:\r) node[right,black]{$14\%$}--+(150:1) 

(175:\r) arc(175:180:\r)--(0,0)--cycle;
\draw[gray!50] (177.5:\r) node[right,black]{$3\%$}--+(150:1) 


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.