我尝试了以下代码,但我不知道如何用不同的颜色填充不同的切片(三种不同的灰色比绿色、蓝色和黄色更好)。此外,我不知道如何在切片中放入文本,您能帮我吗?提前谢谢您 :)
\documentclass{article}
\usepackage{xstring,tikz}
\newcommand*\GetListMember[2]{\StrBetween[#2,\number\numexpr#2+1]{,#1,},,\par}%
\newlength{\MidRadius}
\newcommand*{\CircularSequence}[3]{%
% #1 = outer circle radius
% #2 = inner circle radius
% #3 = seqeunce
\StrCount{#3}{,}[\NumberOfElements]
\pgfmathsetmacro{\AngleSep}{360/(\NumberOfElements+1)}
\pgfmathsetlength{\MidRadius}{(#1+#2)/2}
\draw [black, ultra thick] circle (#2);
\draw [black, ultra thick] circle (#1);
\foreach [count = \Count] \Angle in {0,\AngleSep,..., 360} {%
\draw [gray, ultra thick] (\Angle:#2) -- (\Angle:#1);
\pgfmathsetmacro{\MidPoint}{\Angle+\AngleSep/2}
\node at (\MidPoint:\MidRadius) {\GetListMember{#3}{\Count}};
}%
}%
\begin{document}
\begin{tikzpicture}
\centering
\CircularSequence{6.0cm}{4.cm}{Liquidity Risk,Counterparty Risks,Management Risks,Corporate Governance Risk,Legal \& Regulatory Risks,Political and Social Risks,System Risk,Business Risks,Market Risks}
\end{tikzpicture}
\end{document}
答案1
为了使文本适合切片,您可以设置text width=2cm,align=center
适当的\node
。
可能有很多种方法可以设置颜色,下面代码中显示了其中一种可能性。请注意,我稍微重写了循环。我做的一件事是coordinate
在瓷砖的每个“内”角创建一个,稍后我会用到它。
内部切片采用更手工的方式制作。没有阴影,因为我不知道怎么做。
\documentclass{article}
\usepackage{xstring,tikz}
\usetikzlibrary{backgrounds}
\newcommand*\GetListMember[2]{\StrBetween[#2,\number\numexpr#2+1]{,#1,},,\par}%
\newlength{\MidRadius}
\newcommand*{\CircularSequence}[3]{%
% #1 = outer circle radius
% #2 = inner circle radius
% #3 = seqeunce
\StrCount{#3}{,}[\NumberOfElements]
\pgfmathtruncatemacro\NumberOfElements{\NumberOfElements+1}
\pgfmathsetmacro{\AngleSep}{360/(\NumberOfElements)}
\pgfmathsetlength{\MidRadius}{(#1+#2)/2}
\draw [black, ultra thick] circle (#2);
\draw [black, ultra thick] circle (#1);
\foreach [evaluate=\Count as \Angle using (\Count-1)*\AngleSep] \Count in {1,...,\NumberOfElements} {%
\ifnum\Count>6
\edef\myclr{black!40} % color for element 7-9
\else
\ifnum\Count>2
\edef\myclr{black!25} %color for element 3-6
\else
\edef\myclr{black!10} % color for element 1-2
\fi\fi
%fill the slice
\fill [\myclr] (\Angle:#2) coordinate (i-\Count) -- (\Angle:#1) arc[start angle=\Angle,delta angle=\AngleSep,radius=#1] -- (\Angle+\AngleSep:#2) arc[start angle=\Angle+\AngleSep,end angle=\Angle,radius=#2];
% draw the separator
\draw [gray, ultra thick] (\Angle:#2) -- (\Angle:#1);
\pgfmathsetmacro{\MidPoint}{\Angle+\AngleSep/2}
\node [text width=2cm,align=center] at (\MidPoint:\MidRadius) {\GetListMember{#3}{\Count}};
}%
}%
\begin{document}
\begin{tikzpicture}
\centering
\CircularSequence{6.0cm}{4.cm}{Liquidity Risk,Counterparty Risks,Management Risks,Corporate Governance Risk,Legal \& Regulatory Risks,Political and Social Risks,System Risk,Business Risks,Market Risks}
\begin{scope}[on background layer]
\foreach \clr/\txt/\txtang/\starti/\stopi in {%
black!15/Financial risk/50/1/3,%
black!30/Strategic risk/-70/3/7,%
black!45/Operational risk/-30/7/1%
}
{
\pgfmathsetmacro\startangle{(\starti-1)*360/9}
\pgfmathsetmacro\stopangle{(\stopi-1)*360/9}
\pgfmathsetmacro\deltaangle{ifthenelse(\stopangle-\startangle<0,\stopangle-\startangle+360,\stopangle-\startangle)}
\pgfmathsetmacro\textangle{\startangle+0.5*\deltaangle}
\fill [\clr] (i-\starti) -- ++({\startangle+180}:1cm) arc[start angle=\startangle,delta angle=\deltaangle,radius=3cm] -- (i-\stopi) arc[start angle=\stopangle,delta angle=-\deltaangle,radius=4cm];
\node [rotate=-\txtang] at (\textangle:3.4cm) {\txt};
}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这轮图我写的包,可以使用。
每个环都放置在单独的 中\wheelchart
。
首先\wheelchart
我们设置WClistcolors{1,2,3}=blue
、WClistcolors{4,5}=orange
和WClistcolors{6,7,8,9}=green
。因此,宏\WClistcolors
表示切片 1 至 3 为蓝色,切片 4 和 5 为橙色,切片 6 至 9 为绿色。此宏\WClistcolors
用于键slices style
。使用键value=1
是为了使每个切片的角度相同。无需在每个切片的文本中添加“风险”,因为这已添加到键 中wheel data
。
在第二个窗口中\wheelchart
,使用 键旋转车轮数据wheel data style
。第二个切片的角度使用 键单独指定wheel data style{2}
。
\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\begin{document}
\begin{tikzpicture}
\definecolor{blue1}{RGB}{193 211 231}
\definecolor{blue2}{RGB}{134 171 213}
\definecolor{blue3}{RGB}{136 167 191}
\definecolor{orange1}{RGB}{247 230 197}
\definecolor{orange2}{RGB}{253 217 155}
\definecolor{orange3}{RGB}{236 211 143}
\definecolor{green1}{RGB}{209 234 205}
\definecolor{green2}{RGB}{166 211 156}
\definecolor{green3}{RGB}{166 197 165}
\wheelchart[
data=,
radius={3.5}{5.7},
slices style={\WClistcolors1,draw=\WClistcolors3,ultra thick},
value=1,
WClistcolors{1,2,3}=blue,
WClistcolors{4,5}=orange,
WClistcolors{6,7,8,9}=green,
wheel data=\WCvarA\\Risks,
wheel data pos=0.5,
wheel data style={align=center}
]{%
Counterparty,
Liquidity,
Market,
Business,
System,
Political and\\Social,
Legal \&\\Regulatory,
Corporate\\Governance,
Management%
}
\wheelchart[
data=,
radius={2}{3.5},
wheel data=\WCvarC{} Risks,
wheel data pos=0.4,
wheel data style={rotate={\WCmidangle-90}},
wheel data style{2}={rotate={\WCmidangle+90}}
]{%
3/blue2/Financial,
2/orange2/Operational,
4/green2/Strategic%
}
\end{tikzpicture}
\end{document}