| 1 |
% This file is public domain. |
| 2 |
\documentclass[captions=tableheading]{scrartcl} |
| 3 |
|
| 4 |
\usepackage{tikz} |
| 5 |
\usetikzlibrary{snakes} |
| 6 |
|
| 7 |
\usepackage{databar} |
| 8 |
|
| 9 |
\DTLloaddb{marks}{sample-student-records.csv} |
| 10 |
|
| 11 |
\begin{document} |
| 12 |
|
| 13 |
% Compute average mark for each student: |
| 14 |
\DTLforeach{marks}{% |
| 15 |
\assignI=Assignment 1,% |
| 16 |
\assignII=Assignment 2,% |
| 17 |
\assignIII=Assignment 3}{% |
| 18 |
\DTLmeanforall{\theMean}{\assignI,\assignII,\assignIII}% |
| 19 |
\DTLround{\theMean}{\theMean}{0}\DTLclip{\theMean}{\theMean}% |
| 20 |
\DTLappendtorow{Average}{\theMean}} |
| 21 |
|
| 22 |
\begin{table} |
| 23 |
\caption{Student Marks} |
| 24 |
\centering |
| 25 |
\DTLdisplaydb[Address,RegNum,Title]{marks} |
| 26 |
\end{table} |
| 27 |
|
| 28 |
\begin{figure}[htbp] |
| 29 |
\centering |
| 30 |
% compute the overall mean |
| 31 |
\DTLmeanforkeys{marks}{Average}{\overallmean} |
| 32 |
% round it to 2 decimal places |
| 33 |
\DTLround{\overallmean}{\overallmean}{2} |
| 34 |
% draw a grey dotted line indicating the overall mean |
| 35 |
% covering the entire width of the bar chart |
| 36 |
\renewcommand*{\DTLbaratendtikz}{% |
| 37 |
\draw[lightgray,loosely dotted] (0,\overallmean) -- |
| 38 |
(\DTLbarchartwidth,\overallmean) |
| 39 |
node[right,black]{Average (\overallmean)};} |
| 40 |
% Set the lower bar labels to draw a brace across the current |
| 41 |
% group, along with the student's name and average score |
| 42 |
\renewcommand*{\DTLdisplaylowerbarlabel}[1]{% |
| 43 |
\tikz[baseline=(current bounding box.center)]{ |
| 44 |
\draw[snake=brace,rotate=-90](0,0) -- (\DTLbargroupwidth,0);} |
| 45 |
\DTLround{\theMean}{\theMean}{2}% |
| 46 |
\shortstack{#1\\(Average: \theMean)}} |
| 47 |
% draw the bar chart |
| 48 |
\DTLmultibarchart{variables={\assignI,\assignII,\assignIII}, |
| 49 |
barwidth=10pt,uppermultibarlabels={\assignI,\assignII,\assignIII}, |
| 50 |
barlabel={\firstname\ \surname}}{marks} |
| 51 |
{\surname=Surname,\firstname=First Name,\assignI=Assignment 1,% |
| 52 |
\assignII=Assignment 2,\assignIII=Assignment 3,\theMean=Average} |
| 53 |
\caption{Student marks} |
| 54 |
\end{figure} |
| 55 |
|
| 56 |
|
| 57 |
\end{document} |