I would like to create some bar charts using pgfplots. Each chart will have a similar format, but with some different labels and values. I am trying to make a command that will generate my chart from this input data. For example, I would like to be able to type \drawchart{Foo/10, Bar/20} and have this produce an appropriate bar chart. I'm having trouble taking this input "Foo/10, Bar/20" and converting it into a list "Foo,Bar" that symbolic coords can use. Here is a MWE, that doesn't work:
\documentclass{article}
\usepackage{tikz, pgfplots}
\pgfplotsset{compat=1.9}
\def\lab{Foo,Bar}
\let\labb\lab
\def\ylabelscmd{\foreach \label/\val in {Foo/1,Bar/2} {{\label},}}
\global\let\ylabels\ylabelscmd
\begin{document}
\ylabelscmd --- \ylabels
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\begin{axis}[
xbar,
%symbolic y coords/.expand once = {\lab}, % works
%symbolic y coords/.expand once = {\labb}, % works
%symbolic y coords/.expand once = {\ylabelscmd}, % error: ! Missing \endcsname inserted.
symbolic y coords/.expand once = {\ylabels}, % error: ! Missing \endcsname inserted.
ytick = data,
]
\addplot+ coordinates { (1,Foo) (2,Bar) };
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
For some reason, it works if the command in the symbolic coords is a hard-coded list, but if I generate it using \foreach it complains. As you can see in the code, I've tried to evaluate the command using \let and using that, but it seems to make no difference (at least with the expand once option).
Any ideas?

! Package pgfplots Error: Sorry, the input coordinate 'Foo' has not been defined with 'symbolic y coords={\foreach \label /\val in {Foo/1,Bar/2} {{\label },}} ... Maybe it has been misspelled? Or did you mean something like [normalized]Fo o?.– Hoang-Ngan Nguyen Jul 04 '16 at 18:34