# How to connect the lines in the simplest way?

How do I connect the lines of the simplest form in the following code. Perhaps with chain or other option, so that the code is short.

\usetikzlibrary{chains,calc}
\newcommand{\xx}{10}
\newcommand{\yy}{9}
\begin{tikzpicture}[>=latex,start chain=dot placed {at=(\tikzchaincount*30:1.5)}]
\draw[very thin,color=lightgray,dashed] (0,0) grid (\xx+1,\yy+1);
%eixos
\draw[->] (-1,0) -- (\xx+1,0) node[below] {$n^\circ$};
\draw[->] (0,-1) -- (0,\yy+1) node[right] {altura $(m)$};
%cotas
\foreach \x in {1,...,\xx}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt)
node[below]     {$\x$};
\foreach \y in {1,...,\yy}
\draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt)
node[left] {$\y 0$};
\node[below left] at (0,0) {$0$};
%grafico
\foreach \y in {1,3,2,4,5,1,3,6,8,9}{
\fill[blue] (\thex,\y) circle (2pt);
\coordinate (p\thex) at (\thex,\y);
\draw (p\thex) -- (p\thex); %CONECT LINES HERE
}
\end{tikzpicture}

I need this.

I solve with

\usetikzlibrary{calc}
\newcommand{\xx}{10}
\newcommand{\yy}{9}
\begin{tikzpicture}[>=latex]
\draw[very thin,color=lightgray,dashed] (0,0) grid (\xx+1,\yy+1);
%eixos
\draw[->] (-1,0) -- (\xx+1,0) node[below] {$n^\circ$};
\draw[->] (0,-1) -- (0,\yy+1) node[right] {altura $(m)$};
%cotas
\foreach \x in {1,...,\xx}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt)
node[below]     {$\x$};
\foreach \y in {1,...,\yy}
\draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt)
node[left] {$\y 0$};
\node[below left] at (0,0) {$0$};
%grafico
\coordinate (p1) at (1,1);
\coordinate (p2) at (2,3);
\coordinate (p3) at (3,2);
\coordinate (p4) at (4,4);
\coordinate (p5) at (5,5);
\coordinate (p6) at (6,1);
\coordinate (p7) at (7,3);
\coordinate (p8) at (8,6);
\coordinate (p9) at (9,8);
\coordinate (p10) at (10,9);

\draw plot[mark=*,mark options={blue}] coordinates{
(p1)(p2)(p3)
(p4)(p5)(p6)
(p7)(p8)(p9)
(p10)
};
\end{tikzpicture}
-
Why do you want to plot your data this way? It would be a lot easier to just use pgfplots, or at least the plot functionality that comes with TikZ. I believe you might get better answers if you explained the motivation behind your approach. – Jake Oct 27 '11 at 2:17

Here's a pgfplots solution.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel=$n^{\circ}$, ylabel=Altura,
grid=major, axis lines = left,
xmin = 0, ymin= 0, xmax=11,ymax=100,
major grid style={dashed},
xtick={0,1,...,10},ytick={0,10,...,90}]
coordinates {
(1,10)
(2,30)
(3,20)
(4,40)
(5,50)
(6,10)
(7,30)
(8,60)
(9,80)
(10,90)
};
\end{axis} \end{tikzpicture}
\end{document}

-
I try new command. See, but no sucessful. – Regis da Silva Oct 27 '11 at 2:14
Resolved. Thanks. – Regis da Silva Oct 27 '11 at 3:37