TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm want to include two graphs mentioned below in a document.

Bar Chart Pie Chart

I'm able to draw pie charts using pgf-pie. Is there any package which is capable of generating BAR & PIE Chart both? [Also which is included in default LATEX installation] ?

share|improve this question
Perhaps you want to try the relevant packages from the »datatool« bundle. – Thorsten Donig Sep 27 '13 at 16:33
Bar charts can be done with pgfplots (take a look at pgfplots). Pie charts are best not done. – Qrrbrbirlbel Sep 27 '13 at 16:33
up vote 15 down vote accepted

For bar charts you can use pgfplots With TikZ you can setup some macros so that you can write pie charts like this:

    pie chart,
    slice type={comet}{blu},
    slice type={legno}{rosso},
    slice type={coltello}{giallo},
    slice type={sedia}{viola},
    slice type={caffe}{verde},
    pie values/.style={font={\small}},

    \pie[xshift=2.2cm,values of coltello/.style={pos=1.1}]%
    \pie[xshift=4.4cm,values of caffe/.style={pos=1.1}]%

    \legend[shift={(0cm,-1cm)}]{{Comet (Pordenone)}/comet, {Wood and furniture (Livenza)}/legno, {Knife (Maniago)}/coltello}
    \legend[shift={(3cm,-1cm)}]{{Chair (Manzano)}/sedia, {Coffee (Trieste)}/caffe}



Pie chart example

The macros \pie and \legend and all the keys needed can be defined as follows:



    legend label/.style={font={\scriptsize},anchor=west,align=left},
    legend box/.style={rectangle, draw, minimum size=5pt},
    axis label/.style={anchor=east,font={\tiny}},

\tikzstyle{bar chart}=[
    bar width/.code={
    bar/.style={very thick, draw=white},
    bar label/.style={font={\bf\small},anchor=north},
    bar value/.style={font={\footnotesize}},
    bar width=.75,

\tikzstyle{pie chart}=[
    slice/.style={line cap=round, line join=round, very thick,draw=white},
    pie title/.style={font={\bf}},
    slice type/.style 2 args={
        values of ##1/.style={}


    \node[pie title] at (90:1.3) {#2};
    \foreach \v/\s in{#3}{
        \pgfmathsetmacro{\nextA}{\curA + \deltaA}

        \path[slice,\s] \c
            -- +(\curA:\r)
            arc (\curA:\nextA:\r)
            -- cycle;
        \pgfmathsetmacro{\d}{max((\deltaA * -(.5/50) + 1) , .5)}

        \path \c -- node[pos=\d,pie values,values of \s]{$\v\%$} +(\midA:\r);


        \foreach \n/\s in {#2}
                  ++(0,-10pt) node[\s,legend box] {} +(5pt,0) node[legend label] {\n}

This code needs polishing and is not very general but I am sharing it as I wrote it for a document I helped typeset. If you like it we can work out a better version.

share|improve this answer
Thanks for detail reply. Can you please suggest how to add legend in bar chart mentioned below: \begin{tikzpicture} \begin{axis}[ title=Title, xbar, xmajorgrids = true, bar width=6mm, width=12cm, height=5.5cm, enlarge y limits=0.2, xlabel={\#number}, symbolic y coords={A,B,C,D}, ytick=data, nodes near coords, nodes near coords align={horizontal}, ] \addplot coordinates {(1,A) (7,B) (5,C)(2,D)}; \end{axis} \end{tikzpicture} – Pawan Mude Sep 27 '13 at 19:22
well, you could use my \legend macro and put it right before the \end{tikzpicture}. – Bordaigorl Sep 27 '13 at 21:40
By the way this was quick and dirty code I put together some time ago, if anybody has suggestions on how to make it better, I'd be interested to hear them! – Bordaigorl Sep 27 '13 at 21:42
Thank You for your comments. – Pawan Mude Sep 28 '13 at 18:41
follow up question: tex.stackexchange.com/questions/157309/… – endo.anaconda Feb 3 '14 at 11:49

With PSTricks

    \pswedge[fillstyle=solid,fillcolor=#1,opacity=.5](0,0){4}{!\thecounter}{!\thecounter\space #2 add}%
    \uput{2}[!#2 2 div \thecounter\space add](0,0){#2\%}%


enter image description here

share|improve this answer
To offset the angle, invoke \setcounter{counter}=<offset> before calling the first \data. – kiss my armpit Sep 27 '13 at 17:54
I meant \setcounter{counter}{<offset>}. – kiss my armpit Sep 28 '13 at 10:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.