The basicity of a compound is typically not directly proportional to the electronegativity of its substituents but indirectly proportional. That is, the more electronegative a substituent is, the less basic the entire compound is.
First let’s take a look at basicity and what factors into it. For a molecule or group to be basic, the following reaction (1) needs to occur adequately favourably:
$$\ce{B + H+ <=> BH+}\tag{1}$$
What is happening in this reaction is that we are giving the molecule $\ce{B}$ a positive charge. Positive charges are more stabilised if they are ‘balanced’ by negative charges — i.e. if the molecule $\ce{B}$ was already partially negatively charged before the proton came in.
Remember that electronegativity is the ability of an atom to draw bonding electrons towards it. That is exactly what you want to create a partial negative charge, so if the basic group of a molecule is more electronegative than its surroundings that is what you want. In the context of aromatic compounds, electronegativity is usually described as a $-I$ (negative inductive) or $+I$ positive inductive effect; the former being exercised by electronegative groups and reducing the electron density in an aromatic ring and the latter due to electropositive groups and increasing it.
If we want to create a pyridine that is as basic as possible, we want $+I$ effects, i.e. electron donating groups. If we rank the groups by their ability to donate electrons from $+I$ to $-I$, we get:
- $\ce{CH3}$ — due to the electropositive hydrogens
- $\ce{H}$ — defined as the standard ($0$)
- $\ce{Cl}$ — mediumly deactivating
- $\ce{Me2N}$ — strongly deactivating inductively.
However, inductive effects are not the only ones that can modify an aromatic system: mesomeric effects ($+M$ or $-M$) can do so, too. Mesomeric effects are exercised by groups that can either mesomericly donate electrons into the aromatic ring, increasing the electron density; or by those that can pull electrons out of the aromatic ring reducing its density. Mesomeric effects usually but not always outrank inductive effects, and they can have an effect across longer distances. Ranked by mesomeric effects from $+M$ to $-M$, the groups are:
- $\ce{Me2N}$
- $\ce{Cl}$
- $\ce{CH3}$ — only very weakly; technically, this group can be explained almost solely by its $+I$ effect
- $\ce{H}$
The dimethylamino group is a much better mesomeric electron donator than chlorine because nitrogen’s p-orbital is much more similar to carbon’s allowing for a stronger participation in the π system and because of nitrogen’s generally larger basicity than chlorine’s. If you want, you can visualise the $+M$ effect with the resonance structures Ringo’s answer shows.
Taking this all into account, we get the following final rating from more basic to less basic — and note that this corresponds nicely with the respective rates of electrophilic aromatic substitution:
$$\begin{array}{cccl}\hline
\text{Rank} & \text{Compound} & \mathrm{p}K_\mathrm{a} & \text{Source} \\\hline
1 & \ce{4{-}Cl-C5H4N} & 3.83 & \text{Nguyen}\\
2 & \ce{C5H5N} & 5.2 & \text{Bordwell}\\
3 & \ce{4{-}Me-C5H4N} & 6.03 & \text{Nguyen}\\
4 & \ce{4{-}Me2N-C5H4N} & 9.2 & \text{Evans}\\
\hline\end{array}$$
Compared to the ‘standard’ — pyridine — 4-chloropyridine is deactivated (strong $-I$) while 4-methylpyridine is mildly activated ($+I$ effect). 4-dimethylaminopyridine is, of course, strongly activated: the $+M$ effect strongly outweighs the $-I$ effect.
References:
Evans: the Evans $\mathrm{p}K_\mathrm{a}$ table
Bordwell: the Bordwell $\mathrm{p}K_\mathrm{a}$ data
Nguyen: N.-N. Pham-Tran, G. Bouchoux, D. Delaere, M. T. Nguyen, J. Phys. Chem. A 2005, 109, 2957. DOI: 10.1021/jp045339c.