# Making a stacked bar chart

I want to transform a set of barcharts (such as in the subset in the MWE below) to a stacked bar chart which is more legible, as in this example:

\documentclass{article}
\usepackage{tikz}

\begin{document}

Calendars and reminders\\
\begin{centering}
\begin{bchart}[max=70,scale=1,width=14cm,unit=\%]
\bcbar[text={Daily},color=cyan!20!green!40]{51}
\bcbar[text={Weekly},color=cyan!60!green!20]{24}
\bcbar[text={Less often}, color=cyan!10]{25}
\end{bchart}
\end{centering}

\begin{centering}
\begin{bchart}[max=70,scale=1,width=14cm,unit=\%]
\bcbar[text={Daily},color=cyan!20!green!40]{67}
\bcbar[text={Weekly},color=cyan!60!green!20]{23}
\bcbar[text={Less oft}, color=cyan!10]{7}
\end{bchart}
\end{centering}

\begin{centering}
\begin{bchart}[max=70,scale=1,width=14cm,unit=\%]
\bcbar[text={Daily},color=cyan!20!green!40]{46}
\bcbar[text={Weekly},color=cyan!60!green!20]{38}
\bcbar[text={Less often}, color=cyan!10]{16}
\end{bchart}
\end{centering}
\end{document}


I tried to use the solution to a previously asked question here (How to draw bar chart using tikz?) without success.

## Can you help? Thanks!

My first attempts (not a MWE, but for you to have an idea of what I'm doing wrong):

\begin{tikzpicture}

Label   Daily Weekly Less~often
Calendars~and~reminders      0.51      0.24      0.25
}\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=cyan!20!green!40] table [x=First, y expr=\coordindex] {\datatable};   % "First" column against the data index
\addplot [fill=cyan!60!green!20]table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=cyan!10] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}


Based on OP's MWE, this is an attempt to make it work, so that the OP can have a starting point. The main errors come from ~ (now replaced by \space) in Label column and the use of x=First, Second and Third (now they are changed to Daily, Weekly, and LessOften) on read-in.

Code

\documentclass[border=10pt]{standalone}%[a4paper]{article}

\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.8}
\begin{document}

Label                                Daily Weekly LessOften
Calendars\space And\space Reminders   0.51  0.24  0.25
Make/receive\space Phone\space Calls  0.46  0.38  0.16
}\testdata

\begin{tikzpicture}
\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={\testdata}{Label}  % Get the labels from the Label column of the \datatable
]
\addplot [fill=cyan!20!green!40] table [x=Daily, meta=Label,y expr=\coordindex] {\testdata};   % "First" column against the data index
\addplot [fill=cyan!60!green!20] table [x=Weekly, meta=Label,y expr=\coordindex] {\testdata};
\addplot [fill=cyan!10] table [x=LessOften, meta=Label,y expr=\coordindex] {\testdata};
\end{axis}
\end{tikzpicture}

\end{document}