How to create a chart using c#
<p>I need to create a chart from data which I can acquire from 6 comboboxes that I have. </p>

<p>The data in the comboboxes are numbers. Once I select the desired numbers in comboboxes I then press a button which creates a chart based on these values.</p>

<p>My problem is that I can do it only once. Once I change values in comboboxes and click on the button again I receive an exception. </p>

<p>I understand that I need to create an instance of new chart everytime I press the button but I dont know how.</p>

<pre><code>private void button1_Click(object sender, EventArgs e)
{
    chart1.ChartAreas.Add("chart");
    chart1.ChartAreas["chart"].AxisX.Minimum = 0;
    chart1.ChartAreas["chart"].AxisX.Maximum = 20;
    chart1.ChartAreas["chart"].AxisX.Interval = 1;

    chart1.ChartAreas["chart"].AxisY.Minimum = 0;
    chart1.ChartAreas["chart"].AxisY.Maximum = 100;
    chart1.ChartAreas["chart"].AxisY.Interval = 5;

    chart1.Series.Add("xxx");
    chart1.Series.Add("yyy");

    chart1.Series["xxx"].Color = Color.Black;
    chart1.Series["yyy"].Color = Color.Red;

    chart1.Series["xxx"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
    chart1.Series["yyy"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

    chart1.Series["xxx"].Points.AddXY(comboBox1.Text, comboBox4.Text);
    chart1.Series["yyy"].Points.AddXY(comboBox1.Text, comboBox4.Text);

    chart1.Series["xxx"].Points.AddXY(comboBox2.Text, comboBox5.Text);
    chart1.Series["yyy"].Points.AddXY(comboBox1.Text, comboBox4.Text);

    chart1.Series["xxx"].Points.AddXY(comboBox3.Text, comboBox6.Text);
    chart1.Series["yyy"].Points.AddXY(comboBox1.Text, comboBox4.Text);
}
</code></pre>
