Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw the following pie chart. I just wonder if anyone could show me where to start.

(Just the pie chart and those description circles around them)

share|improve this question
    
Can you provide something for a start? Like MWE of what you have tried or data in some useful format. –  m0nhawk Aug 6 at 10:15
    
I plan to use it to illustrate the planning time for different tasks. Say there are 4 tasks: The first one takes 45%, the second takes 25%, and the other two takes 15% each. –  wererabit Aug 6 at 10:19
    
@LaRiFaRi Not exactly, this is more than just a pie chart. wererabit: If you can use code from the question mentioned by LaRaFaRi to create a pie chart, and then edit your question with a minimal example and focus it more on the missing pieces (description circles), we can reopen it. –  Torbjørn T. Aug 6 at 10:47
1  
Don't close questions with lightning speed please. We are not in a hurry. –  percusse Aug 6 at 10:55
2  
@pushpen Please don't change OP sentences. It's now your question not theirs –  percusse Aug 6 at 12:00

2 Answers 2

up vote 8 down vote accepted

Next code is adapted from Jake's answer to Create a ring diagram in TeX which was already adapted from his own answer to How can I produce a 'ring (or wheel) chart' like that on page 88 of the PGF manual?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

% Adjusts the size of the wheel:
\def\innerradius{1cm}
\def\outerradius{3.5cm}

% The main macro
\newcommand{\wheelchart}[1]{
    % Calculate total
    \pgfmathsetmacro{\totalnum}{0}
    \foreach \value/\colour/\name in {#1} {
        \pgfmathparse{\value+\totalnum}
        \global\let\totalnum=\pgfmathresult
    }

    \begin{tikzpicture}

      % Calculate the thickness and the middle line of the wheel
      \pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
      \pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}

      % Rotate so we start from the top
      \begin{scope}[rotate=90]

      % Loop through each value set. \cumnum keeps track of where we are in the wheel
      \pgfmathsetmacro{\cumnum}{0}
      \foreach \value/\colour/\name in {#1} {
            \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}

            % Calculate the percent value
            \pgfmathsetmacro{\percentage}{\value/\totalnum*100}
            % Calculate the mid angle of the colour segments to place the labels
            \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}

            % This is necessary for the labels to align nicely
            \pgfmathparse{
               (-\midangle<180?"west":"east")
            } \edef\textanchor{\pgfmathresult}
            \pgfmathsetmacro\labelshiftdir{1-2*(-\midangle>180)}

            % Draw the color segments. Somehow, the \midrow units got lost, 
            % so we add 'pt' at the end. Not nice...
            \fill[\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
            (-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;

            % Draw the data labels
            \draw [*-,thin,\colour] 
              node [circle, very thick, draw=\colour,
                fill=gray!70, text=white, text width=2cm, align=center, 
                append after command={(\midangle:\midradius pt) -- 
                  (\midangle:\outerradius + 5ex) -- (\tikzlastnode)}] 
              at (\midangle:\outerradius + 1ex) [xshift=\labelshiftdir*0.75cm, 
                inner sep=0pt, outer sep=0pt, ,anchor=\textanchor]
              {\name: \pgfmathprintnumber{\percentage}\%};

            % Set the old cumulated angle to the new value
            \global\let\cumnum=\newcumnum
        }

      \end{scope}
%      \draw[gray] (0,0) circle (\outerradius) circle (\innerradius);
    \end{tikzpicture}
}

% Usage: \wheelchart{<value1>/<colour1>/<label1>, ...}
\wheelchart{45/blue!70/First Task, 25/orange!70/Second Task, 
      15/yellow!70/Third Task, 15/purple!70/Fourth Task}
\end{document}

enter image description here

UPDATE - Descriptions

I've made some changes to add circle descriptions branching from other circles.

wheelchart is a macro but it doesn't includes a tikzpicture on its own but you need to declare it.

\begin{tikzpicture}
\wheelchart{...}
\end{tikzpicture}

Every circle node in wheelchart has a name after its \name parameter. You can use this node name to position (with positioning library) descriptions and add an edge between them.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}

% Adjusts the size of the wheel:
\def\innerradius{1cm}
\def\outerradius{3.5cm}

