I spent few days trying to "macrofy" the rendering of piechart, barchart, and spiderweb from raw data input wihtin the document. I wanted some high level API like
Code: Select all
Code, edit and compile here:
\barchart{5cm} %%label width{ %% data (label/value)apples/432,banana/34,pineapples/1223}%%barchart\spiderweb %% 0 to 100 grid{4,5cm} %% radius for labels{3,5cm} %% radius for spiderweb{70} %% baseline score{ %% data (label/score)Fifty/10,Sixty/20,Seventy/50}%%spiderwebor\def\colorCycleList{{"blue","red","yellow","green", "orange", "gray" }}\piechart{(Very Low,37),(Low,23),(Average,34),(High,5),(Very High,1)}%%piechart
Macro for piechart with example :
Code: Select all
Code, edit and compile here:
\documentclass{standalone}\usepackage{tikz}\usepackage{fp}\usepackage{pgfplots}\usepackage{xintexpr}\usepackage{xstring}%% originaly used with babel french, which causes some issues%% wihout the following line\usetikzlibrary{babel}\def\colorCycleList{{"blue","red","yellow","green", "orange", "gray" }}%%%% #1 = list of titles and values (not percents)%%%% example :%%%% \piechart{%% (Very Low,37),%% (Low,23),%% (Average,34),%% (High,5),%% (Very High,1)%% }%%\newcounter{totalPieChart}\newcommand{\piechart}[1]{%compute total in order to compute percentages\setcounter{totalPieChart}{0}\xintForpair ##1##2 in{#1} \do {\addtocounter{totalPieChart}{##2}}%get the number of colors in the \colorCycleList\pgfmathparse{int(dim(\colorCycleList)-1)}\edef\cycleColorMax{\pgfmathresult}\begin{tikzpicture}[nodes = {font=\sffamily}, scale=1]\def\angle{0}
Code: Select all
Code, edit and compile here:
\documentclass{standalone}\usepackage{tikz}\usepackage{pgfplots}%% originaly used with babel french, which causes some issues%% wihout the following line\usetikzlibrary{babel}%%%% #1 = radius (4cm is good)%% #2 = radius for labels (3.5cm)%% #3 = score baseline (blue line)%% #4 = list of titles and values%%%% example%%%% \spiderweb{4,5cm}{3,5cm}{70}{%% Sécurité/10,%% Maintenabilité/30,%% Fiabilité/50,%% Portabilité/70,%% Performance/90%% }%%\newcommand{\spiderweb}[4]{\newcount\numberOfDimensionsForSpiderWebCounter \numberOfDimensionsForSpiderWebCounter=0\foreach \Title/\Score in {#4} {\global\advance\numberOfDimensionsForSpiderWebCounter by 1 % Advance cyclecount}\def\numberOfDimensionsForSpiderWeb{\the\numberOfDimensionsForSpiderWebCounter} % number of dimensions (config option)\def\numberOfScaleUnits{100} % number of scale units (config option)\def\calculatedAngleBetweenDimAxes{360/\numberOfDimensionsForSpiderWeb} % calculated angle between dimension axes\newdimen\R % maximal diagram radius (config option)\newdimen\L % radius to put dimension labels (config option)\L=#1\R=#2
Code: Select all
Code, edit and compile here:
\documentclass{report}\usepackage[left=20mm,right=20mm, top=30mm, bottom=30mm,a4paper]{geometry}\usepackage[usenames,dvipsnames,table,xcdraw]{xcolor}\usepackage{pgfplots}\usepackage{setspace}\usepackage{siunitx}\usepackage{tikz}\usepackage{wallpaper}\usepackage{xintexpr}\usetikzlibrary{shadows}%% originaly used with babel french, which causes some issues%% wihout the following line\usetikzlibrary{babel}\makeatletter\newcommand*{\getlengthincm}[1]{\strip@pt\dimexpr0.035146\dimexpr#1\relax\relax}\makeatother\newcommand{\nume}[1]{\num[group-separator=\text{~},output-decimal-marker={,},group-digits=integer,group-minimum-digits=4]{#1}}%%%% #1 = label width%% #2 = list of titles and values%%%% example:%%%% \barchart{6cm}{%% apples/2047,%% pears/1244,%% banana/1208,%% {a fruit name with slashes / well / ...}/1055,%% {a fruit name}/9009%% }%%\newcommand{\barchart}[2]{%% reorder list (thanks \foreach...)

Feel free to use and comment.
Best regards.