title: How To Search For a DataPoint on the X-Axis, and then be able to change the Y Value?
body: <p>I am creating a chart that currently generates different data points by adding to x-axis values in a loop in one series.</p>
  
  <p>In another series I want to be able to:</p>
  
  <ul>
  <li>Search to see if the series "Total Cost" has a data point at the same point as a string "starttime"</li>
  <li>if the chart has no values at all, addXY of that point to the series</li>
  <li>if the chart has a value at "starttime", add a value to the current Y value</li>
  <li>if the chart has no value at "starttime", addXY point to the series</li>
  </ul>
  
  <p>Here is the code I have been trying to use so far:</p>
  
  <pre><code>using System.Windows.Forms.DataVisualization.Charting;
  
  // ...
  
  public DateTime starttime;
  public DateTime endtime;
  public DateTime totaltime;
  
  private void comboBoxStart_SelectedIndexChanged(object sender, EventArgs e)
      {
          string format = "HH:mm";
          starttime = DateTime.ParseExact(comboBoxStart.Text, format, System.Globalization.CultureInfo.InvariantCulture);
      }
  
  private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  {
      if (textBoxTotalTime.Text != "")
      {
          string format = "HH:mm";
          totaltime = DateTime.ParseExact(
              comboBoxFinish.Text, format, 
              System.Globalization.CultureInfo.InvariantCulture);
          chartTimespan.Series.Add(textBoxName.Text);             
  
          while(starttime &lt;= endtime)
          {                
              chartTimespan.Series[textBoxName.Text].Points.AddXY(starttime, 6);
              starttime = starttime.AddMinutes(15);
  
              DataPoint DataPointX = chartTimespan.Series[textBoxName.Text].Points
                  .FindByValue((starttime).ToOADate(), "X");
  
              if(chartTimespan.Series["Total Cost"].Points.Contains(null))
              {
                  chartTimespan.Series["Total Cost"].Points.AddXY(starttime, 6);
              }
              else if (!(chartTimespan.Series["Total Cost"].Points.FindByValue((starttime).ToOADate(), "X") == null))
              {
                  chartTimespan.Series["Total Cost"].Points.;
              }
              else
              {
                  chartTimespan.Series["Total Cost"].Points.AddXY(starttime, 6);
              }    
          }
  
          chartTimespan.Legends.Add(textBoxName.Text);
          chartTimespan.Series[textBoxName.Text].ChartType = SeriesChartType.Line;
      }
      textBoxName.Text = "";
      comboBoxStart.Text = "";
      comboBoxFinish.Text="";
      textBoxTotalTime.Text = "";
  }
  </code></pre>
  
  <p>Cheers for any help, or if you think I should be using a different approach!</p>