% The main macro
\newcommand{\wheelchart}[1]{
    % Calculate total
    \pgfmathsetmacro{\totalnum}{0}
    \foreach \value/\colour/\name in {#1} {
        \pgfmathparse{\value+\totalnum}
        \global\let\totalnum=\pgfmathresult
    }

%    \begin{tikzpicture}

      % Calculate the thickness and the middle line of the wheel
      \pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
      \pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}

      % Rotate so we start from the top
      \begin{scope}[rotate=90]

      % Loop through each value set. \cumnum keeps track of where we are in the wheel
      \pgfmathsetmacro{\cumnum}{0}
      \foreach \value/\colour/\name in {#1} {
            \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}

            % Calculate the percent value
            \pgfmathsetmacro{\percentage}{\value/\totalnum*100}
            % Calculate the mid angle of the colour segments to place the labels
            \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}

            % This is necessary for the labels to align nicely
            \pgfmathparse{
               (-\midangle<180?"west":"east")
            } \edef\textanchor{\pgfmathresult}
            \pgfmathsetmacro\labelshiftdir{1-2*(-\midangle>180)}

            % Draw the color segments. Somehow, the \midrow units got lost, 
            % so we add 'pt' at the end. Not nice...
            \fill[\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
            (-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;

            % Draw the data labels
            \draw [*-,thin,\colour] 
             node [circle, very thick, draw=\colour, fill=gray!70, text=white, 
               text width=2cm, align=center, 
               append after command={(\midangle:\midradius pt) -- (\midangle:\outerradius + 5ex) 
               -- (\tikzlastnode)}] (\name) at (\midangle:\outerradius + 1ex) 
               [xshift=\labelshiftdir*0.75cm, inner sep=0pt, outer sep=0pt, 
                 anchor=\textanchor]{\name: \pgfmathprintnumber{\percentage}\%};

            % Set the old cumulated angle to the new value
            \global\let\cumnum=\newcumnum
        }

      \end{scope}
%    \end{tikzpicture}
}

\begin{tikzpicture}

% Usage: \wheelchart{<value1>/<colour1>/<label1>, ...}
\wheelchart{45/blue!70/First Task, 25/orange!70/Second Task, 
     15/yellow!70/Third Task, 15/purple!70/Fourth Task}

\node [above=1cm of First Task, circle, text width=2cm, blue!70, 
      fill=black!70!orange, text=white, align=center] (1TD) 
      {Description for First Task};
\draw[very thick, green!70] (First Task) -- (1TD);

\node [above right=1cm and 0.5cm of Fourth Task, circle, text width=2cm, 
      blue!70, fill=black!70!red, text=white, align=center] (4TD) 
      {Description for Fourth Task};
\draw[very thick, green!70] (Fourth Task) -- (4TD);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thank you so much! I just have one more question, how can I extend your code to have a description circle braching from another circle? –  wererabit Aug 6 at 22:47
    
@wererabit. I've updated the answer –  Ignasi Aug 7 at 8:48
    
Thank you very much –  wererabit Aug 9 at 7:27
\documentclass[border=12pt,pstricks]{standalone}
\usepackage{pstricks-add}
\def\CPut#1#2{\pscircle*[linecolor=black!15](0,0){5mm}%
      \pscircle[linecolor=#1!70](0,0){5mm}\rput(0,0){\tiny\shortstack{#2}}}
\begin{document}

 \begin{pspicture}(-3.5,-3.5)(4,3.5)
 \psChart[userColor={blue!70,orange!70,yellow!70,purple!70},
    chartSep=13pt,shadow,shadowsize=5pt]{45,25,15,15}{4}{2}
 \pscircle*{0.5}
 \psset{nodesepA=5pt,nodesepB=-10pt}
 \ncline{psChartO1}{psChart1}\nput{0}{psChartO1}{\CPut{blue}{Foo\\ 45\,\%}}
 \ncline{psChartO2}{psChart2}\nput{150}{psChartO2}{\CPut{orange}{Bar\\ 25\%}}
 \ncline{psChartO3}{psChart3}\nput{-90}{psChartO3}{\CPut{yellow}{Baz\\ 15\%}}
 \ncline{psChartO4}{psChart4}\nput{0}{psChartO4}{\CPut{purple}{FBa\\ 15\%}}
 \rput(psChartI1){Taxes}\rput(psChartI2){Rent}\rput(psChartI3){Bills}\rput(psChartI4){Car}
  \rput(0,0){\bfseries\white Rock}
 \end{pspicture}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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