maryam mohammadi

maryam mohammadi

  • NA
  • 26
  • 4.2k

chart+object reference not set...error

Aug 26 2014 3:38 PM
Hello

I want to make a chart with following code
but I get error for specified line!
please help! :(

private void button3_Click(object sender, EventArgs e)
        {
            chart1 = new Chart();
            ChartArea chartArea1 = new ChartArea();
            chart1.ChartAreas.Add(chartArea1);
            Series series1 = new Series();
            chart1.Series.Add(series1);


            for (int i = 0; i < prediction_year; i++)
            {
                series1.Points.Add(Concentration[i]).AxisLabel = Convert.ToString(1393 + i);
            }
            chart1.Series[0].ChartType = SeriesChartType.Line;
            chart1.Location = new System.Drawing.Point(30, 40);
            chart1.Size = new System.Drawing.Size(500, 300);
            chart1.Legends.Add("hi");
            chart1.Series[0].LegendText = "concentration";
            chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
            this.Controls["gbxChart"].Controls.Clear();
            this.Controls["gbxChart"].Controls.Add(chart1);
           
        }

Answers (5)