\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\makeatletter
% argument #1: any options
\newenvironment{customlegend}[1][]{%
    \begingroup
	\pgfutil@IfUndefined{label}{\relax}{%
		\let\pgfplots@original@LaTeX@label=\label
		\let\label=\pgfplots@plot@label
	}%
	%
	\global\pgfplots@has@label@informationfalse
	%
    % inits/clears the lists (which might be populated from previous
    % axes):
    \csname pgfplots@init@cleared@structures\endcsname
    \pgfplotsset{#1}%
}{%
    % draws the legend:
    \csname pgfplots@createlegend\endcsname
    \endgroup
}%

% makes \addlegendimage available (typically only available within an
% axis environment):
\def\addlegendimage{\csname pgfplots@addlegendimage\endcsname}
\makeatother

\begin{document}

\thispagestyle{empty}

\begin{tikzpicture}
    \begin{customlegend}[legend entries={$a$,$e^x$,C,$d$}]
    \addlegendimage{red,fill=black!50!red,area legend}
    \addlegendimage{red,fill=black!50!red,sharp plot}
    \addlegendimage{red,fill=black!50!red,mark=*,sharp plot}
	\label{xy}
    \addlegendimage{red,fill=black!50!red,ybar,ybar legend}
    \end{customlegend}
\end{tikzpicture}

Image: \ref{xy}.

\end{document}
