title: How to draw a graph in chart control with mouse
body: <p>My task is to draw a graph in chart control using mouse and retrieve the (X,Y) points from the Graph. </p>
  
  <p>I tried of drawing a graph with mouse.
  Here is the normal Graph looks like.<img src="https://i.stack.imgur.com/YN4t5.jpg" alt="enter image description here">
  After drawing with mouse, it looks like : <img src="https://i.stack.imgur.com/eIX3I.jpg" alt="enter image description here">
  The code which i used to draw graph is : </p>
  
  <pre><code>    private void Form1_Load(object sender, EventArgs e)
      {
      chart1.ChartAreas[0].AxisX.Minimum =0170101;
      chart1.ChartAreas[0].AxisX.Maximum =0175951;
      chart1.ChartAreas[0].AxisY.Minimum=0780101;
      chart1.ChartAreas[0].AxisY.Maximum=0785951;
      double range = chart1.ChartAreas[0].AxisX.Maximum - chart1.ChartAreas[0].AxisX.Minimum;
          chart1.ChartAreas[0].AxisX.Interval = range / 5;
  
          range = chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum;
          chart1.ChartAreas[0].AxisY.Interval = range / 5;
      }
      private void chart1_MouseMove(object sender, MouseEventArgs e)
      {
          if (!(FirstPoint == null))
          {
              Graphics g = chart1.CreateGraphics();
              Pen ErasePen = new Pen(Color.Transparent);
              g.DrawLine(ErasePen, FirstPoint, TempPoint);
              TempPoint = new Point(e.X, e.Y);
              this.Refresh();
          }
      }
      private void chart1_MouseDown_1(object sender, MouseEventArgs e)
      {
          FirstPoint = new Point(e.X, e.Y);
          TempPoint = new Point(e.X, e.Y);
      }
  
      private void chart1_MouseUp_1(object sender, MouseEventArgs e)
      {
          LineEndPoints Line = new LineEndPoints
          {
              StartPoint = FirstPoint,
              endPont = new Point(e.X, e.Y)
          };
          LinesList.Add(Line);
          // FirstPoint = null;
          this.Refresh();
      }
  
      private void chart1_Paint_1(object sender, PaintEventArgs e)
      {
          foreach (LineEndPoints line in LinesList)
          {
              e.Graphics.DrawLine(Pens.Green, line.StartPoint, line.endPont);
          }
          if (!(FirstPoint == null))
          {
              e.Graphics.DrawLine(Pens.Red, FirstPoint, TempPoint);
          }
      }
  </code></pre>
  
  <p>When I used to draw a graph it is moving away from the max and min values of the chart control.
  Now what I need to know is:
  1) My graph should not move away from the X and Y axis points of the chart control.
  2) I need to know the X,Y points of the graph which is drawn with respect to chart axis but not with form axis.</p>
  
  <p>I use C# VS 2010 Win-forms.</p>