我正在尝试创建一个轮图,它显示得几乎正常,但仍然有一个错误:
包 tikz 错误:无法解析此坐标。
main.tex, 32 请参阅 tikz 包文档以了解解释。输入 H 可立即获得帮助。...
l.32 }此错误消息是由 \errmessage 命令生成的,因此我无法提供任何明确的帮助。假设您是赫尔克里·波洛:检查所有线索,并按顺序和方法推断真相。
我正在运行此代码:
\begin{repenv}
\begin{center}
\wheelchartwithlegend{
12/green/state 1,
1/red/state 2,
1/yellow/state 3,
1/gray/state 4
}
\end{center}
\end{repenv}
用这个宏来生成轮图:
\usepackage{color}
\usepackage{tikz}
\usepackage{longtable}
\usepackage{multirow}
\usetikzlibrary{arrows.meta}
\def\innerradius{1.8cm}
\def\outerradius{2.2cm}
% The main macro
\newcommand{\wheelchartwithlegend}[1]{
% Calculate total
\pgfmathsetmacro{\totalnum}{0}
\foreach \value/\colour/\name in {#1} {
\pgfmathparse{\value+\totalnum}
\global\let\totalnum=\pgfmathresult
}
% \begin{tikzpicture}[every node/.style={scale=1.4}]
\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]
% add coordinate to define the upper left starting point of the legend entries
\coordinate (L-0) at (\outerradius-3mm,-\outerradius-2.5cm);
% Loop through each value set. \cumnum keeps track of where we are in the wheel
\pgfmathsetmacro{\cumnum}{0}
\foreach [count=\i,remember=\i as \j (initially 0)] \value/\colour/\name in {#1} {
\pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}
% Calculate the percent value
% \pgfmathsetmacro{\percentage}{\value/\totalnum*100}
\pgfmathsetmacro{\percentage}{\value}
% 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 [Circle-,thin] node [
append after command={
(\midangle:\midradius pt) -- (\midangle:\outerradius + 1ex) -- (\tikzlastnode)
}
] at (\midangle:\outerradius + 1ex) [shift=\labelshiftdir*0.5cm,inner sep=1pt, outer sep=1pt, ,anchor=\textanchor]{\pgfmathprintnumber{\percentage}};
% add legend node
\node [anchor=north west,text width=5cm,font=\footnotesize] (L-\i) at (L-\j.south west) {\textcolor{\colour}{\faPlug} \value \\ \name};
% Set the old cumulated angle to the new value
\global\let\cumnum=\newcumnum
}
\end{scope}
\end{tikzpicture}
}
以下是它生成的图表:
答案1
你知道吗wheelchart
包裹?
\documentclass[tikz]{standalone}
\usepackage{wheelchart}
\usetikzlibrary{decorations.markings}
\usepackage{fontawesome}
\usepackage{etoolbox}
\begin{document}
\begin{tikzpicture}
\newcommand{\WClegend}{}
\newcommand{\WClegendrow}[3]{%
\begin{tabular}{l}
\textcolor{#1}{\faPlug}\ #2\\#3
\end{tabular}\\
}
\wheelchart[data=\WCvarA,
data style={text=gray},
legend entry={
\gappto\WClegend{\WClegendrow}
\xappto\WClegend{{\WCvarB}{\WCvarA}{\WCvarC}}
},
legend={
\node[anchor=west] at (3.5,0) {%
\begin{tabular}{l}
\WClegend
\end{tabular}
};
},
lines,
lines sep=-0.5,
lines style={
gray!30,
postaction=decorate,
decoration={
markings,
mark=at position 0 with {
\fill[gray!30] (0,0) circle[radius=2pt];
}
}
}
]{
12/green/{state 1},
1/red/{state 2},
1/yellow/{state 3},
1/gray/{state 4}
}
\end{tikzpicture}
\end{document}