I found the answer myself .I changed the line:
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.chart1 });
to the line:
this.Controls.AddRange(new System.Windows.Forms.Control[] { chart1});
and the line
this.chart1.Legends.Add(Legend1);
to the line
chart1.Legends.Add(Legend1);