在饼图/环形图中的每个扇区后绘制一条白线/间隙

在饼图/环形图中的每个扇区后绘制一条白线/间隙

正如标题所述,我想在圆环图的每个扇区后画一条白线/间隙。目前,我正在使用的代码正在生成令人惊叹的圆环图,但如果每个扇区后都有白线/间隙就更好了。

这是我的代码目前正在生成的图表:

在此处输入图片描述

梅威瑟:

\documentclass{article}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%
%Donut Chart
%%%%%%%%%%%%%%%%%%%%
\def\innerradius{0.7cm}
\def\outerradius{1.9cm}
\pgfmathsetlengthmacro{\centerradius}{(\outerradius + \innerradius)/2}
\pgfmathsetlengthmacro{\donutcenter}{\innerradius/2}
 % The Macro
\newcommand{\donutchart}[1]{
   % Calculate total
   \pgfmathsetmacro{\totalnum}{0}
   \foreach \value/\colour/\name in {#1} {
     \pgfmathparse{\value+\totalnum}
     \global\let\totalnum=\pgfmathresult
   }

  \begin{tikzpicture}

  \pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
  \pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}

  \begin{scope}[rotate=90]

    \pgfmathsetmacro{\cumnum}{0}
    \foreach \value/\colour/\name in {#1} {
        \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}

        \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}

        \fill[\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
        (-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;

        \fill[darkgray!25] circle (\innerradius);

        \draw node [text=white, font=\bfseries] at (\midangle:{\innerradius+\wheelwidth/2}) {\name};

        \node[scale=1.0, color=black, font=\bfseries](\innerradius) {A};

        \global\let\cumnum=\newcumnum
    }

  \end{scope}

  \end{tikzpicture}}

\begin{document}

 \donutchart{15/blue/A1,15/green/A2, 15/red/A3, 15/orange/A4, 10/teal/A5, 10/violet/A6, 20/purple/A7}

\end{document}

答案1

使用\filldraw而不是\fill

\documentclass{article}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%
%Donut Chart
%%%%%%%%%%%%%%%%%%%%
\def\innerradius{0.7cm}
\def\outerradius{1.9cm}
\pgfmathsetlengthmacro{\centerradius}{(\outerradius + \innerradius)/2}
\pgfmathsetlengthmacro{\donutcenter}{\innerradius/2}
 % The Macro
\newcommand{\donutchart}[1]{
   % Calculate total
   \pgfmathsetmacro{\totalnum}{0}
   \foreach \value/\colour/\name in {#1} {
     \pgfmathparse{\value+\totalnum}
     \global\let\totalnum=\pgfmathresult
   }

  \begin{tikzpicture}

  \pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
  \pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}

  \begin{scope}[rotate=90]

    \pgfmathsetmacro{\cumnum}{0}
    \foreach \value/\colour/\name in {#1} {
        \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}

        \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}

        \filldraw[draw=white,fill=\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
        (-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;

        \fill[darkgray!25] circle (\innerradius);

        \draw node [text=white, font=\bfseries] at (\midangle:{\innerradius+\wheelwidth/2}) {\name};

        \node[scale=1.0, color=black, font=\bfseries](\innerradius) {A};

        \global\let\cumnum=\newcumnum
    }

  \end{scope}

  \end{tikzpicture}}

\begin{document}

 \donutchart{15/blue/A1,15/green/A2, 15/red/A3, 15/orange/A4, 10/teal/A5, 10/violet/A6, 20/purple/A7}

\end{document}

在此处输入图片描述

答案2

gap选择来自wheelchart包做到了。

\documentclass[tikz, border=2mm]{standalone}
\usepackage{wheelchart}
\usepackage{lmodern}

\begin{document}

\begin{tikzpicture}\wheelchart[
gap,
middle fill=gray!30, 
middle style={font=\LARGE\bfseries},
middle={A},
radius={1}{2.5},
data={},
wheel data style={text=white, font=\Large\bfseries},
wheel data={\WCvarC},
wheel data pos=0.5,
]{%
15/blue/A1,
15/green/A2,
15/orange/A4,
10/teal/A5,
10/violet/A6,
20/purple/A7}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容