title: C# Datatable data to chart
body: <p>Language: C#</p>
  
  <p>Hi all,</p>
  
  <p>Im a bit stuck here and was hoping someone could point me in the right direction.</p>
  
  <p>I have a text file as a data source and made  a datatable with all the data in it. Now i need to get data out of it create a chart.</p>
  
  <p>full datatable looks like this</p>
  
  <pre><code>datestamp   |    name_X_1      |    name_X_2      |    name_Y_1      |    name_Y_2
  -----------------------------------------------------------------------------------
  1/1/199     |    somevalue     |    somevalue     |    somevalue     |    somevalue
  1/2/199     |    somevalue     |    somevalue     |    somevalue     |    somevalue
  </code></pre>
  
  <p>Now i need to have all name_X_* values from the name_x_* columns from a certain time (wich will be a varible from a calander control). </p>
  
  <p>This is how i need the data to be for the chart</p>
  
  <pre><code>datastamp   |    name_x_data        |    name_y_data
  -------------------------------------------------------
  1/1/199     |    name_X_1_value     |    name_y_1_value  
  1/1/199     |    name_X_2_value     |    name_y_2_value  
  </code></pre>
  
  <p>To make a bit more difficult, the name_X_* and name_y_* columns can vary (X and Y are the x and y axis values from a massurement and are always the same amount of columns). In one text file it's 10 columns and a other text file it could be 20. So i can't hardcode the column names. I need to filter them on name_X_ and name_Y_ and search on a specific date.</p>
  
  <p>I could also store the number of columns. So if we could select on column number 2 till 10 for X and 10 till 20 for Y it would be awesome to. Its ok to have a administration on the text file in the database here i enter the amount of colums the text file has. So if someone has a option to use count it would work for me too.</p>
  
  <p>If anyone could point me in the right direction i would really appreciateit. Im stuck haha</p>
  
  <p>thanks allot!</p>
  
  <p>ps; Im willing to pay for a good solution :)</p>
  
  <p>This is the code i made so far:</p>
  
  <pre><code> DataTable dt = new DataTable();
          string[] columns = null;
  
          string FileName = "C:\\datapath\\data.dat";
          var lines = File.ReadAllLines(FileName);
  
          // create columns from text file and skip first few rows
          if (lines.Count() &gt; 2)
              {
  
                  columns = lines[1].Split(new char[] { ',' }).Select(x =&gt; x.Replace("\"", "")).ToArray();
  
                  foreach (var column in columns)
                      dt.Columns.Add(column);
              }
  
          // add data to rows
          for (int i = 2; i &lt; lines.Count(); i++)
              {
                  DataRow dr = dt.NewRow();
                  string[] values = lines[i].Split(new char[] { ',' }).Select(x =&gt; x.Replace("\"", "")).ToArray();
  
                  for (int j = 0; j &lt; values.Count() &amp;&amp; j &lt; columns.Count(); j++)
                      dr[j] = values[j];
  
                  dt.Rows.Add(dr);
              }
  
          // Columns filter (under construction) (this is the part i need to be not hard coded)
  
          string[] selectedColumns = new[] { "TIMESTAMP", "sensor_X_001", "sensor_X_002" };
  
          DataTable dt2 = new DataView(dt).ToTable(false, selectedColumns);
  
          // Date filter (under construction)
          // string s = "2014-05-21 13:05:00";
          // DataRow foundRow = dt2.Tables["TIMESTAMP"].Rows.Find(s);
  
          // data to grid 
          this.GridView1.DataSource = dt2;
          this.GridView1.DataBind();
  </code></pre>