# Using variables to draw a tikz diagram

I am defind my own command to plat a diagram with tikz.

Instead of constant values I rather want to pass numbers to my command which determine the height of the bars in my diagram.

Problem: I am using a wrong syntax, so Tex cannot parse my arguments to set the bar height. I tried a, #a, {#a} and #{a} but nothing workd so far.

Question: What is my mistake and how can I solve it?

\newcommand{\clocksTen}[a][b][c][d]{
\begin{tikzpicture}
%  \centering
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
%width=0.4\textwidth,
ylabel={CPU clocks},
symbolic x coords={one, two, three, four},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
(one, a) %doesnt work
};
(two, #a) %doesnt work
};
(three, {#a}) %doesnt work
};
(four, #{a}) %doesnt work
};
\legend{one, two, three, four}
\end{axis}
\end{tikzpicture}
}

-

LaTeX arguments are always numeric, preceded by a hash sign, e.g. #1. You provide the number of required parameters (later entered inside curly braces) to \newcommand in square brackets. The default value for a single optional parameter (always #1) may follow in another pair of square brackets and is put inside square brackets when used, too.

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}

\newcommand{\clocksTen}[4]{
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={CPU clocks},
symbolic x coords={one, two, three, four},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
\legend{one, two, three, four}
\end{axis}
\end{tikzpicture}
}
\begin{document}

\clocksTen{2}{4}{8}{16}

\end{document}