f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] :=
a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] +
Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Tooltip@Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1},
PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]
Manipulate[
Plot[Tooltip@Table[g[x, n], {n, i}] // Evaluate, {x, -1, 1},
PlotRange -> {-1, 1}, AspectRatio -> 1,
PlotLegends -> Automatic], {i, Range[5]}]