# Waterfall graph in Tikz?

I would like to create a waterfall graph like this one. My apologies I don't have a MWE at this point despite two days of futile coding.

• Welcome to TeX.SX! If you have invested two days in your code it would be a great starter to post it as MWE here (it helps us and therefore also you). – TeXnician May 20 '17 at 9:49
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. If you don't know what is a minimal working example (MWE), see here: tex.meta.stackexchange.com/q/228. – CarLaTeX May 20 '17 at 9:51
• Out of curiosity: what are imports doing in a GDP graph? Are these imports related industries? – JPi May 20 '17 at 14:37
• Good point about the imports but I think it is just a pedagogical tool to show how eventually you get to a positive GDP figure after netting out imports and the like. – P.Asea May 21 '17 at 2:17

If you just wish to replicate the graph with no functionality, you can build it easily with relative coordinates, i.e ++(coordinate). Something along the lines of

\begin{tikzpicture}[xscale=3]
\draw[thin,gray] (-3,0) node[above] {-3 pct pts} -- (-3,-10) node[below] {-3} (-2,0) node[above] {-2} -- (-2,-10) node[below] {-2} (-1,0) node[above] {-1} -- (-1,-10) node[below] {-1};
\draw[red, line width=1cm] (0,-1) -- (-1.85,-1) node[left] {-1.85}
++(0,-1) --++ (-.41,0) node[left] {-0.41}
++ (0,-1) --++(-0.09,0) node[left] {-0.09}
++ (0,-1) --++(-0.08,0) node[left]{-0.08}
++ (0,-1) --++(-0.05,0) node[left] {-0.05};
\draw[blue,line width=1cm]
(-2.48,-6) node[left] {0.08} --++(0.08,0)
++ (0,-1) node[left] {0.14}  --++(0.14,0)
++ (0,-1) node[left] {0.17} --++(0.17,0)
++ (0,-1) node[left] {0.23} --++ (0.23,0)
++ (0,-1) node[left] {0.35} --++ (0.35,0); %%and so on, you can place the labels at the proper coordinates
\end{tikzpicture}


I am unaware of a functionality that covers your kind of graph within the \datavisualization framework. You will have to go to a hand-drawn kind of solution or modify your data accordingly, i.e. (in \datavisualization)

data{
element, percentage
0,0
0,-1.85
1,-1.85
1,(-1.85-0.41)}


I hope that helps on your quest to making such beautiful graphs.

Borrowing a bit from Huang_d's answer, here is a version that uses a couple of loops and if statements to automate things.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[xscale=3]
\pgfmathsetmacro\Yscale{0.5}

% draw grid lines and labels
\foreach \x in {-3,...,2}
\draw [thin,gray] (\x,0)
\ifnum \x < 1 % only add top labels for negative numbers
node[above] (t\x) {$\x$}
\fi
-- (\x,-8) node[below] {$\x$};

% fill white on top, and draw zero line thicker
\fill [white] (0,0) rectangle (2.2,-7.5);
\draw [thick] (0,0) -- (0,-8);

% append pct. pts to -3
\node [gray,right,inner sep=0,anchor=base west] at (t-3.base east) {pct. pts};

% initialize \totalx
\pgfmathsetmacro\totalx{0}

% main loop
\foreach [
count=\y,
evaluate=\x as \xint using int(floor(\x))]
\x/\txt in {
-1.85/abc,
-0.41/abc,
-0.09/abc,
-0.08/abc,
-0.05/abc,
0.08/abc,
0.14/abc,
0.17/abc,
0.3/abc,
0.6/abc,
1/abcd,
0.4/abcd,
0.4/abcd,
0.3/abcd,
0.6/% note no text here
}
{
\ifnum \xint <0 % for negative numbers, draw red bars
\draw [line width=\Yscale cm,red!75!blue] (\totalx,-\y*\Yscale) -- ++(\x,0) node[left] (num\y) {$\x$};
\else % for positive numbers, draw blue bars, and node at start instead of end
\draw [line width=\Yscale cm,blue!75!red] (\totalx,-\y*\Yscale) node[left] (num\y) {$\x$} -- ++(\x,0);
\fi

% update \totalx
\pgfmathsetmacro{\temp}{\totalx+\x}
\global\let\totalx=\temp

% place text node
\node [right] at ({max(0,\totalx)},-\y*\Yscale) {\txt};
}

% final label, which has a custom placement
\node [left,anchor=base east] at (num\y.base west) {abcde};

\end{tikzpicture}

\end{document}