| 1 |
% This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04 |
| 2 |
% Example 124 Pie Chart (Changing and Referencing the Segment Colours) |
| 3 |
% Label: "ex:piechartcolors" |
| 4 |
% arara: pdflatex |
| 5 |
% arara: pdfcrop |
| 6 |
\documentclass[12pt]{article} |
| 7 |
\pagestyle{empty} |
| 8 |
% sample CSV file: |
| 9 |
\begin{filecontents}[noheader,overwrite]{fruit.csv} |
| 10 |
Name,Quantity |
| 11 |
"Apples",30 |
| 12 |
"Pears",25 |
| 13 |
"Lemons,Limes",40.5 |
| 14 |
"Peaches",34.5 |
| 15 |
"Cherries",20 |
| 16 |
\end{filecontents} |
| 17 |
|
| 18 |
|
| 19 |
\usepackage{datapie} |
| 20 |
% Load data from fruit.csv file: |
| 21 |
\DTLsetup{store-datum,default-name=fruit} |
| 22 |
\DTLread{fruit.csv} |
| 23 |
% change the colours for the third and fourth segments: |
| 24 |
\DTLsetpiesegmentcolor{3}{yellow} |
| 25 |
\DTLsetpiesegmentcolor{4}{pink} |
| 26 |
% customize the label format: |
| 27 |
\renewcommand{\DTLdisplayinnerlabel}[1]{% |
| 28 |
\textcolor{lightgray}{\bfseries #1}% |
| 29 |
} |
| 30 |
\renewcommand{\DTLdisplayouterlabel}[1]{% |
| 31 |
\DTLdocurrentpiesegmentcolor |
| 32 |
\textsf{\shortstack{#1}}} |
| 33 |
|
| 34 |
\begin{document} |
| 35 |
\DTLpiechart |
| 36 |
{ |
| 37 |
variable=\Quantity, |
| 38 |
outline-width=2pt, |
| 39 |
round=0, |
| 40 |
inner-label=\DTLpiepercent\%, |
| 41 |
outer-label=\Name\\(\DTLpievariable) |
| 42 |
} |
| 43 |
{fruit}% database |
| 44 |
{\Quantity=Quantity,\Name=Name} |
| 45 |
% legend: |
| 46 |
\begin{tabular}[b]{ll} |
| 47 |
\DTLforeach{fruit}{\Name=Name}{% |
| 48 |
\DTLiffirstrow{}{\\}% |
| 49 |
\DTLdocurrentpiesegmentcolor |
| 50 |
\rule{10pt}{10pt} & |
| 51 |
\Name |
| 52 |
} |
| 53 |
\end{tabular} |
| 54 |
\end{document} |