0

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:

wheel chart generated by this code

2
  • 3
    Welcome. shift=\labelshiftdir*0.5cm is your mistake. The shift key expects a coordinate, e.g. shift=(\midangle:\labelshiftdir*0.5cm)? By the way, there are the pgf-pie and the wheelchart packages. May 19 at 16:07
  • Thank you, it worked with this
    – Balansoire
    May 22 at 8:34

1 Answer 1

2

Do you know the wheelchart package?

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .