Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \ProvidesPackage{google_style_donut_chart}[2017/10/220 v1.0 Donut chart]
- \usepackage{tikz}
- \usepackage{xcolor}
- \definecolor{chartColor1}{HTML}{4285F4}
- \definecolor{chartColor2}{HTML}{DB4437}
- \definecolor{chartColor3}{HTML}{F4B400}
- \definecolor{chartColor4}{HTML}{0F9D58}
- \definecolor{chartColor5}{HTML}{AB47BC}
- \definecolor{chartColor6}{HTML}{00ACC1}
- % Adjusts the size of the wheel:
- \def\innerradius{2.0cm}
- \def\outerradius{4.2cm}
- % I found somewhere on the internet an template for this and I extended to fit.
- %
- % The default usage:
- % \wheelchart{28.3/chartColor1/Loading, 775.5/chartColor2/Scripting, 79.3/chartColor3/Rendering, 16/charColor4/Painting, 163/chartColor5/Other}
- \newcommand{\wheelchart}[1]{
- % Calculate total
- \pgfmathsetmacro{\totalnum}{0}
- \foreach \value/\color/\name [count=\xi] in {#1} {
- \pgfmathparse{\value+\totalnum}
- \global\let\totalnum=\pgfmathresult
- \global\let\allnum=\xi
- }
- \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}[line width=\wheelwidth,rotate=90]
- % Loop through each value set. \cumnum keeps track of where we are in the wheel
- \pgfmathsetmacro{\cumnum}{0}
- \foreach \value/\color/\name [count=\xi] in {#1} {
- \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}
- % Calculate the percent value
- \pgfmathsetmacro{\percentage}{\value/\totalnum*100}
- % Calculate the mid angle of the color segments to place the labels
- \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}
- % This is necessary for the labels to align nicely
- \pgfmathparse{
- (-\midangle<5?"south":
- (-\midangle<85?"south west":
- (-\midangle<105?"west":
- (-\midangle<175?"north west":
- (-\midangle<185?"north":
- (-\midangle<265?"north east":
- (-\midangle<275?"east":
- (-\midangle<355?"south east":"south")
- )
- )
- )
- )
- )
- )
- )
- } \edef\textanchor{\pgfmathresult}
- % Draw the color segments. Somehow, the \midrow units got lost, so we add 'pt' at the end. Not nice...
- \draw[color=\color] (-\cumnum:\midradius pt) arc (-\cumnum:-(\newcumnum):\midradius pt);
- % Draw the data labels
- \node [color=\color] at (\allnum/2-\xi, 7.0){\name: \value};
- % 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}
- }
Add Comment
Please, Sign In to add comment