[texhax] Drawing colored pie chart in KOMA-Class scrreprt (preferably without manually installing pgf-pie

Pascal pascal.bernhard at belug.de
Sun Mar 23 13:50:45 CET 2014


Am Saturday, den 22.03.2014, 16:22 -0700 schrieb Suresh Govindachar:
> > On Fri, Mar 21, 2014 at 5:02 PM, Pascal <pascal.bernhard at belug.de> asked:
> 
> [for a simple, quick way to add a 2-dimensional pie chart with colors 
> without having to install pgf-pie]:
> 
>    > The first example works
>    > (http://www.texample.net/tikz/examples/pie-chart/), but I'm
>    > totally at a loss about how get colors into the pie chart.
>    > This basically does the trick, I do not aspire to fancy stuff
>    > like a drawn out slice, but colors I definitively would like
>    > to see.
>    [...]
>    > I should mention that in my case the pie chart is supposed to
>    > show that the markets is carved up by two companies, one
>    > having a 69 % market share, the other 29 %, which leaves 2 %
>    > for various other tiny firms.  I'm not sure whether I could
>    > modify the example above quite easily to fit my needs, so any
>    > help here would also be higly appreciated.
> 
> Here's a simple tweak to that example to get colors and to illustrate 
> your particular "69-29-2" example:
> 
> % Pie chart
> % Original Author: Robert Vollmert
> % Modified to illustrate coloring the slices by Suresh Govindachar
> %
> \documentclass{article}
> \usepackage{calc}
> \usepackage{ifthen}
> \usepackage{tikz}
> \begin{document}
> 
> \newcommand{\slice}[5]{
>    \pgfmathparse{0.5*#1+0.5*#2}
>    \let\midangle\pgfmathresult
> 
>    % slice
>    \draw[thick,fill=#5] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;
> 
>    % outer label
>    \node[label=\midangle:#4] at (\midangle:1) {};
> 
>    % inner label
>    \pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
>    \let\temp\pgfmathresult
>    \pgfmathparse{max(\temp,-0.5) + 0.8}
>    \let\innerpos\pgfmathresult
>    \node at (\midangle:\innerpos) {#3};
> }
> 
> \begin{tikzpicture}[scale=3]
> 
> \newcounter{a}
> \newcounter{b}
> \foreach \p/\t/\c in
> %
> % original example with color added %   {20/type A/green!20!white,
> % original example with color added %   4/type B/green!80!white,
> % original example with color added %   11/type C/yellow!60!black,
> % original example with color added %   49/type D/blue!40!white,
> % original example with color added %   16/other/red!40!white}
> %
> % following is for OP's needs:
>                    { 69/Big Company/green!80!black,
>                      29/Start Up/blue!40!white,
>                       2/Tiny Firms/yellow!30!white}
>    {
>      \setcounter{a}{\value{b}}
>      \addtocounter{b}{\p}
>      \slice{\thea/100*360}
>            {\theb/100*360}
>            {\p\%}{\t}{\c}
>    }
> \end{tikzpicture}
> 
>    From the TikZ document:  The color green!20!white means 20\%
>    green and 80\% white mixed together. Such color expression are
>    possible since TikZ uses Uwe Kern's xcolor package, see the
>    documentation of that package for details on color expressions.
> 
> \end{document}
> 
> 

Thanks Suresh, especially for your effort to customize your chart to my
question, 

your example worked fine, I did not have any trouble running it via
pdflatex.

Pascal






More information about the texhax mailing list