% This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
% Example 124 Pie Chart (Changing and Referencing the Segment Colours)
% Label: "ex:piechartcolors"
% arara: pdflatex
% arara: pdfcrop
\documentclass[12pt]{article}
\pagestyle{empty}
% sample CSV file:
\begin{filecontents}[noheader,overwrite]{fruit.csv}
Name,Quantity
"Apples",30
"Pears",25
"Lemons,Limes",40.5
"Peaches",34.5
"Cherries",20
\end{filecontents}


\usepackage{datapie}
% Load data from fruit.csv file:
\DTLsetup{store-datum,default-name=fruit}
\DTLread{fruit.csv}
% change the colours for the third and fourth segments:
\DTLsetpiesegmentcolor{3}{yellow}
\DTLsetpiesegmentcolor{4}{pink}
% customize the label format:
\renewcommand{\DTLdisplayinnerlabel}[1]{% 
 \textcolor{lightgray}{\bfseries #1}% 
}
\renewcommand{\DTLdisplayouterlabel}[1]{% 
 \DTLdocurrentpiesegmentcolor
 \textsf{\shortstack{#1}}}

\begin{document}
\DTLpiechart
{
 variable=\Quantity,
 outline-width=2pt,
 round=0,
 inner-label=\DTLpiepercent\%,
 outer-label=\Name\\(\DTLpievariable)
}
{fruit}% database
{\Quantity=Quantity,\Name=Name}
% legend:
\begin{tabular}[b]{ll}
\DTLforeach{fruit}{\Name=Name}{% 
 \DTLiffirstrow{}{\\}% 
 \DTLdocurrentpiesegmentcolor 
 \rule{10pt}{10pt} & 
 \Name
}
\end{tabular} 
\end{document}
