Most of us create charts that have to be repeated
a number of times with only the data varying. Applying DRY (do not repeat yourself) programming principles to such problems is not an easy task.
To achieve this, one has to separate the data from the presentation. This has the added advantages of providing better semantics for authors and can hide the verbosity of the pgf and friends libraries. It also makes progressive editing of the looks of the charts easier.
For example consider the charts shown below, the data part consists of the title, the month label and two data series:

These are produced using an environment as follows:
\begin{monthlyChart}
\addTitle{AHU (October)}
\addMonth{Oct-11}
\addPlanned{10}{20}{30}{40}
\addActual {9}{18}{31}{39}
\end{monthlyChart}
Question
How can I abstract the creation of the environment, i.e., to consider the original bar chart as a master template from which other variations can be defined -- rather than repeating the process. For example, to create a slightly different chart, I have used the same environment as follows:
\begin{monthlyChart}
\addTitle{Turnover $\times 10^3$}
\addMonth{Jan-11}
\addPlanned{300}{400}{500}{600}
\addActual {300}{400}{500}{600}
\end{monthlyChart}
giving a chart that can now be used for a different purpose, resulting in:
I am looking for a way to define a createNewChartType sort of command, which will use a predefined template and adjust a few parameters, more like a relationship between a template and a theme as used in web development. Lengthy and verbose
minimal follows:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{pgfplots}
\makeatletter
\newcommand\progressChart[8]{
\def\week##1##2{
\footnotesize
\begin{tabular}{c}##1\\
##2\\\end{tabular}
}
\begin{tikzpicture}
\begin{axis}[
width=6.9cm,height=5cm,
bar width=0.3cm,
title={\ctitle},
ymin=0,
% ytick={0,25,50,100,125},
ylabel=Total,
ybar=0,symbolic x coords={A, B, C, D},
xtick=data,
xticklabels={
\week{\Month}{week-1},
\week{\Month}{week-2},
\week{\Month}{week-3},
\week{\Month}{week-4}
},enlarge x limits=true,
legend style={
at={(.43,.98)}, font=\footnotesize }],
\addplot[draw=none, fill=gray] coordinates {
(A,#1)
(B,#2)
(C,#3)
(D,#4)
};
\addplot[draw=none,fill=orange!90] coordinates {
(A,#5)
(B,#6)
(C,#7)
(D,#8)
};
\legend{Planned, Actual}
\end{axis}
\end{tikzpicture}}
\newenvironment{monthlyChart}{%
\def\addMonth##1{\def\Month{##1}}
\def\addTitle##1{\def\ctitle{\small\textbf{##1}}}
\def\addPlanned##1##2##3##4{%
\def\one{##1}\def\two{##2}\def\three{##3}\def\four{##4}}
\def\addActual##1##2##3##4{%
\progressChart{\one}{\two}{\three}{\four}{##1}{##2}{##3}{##4}
}%
\parindent0pt}{}
\makeatother
\begin{document}
\begin{monthlyChart}
\addTitle{AHU (October)}
\addMonth{Oct-11}
\addPlanned{10}{20}{30}{40}
\addActual {9}{18}{31}{39}
\end{monthlyChart}
\begin{monthlyChart}
\addTitle{AHU (November)}
\addMonth{Nov-11}
\addPlanned{30}{40}{50}{60}
\addActual {30}{40}{60}{60}
\end{monthlyChart}
\begin{monthlyChart}
\addTitle{AHU (December)}
\addMonth{Dec-11}
\addPlanned{30}{40}{50}{60}
\addActual {30}{50}{58}{70}
\end{monthlyChart}
\begin{monthlyChart}
\addTitle{AHU (January)}
\addMonth{Jan-11}
\addPlanned{30}{40}{50}{60}
\addActual {30}{40}{50}{113}
\end{monthlyChart}
\begin{monthlyChart}
\addTitle{Turnover $\times 10^3$}
\addMonth{Jan-11}
\addPlanned{300}{400}{500}{600}
\addActual {300}{400}{500}{600}
\end{monthlyChart}
\end{document}

.texfile, or are all of the sources meant to be in one place? This makes a difference to the best approach. (For example, as I have to have 'stand alone' versions of each plot, I create them as separate.texfiles.) – Joseph Wright Oct 14 '11 at 19:44pgfkeysto define a couple of keys - one for each of your parameters. Defining your parameters by means of a key-value approach will probably simplify the usage while it does not complicate the implementation. This would also allow you to write\XXXset{month=<common month>}in front of a couple of diagrams to set the shared parameters only once. An introduction topgfkeyscan be found in http://www.tug.org/TUGboat/tb30-1/tb94wright-keyval.pdf – Christian Feuersänger Oct 15 '11 at 20:11