4

I am writing my Bachelor thesis and I am facing some issues drawing a spiderweb diagram. I am trying to load my data from a csv file using the csvsimple package, but latex is interpreting D1 to D7 as functions. Is there any way to prevent pgf to do that?

This is the error: ! Package PGF Math Error: Unknown function `D1' (in 'D1-11').

\documentclass[cleardoublepage=empty, listof=totoc, bibliography=totoc, index=totoc, 11pt, abstracton, numbers=noenddot, oneside,titlepage,openright,headings=normal]{scrreprt}
\usepackage{filecontents}
\usepackage{csvsimple}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes}

\begin{document}

\begin{filecontents*}{data.csv}
Vertreter;Portability;Compatibility;Performance efficiency;Usability;Security;Reliability;Functional Suitability
SAPUI5;12,4;10,4;11,0;14,9;10,5;15,0;15,0
Apache Cordova;11,9;13,2;10,7;9,9;11,0;15,0;14,8
Xamarin;11,4;13,2;15,0;12,8;11,9;15,0;14,1
Android ;7,8;13,2;15,0;12,8;11,9;15,0;14,1

\end{filecontents*}

\newcommand{\D}{7} % number of dimensions (config option)
\newcommand{\U}{7} % number of scale units (config option)

\newdimen\R % maximal diagram radius (config option)
\R=3.5cm 
\newdimen\L % radius to put dimension labels (config option)
\L=4.5cm

\newcommand{\A}{360/\D} % calculated angle between dimension axes  


\begin{figure}
\centering

\begin{tikzpicture}[scale=1]
\path (0:0cm) coordinate (O); % define coordinate for origin

% draw the spiderweb
\foreach \X in {1,...,\D}{
    \draw (\X*\A:0) -- (\X*\A:\R);
}

\foreach \Y in {0,...,\U}{
    \foreach \X in {1,...,\D}{
        \path (\X*\A:\Y*\R/\U) coordinate (D\X-\Y);
        \fill (D\X-\Y) circle (1pt);
    }
    \draw [opacity=0.3] (0:\Y*\R/\U) \foreach \X in {1,...,\D}{
        -- (\X*\A:\Y*\R/\U)
    } -- cycle;
}

% define labels for each dimension axis (names config option)
\path (1*\A:\L) node (L1) {\tiny Portabilität};
\path (2*\A:\L) node (L2) {\tiny Kompatibilität};
\path (3*\A:\L) node (L3) {\tiny Leistungseffizienz};
\path (4*\A:\L) node (L4) {\tiny Usability};
\path (5*\A:\L) node (L5) {\tiny Sicherheit};
\path (6*\A:\L) node (L6) {\tiny Verlässlichkeit};
\path (7*\A:\L) node (L7) {\tiny Funkt. Eignung};

\csvreader[separator=semicolon]
    {data.csv}
    {Vertreter=\v,Portability=\port,Compatibility=\comp,Performance efficiency=\perf,Usability=\use,Security=\secur,Reliability=\rel,Functional Suitability=\func}
    {
        \draw[color=blue,line width=1.5pt,opacity=0.5]
            (D1-\perf) -- 
            (D2-\comp) -- 
            (D3-\perf) -- 
            (D4-\use) -- 
            (D5-\secur) -- 
            (D6-\rel) -- 
            (D7-\func) -- cycle;
    }


\end{tikzpicture}
\caption{Spiderweb Diagram (\D~Dimensions, \U-Notch Scale, 3 Samples)}
\label{fig:spiderweb}
\end{figure}

\end{document}
Stefan Pinnow
  • 29,535

1 Answers1

5

In your code you define seven named coordinates along each "branch" of the web, e.g. D1-1, D1-2, ... D1-7. But your data has decimal values, not indices.

Take for example the first value in the "Performance efficiency" column, which is 11,4. In the \draw statement you use (D1-\perf), which becomes (D1-11,4). TikZ interprets this as a Cartesian coordinate I think, because it has the structure (x,y). And because the x-component isn't a numerical value, it tries to interpret it as a function, but there is of course no function D1-11.

(And the first coordinate should have \port, not \perf, for that matter.)

Instead of coordinates such as (D1-\perf), you probably want coordinates like (\A*1:\perf/\datascale). These are polar coordinates, as you might recognize. \datascale is a new macro that just holds a number, that you can adjust to get the appropriate scaling. For this to work though, you have to replace the commas in the data by periods.

In the code below I also added a new column in your data for the colour of the lines, if you'd like to use different colours. And for fun, add a legend on the right.

output of code

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}

\usepackage{filecontents}
\usepackage{csvsimple}
\usepackage{pgfplots} % loads tikz
\usetikzlibrary{shapes}

\begin{document}

% replaced commas with periods
% added colour-column
\begin{filecontents*}{data.csv}
Vertreter;Portability;Compatibility;Performance efficiency;Usability;Security;Reliability;Functional Suitability;colour
SAPUI5;12.4;10.4;11.0;14.9;10.5;15.0;15.0;blue
Apache Cordova;11.9;13.2;10.7;9.9;11.0;15.0;14.8;red
Xamarin;11.4;13.2;15.0;12.8;11.9;15.0;14.1;green
Android ;7.8;13.2;15.0;12.8;11.9;15.0;14.1;cyan
\end{filecontents*}

\newcommand{\D}{7} % number of dimensions (config option)
\newcommand{\U}{7} % number of scale units (config option)

\newdimen\R % maximal diagram radius (config option)
\R=3.5cm 
\newdimen\L % radius to put dimension labels (config option)
\L=4.5cm

\newcommand{\A}{360/\D} % calculated angle between dimension axes  


\begin{figure}
\centering

\begin{tikzpicture}[scale=1]
\path (0:0cm) coordinate (O); % define coordinate for origin

% draw the spiderweb
\foreach \X in {1,...,\D}{
    \draw (\X*\A:0) -- (\X*\A:\R);
}

\foreach \Y in {0,...,\U}{
    \foreach \X in {1,...,\D}{
        \path (\X*\A:\Y*\R/\U) coordinate (D\X-\Y);
        \fill (D\X-\Y) circle (1pt);
    }
    \draw [opacity=0.3] (0:\Y*\R/\U) \foreach \X in {1,...,\D}{
        -- (\X*\A:\Y*\R/\U)
    } -- cycle;
}

% define labels for each dimension axis (names config option)
\foreach [count=\i] \txt in
       {Portabilität,Kompatibilität,Leistungseffizienz,
        Usability,Sicherheit,Verlässlichkeit,Funkt. Eignung}
   \node [font=\tiny] (L\i) at (\i*\A:\L) {\txt};

% common scale factor for the values
\newcommand\datascale{5}

\csvreader[separator=semicolon]
    {data.csv}
    {Vertreter=\v,Portability=\port,Compatibility=\comp,
     Performance efficiency=\perf,Usability=\use,Security=\secur,
     Reliability=\rel,Functional Suitability=\func,colour=\clr}
    {
        \draw[\clr,line width=1.5pt,opacity=0.5]
            (\A*1:\port/\datascale) -- 
            (\A*2:\comp/\datascale) -- 
            (\A*3:\perf/\datascale) -- 
            (\A*4:\use/\datascale) -- 
            (\A*5:\secur/\datascale) -- 
            (\A*6:\rel/\datascale) -- 
            (\A*7:\func/\datascale) -- cycle;

       % add legend
       \draw [line width=1.5pt,\clr,opacity=0.5] (\R*1.2,\R-12pt*\thecsvrow) -- ++(1,0) node[right,opacity=1,black] {\v};
    }


\end{tikzpicture}
\caption{Spiderweb Diagram (\D~Dimensions, \U-Notch Scale, 3 Samples)}
\label{fig:spiderweb}
\end{figure}
\end{document}
Torbjørn T.
  • 206,688