# Missing mark at legend for tikz bar chart

I have the following code:

\begin{tikzpicture}
Label   First   Second  Third
test      30     30     40
}\datatable

\begin{axis}[
xbar stacked,   % Stacked horizontal bars
xmin=0,         % Start x axis at 0
xmax = 100.01,
xticklabels={0, 0\%, 20\%,40\%,60\%,80\%,100\%},%
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};
\legend{test1, test2, test3}
\end{axis}
\end{tikzpicture}


Can someone please explain why the "colour-boxes" do not show for each legend, and help me add them?

It seems to be working if I make the bar chart vertical, but I would like to keep it horizontal.

Thank you very much for any help!

-

This looks like a bug in PGFPlots: The legend image code for the xbar stacked plot type is defined incorrectly. If you put the following code snippet in your preamble, the legend is displayed correctly:

\pgfplotsset{
single xbar legend/.style={
legend image code/.code={\draw[##1,/tikz/.cd,bar width=6pt,bar shift=0pt,xbar] plot coordinates {(0.8em,0pt)};},
}
}


-
Wow! Thank you so much for the answer. It works:-) –  Martha Marie Jun 6 '13 at 22:56
whoops, while reading this answer I accidentally clicked on the downvote button and didn't notice it until now... I'm very sorry, to compensate I upvoted another random answer of yours. –  dcmst Jul 26 '13 at 16:38
@dcmst: Haha, no problem! For the future: You can undo a downvote by clicking the downvote button again, but that only works for a short time (5 minutes, I think?) –  Jake Jul 26 '13 at 16:57
yes, unfortunately I noticed only 44 minutes later... –  dcmst Jul 26 '13 at 16:58