How to draw Kiviat Diagrams
It was interesting to make a package to use TikZ to build Kiviat Diagram. This package is now on CTAN:
tkz-kiviat
.
You can find some examples on my homepage:
kiviat examples.
The first example uses three macros with arguments. First, you create a spider, then you can create a kiviat polygon and you can create graduations
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usetikzlibrary{arrows}
\thispagestyle{empty}
\begin{document}
\begin{tikzpicture}
\tkzKiviatDiagram[scale=1.25,label distance=.5cm,
radial = 5,
gap = 1,
lattice = 5]{McCabe,LOC,Live Variables,Halstead N,Variablenspanne}
\tkzKiviatLine[thick,color=blue,mark=none,
fill=blue!20,opacity=.5](3,3.5,3,3.5,3)
\tkzKiviatLine[thick,color=darkgray,
fill=green!20,opacity=.5](0.5,1,0.5,0.75,1)
\tkzKiviatLine[ultra thick,mark=ball,
mark size=4pt,color =Maroon](2,3.75,1,1.5,2)
\tkzKiviatGrad[prefix=,unity=100,suffix=\ \texteuro](1)
\end{tikzpicture}
\end{document}
Another solution is to use an external file with data
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplotstable}
\usetikzlibrary{arrows}
\thispagestyle{empty}
\begin{document}
\begin{tikzpicture}
\tkzKiviatDiagramFromFile[
scale=.5,
label distance=.5cm,
gap = 1,label space=3,
lattice = 10]{tableae.dat}
\tkzKiviatLineFromFile[thick,
color = blue,
mark = ball,
ball color = blue,
mark size = 4pt,
fill = blue!20]{tableae.dat}{2}
\tkzKiviatLineFromFile[thick,
color = red,
mark = ball,
ball color = red,
mark size = 4pt,
fill = red!20]{tableae.dat}{1}
\end{tikzpicture}
\end{document}
The tableae.dat file is used with the package pgfplotstable.sty
%tableae.dat
column1 column2 column3
Reliability 6 6.5
Usability 4 9
{Application Architecture} 7 8
{Version Control} 6.5 7
Timeliness 2 8
Efficiency 3 4
Effectiveness 5 6.5
Interoperability 1.5 7
I'd go fot the tikz
package.
Have a look at this example.
I've written a crude set of macro's that might help you on your way when making your own (adjust these and you should be fine).
I'm not that great a programmer myself so perhaps someone else will come up with something much more refined but this will do for now. The upside to my little programming skills is that the code is easy, so you'll probably be able to grasp it quickly and adjust it to your needs.
There are 4 macro's. The main macro is \spider
, it takes as much parameters as there are axes (I've written the code for 8 axes, adjust it if you need more or less using the \n
command and some tweaking in the code). Each paramter of \spider
stands for a value on the the corresponding axis.
\outertolerance
works the same way as spider and sets the outer tolerance band for the next \spider
to take into account. The same way \innertolerance
sets the values for the inner tolerance band.
Everytime a \spider
is used the \outertolerance
and \innertolerance
values are reset to nothing (draw no tolerance bands). You can also reset them youerself this by hand using \resettolerance
Add this to preamble:
\usepackage{tikz}
\def\n{8} %define how much axes you want
\def\N{5} %define the number of node on each axis
\newcommand{\spider}[\n]{
\begin{tikzpicture}[scale=0.5]
\thebigtolerance
\foreach \x in{0,1,...,\n}{%
\draw[->] (0,0)--(360/\n*\x:\N+0.5);
\foreach \y in{0,1,...,\N}{
\draw[thin,lightgray](360/\n*\x:\y)--(360/\n*\x+360/\n:\y);
\draw[fill] (360/\n*\x:\y) circle(0.75pt);
}
}
\draw(360/\n:\N+0.5)node[right]{axis1}; %adjust the labels (also add or delete exces axes)
\draw(2*360/\n:\N+0.5)node[above]{axis2}; %eg. if you have 6 axes, delete the last 2
\draw(3*360/\n:\N+0.5)node[left]{axis3}; %or if you have 9 axes add one
\draw(4*360/\n:\N+0.5)node[left]{axis4};
\draw(5*360/\n:\N+0.5)node[left]{axis5};
\draw(6*360/\n:\N+0.5)node[below]{axis6};
\draw(7*360/\n:\N+0.5)node[right]{axis7};
\draw(8*360/\n:\N+0.5)node[right]{axis8};
\thesmalltolerance
\draw[thick,draw=red](360/\n:#1)--(360/\n*2:#2)--(360/\n*3:#3)--(360/\n*4:#4)--(360/\n*5:#5)--(360/\n*6:#6)--(360/\n*7:#7)--(360/\n*8:#8)--cycle;
%add or remove coordinates if you have more or less than 8 axes
\end{tikzpicture}
\resettolerance
}
\newcommand{\thesmalltolerance}[0]{}
\newcommand{\innertolerance}[\n]{
\renewcommand{\thesmalltolerance}{\draw[fill=gray,thick,opacity=0.3](360/\n:#1)--(360/\n*2:#2)--(360/\n*3:#3)--(360/\n*4:#4)--(360/\n*5:#5)--(360/\n*6:#6)--(360/\n*7:#7)--(360/\n*8:#8)--cycle;}
%add or remove coordinates if you have more or less than 8 axes
}
\newcommand{\thebigtolerance}[0]{}
\newcommand{\outertolerance}[\n]{
\renewcommand{\thebigtolerance}{
\foreach \x in{1,2,...,\n}{
\draw[draw=none,fill=gray,opacity=0.3](0,0)--(360/\n*\x:\N)--(360/\n*\x+360/\n:\N);}
\draw[fill=white,thick,draw=gray](360/\n:#1)--(360/\n*2:#2)--(360/\n*3:#3)--(360/\n*4:#4)--(360/\n*5:#5)--(360/\n*6:#6)--(360/\n*7:#7)--(360/\n*8:#8)--cycle;
%add or remove coordinates if you have more or less than 8 axes
}
}
\newcommand{\resettolerance}[0]{%resets the tolerance band to none
\renewcommand{\thebigtolerance}{}
\renewcommand{\thesmalltolerance}{}
}
As said above, you will need to adjust the drawing commands to fit the number of axis. This means adding (360/\n*9:#9)--
if you want nine axes. Or removing (360/\n*8:#8)--
if you want 7 axes. You should do this in 3 places (in the \spider
command, and in \outertolerance
and \innertolerance
. The adjustment should be the same for every command.
You can also adjust the number of nodes on each axis by adjusting the \N
number. You might have to also adjust the scaling=0.5
because more nodes means a bigger chart.
I've also made an example of how to actually draw the spider chart:
\outertolerance{4}{4}{4}{3}{4}{4}{4.5}{4}%defines the outer toleranceband for next spider
\innertolerance{1}{1}{1}{1}{1}{2}{2}{1}%defines the inner toleranceband for next spider
\spider{2}{2}{2}{2}{3}{4}{4}{3}%draws the spider diagram with coordinates
Hope this helps!
With the current pstricks-add.tex you can simplify it:
\documentclass{article}
\usepackage{pstricks-add}
\def\Tab#1{\tabular{@{}l@{}}#1\endtabular}
\begin{document}
\psframebox*[fillcolor=yellow!15]{%
\begin{pspicture}(-6,-5)(5,5)
\psset{unit=1.2}
\psKiviat[rotate=0.5,
yLabels={Marketing,Sales,Administration,\Tab{Information\\Technology},%
\Tab{Customer\\Support},Developer},
labelsep=10pt]{6}{3}
\psKiviatTicklines[Dx=0.5,linecolor=black!30]{6}{3}
\psKiviatAxes[linecolor=black!30]{7}{3}
\psKiviatLine[linewidth=2pt,linecolor=blue!60]{1,2,1,1.7,1.3,3}
\psKiviatLine[linewidth=2pt,linecolor=red!60]{2.25,2.5,0.6,1.2,1,1}
\multido{\rA=0.5+0.5,\iA=10+10}{6}{\uput[3](0,\rA){\$\iA}}
\end{pspicture}}
\clearpage
\begin{pspicture}(-5,-5)(5,5)
\psKiviat[fillstyle=solid,fillcolor=red!20,
yLabels={McCabe,LOC,Live Variables,Halstead N,Variablenspanne},
labelsep=20pt]{5}{4}
\psKiviatLine[fillstyle=solid,fillcolor=white]{3,3.5,3,3.5,3}
\psKiviatLine[fillstyle=solid,fillcolor=black!10]{0.5,1,0.5,0.75,1}
\psKiviatLine[dotstyle=square*,linewidth=1.5pt,linecolor=red]{2,3.75,1,1.5,2}
\psKiviatTicklines[Dx=0.5,subtickcolor=black!15]{5}{4}
\psKiviatAxes[arrows=->,arrowscale=2]{5}{4.5}
\end{pspicture}
\end{document}