# How to draw bar chart using tikz?

I have drawn the above figure using powerpoint, how can I plot something similar using tikz?

I want the 3 different sections in every bar which should ve 3 different colors

I am using the code from 1st answer but all my bars are overlapping why?

    \documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\begin{tikzpicture}
Label   First   Second  Third
10      0.1     0.3     0.3
20      0.2     0.3     0.3
30      0.3     0.4     0.5
40      0.3     0.5     0.8
160     0.5     0.9     1.5
}\datatable

\begin{axis}[
xbar stacked,   % Stacked horizontal bars
xmin=0,         % Start x axis at 0
ytick=data,     % Use as many tick labels as y coordinates
yticklabels from table={\datatable}{Label}  % Get the labels from the Label column of the \datatable
]
\addplot [fill=yellow] table [x=First, y expr=\coordindex] {\datatable};    % Plot the "First" column against the data index
\addplot [fill=green!70!blue]table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=red!80!yellow] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}

\end{document}


-------edit------

I updated my pgfplots package and now everything is working as expected!

You can use PGFPlots for this. It has an xbar stacked style that uses stacked horizontal bars. Here's an example based on your image:

\documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\begin{tikzpicture}
Label   First   Second  Third
10      0.1     0.3     0.3
20      0.2     0.3     0.3
30      0.3     0.4     0.5
40      0.3     0.5     0.8
160     0.5     0.9     1.5
}\datatable

\begin{axis}[
xbar stacked,   % Stacked horizontal bars
xmin=0,         % Start x axis at 0
ytick=data,     % Use as many tick labels as y coordinates
yticklabels from table={\datatable}{Label}  % Get the labels from the Label column of the \datatable
]
\addplot [fill=yellow] table [x=First, y expr=\coordindex] {\datatable};    % Plot the "First" column against the data index
\addplot [fill=green!70!blue]table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=red!80!yellow] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}

\end{document}

• why are all bars overlapping when I use the same code? – zcqwevb Feb 25 '13 at 11:29
• Are you using exactly the same code? Then they shouldn't be overlapping. Are you sure that you have the y expr=\coordindex keys in your code? – Jake Feb 25 '13 at 11:46
• yes...i ve just changed the value inside the table...but nothing else – zcqwevb Feb 25 '13 at 11:47
• @user494461: Please edit your question to include the complete code (including the changed values) – Jake Feb 25 '13 at 11:48
• i have edited my orignal question – zcqwevb Feb 25 '13 at 11:52