[Tex/LaTex] Customed Pie Chart

graphicstikz-pgf

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)

Best Answer

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