I am trying to create a wheel chart and it displays almost fine but i still have an error:
Package tikz Error: Cannot parse this coordinate.
main.tex, 32 See the tikz package documentation for explanation. Type H for immediate help. ...
l.32 }This error message was generated by an \errmessage command, so I can't give any explicit help. Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.
i am running this code:
\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}
with this macro to generate the wheel chart:
\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}
}
Here is the chart it generates:
shift=\labelshiftdir*0.5cm
is your mistake. Theshift
key expects a coordinate, e.g.shift=(\midangle:\labelshiftdir*0.5cm)
? By the way, there are thepgf-pie
and thewheelchart
packages.