title: Drawing a chart from a datatable
body: <p>I am trying to draw a graph with multiple series on it. the data for it comes from a database through a <code>DataAdapter</code> into a <code>DataTable</code>, like this;</p>
  
  <pre><code>public DataTable deaths_per_reason_per_year(string farmerid)
   {
       dt = new DataTable();
       try
       {
           conn.Open();  // (select formatted to fit SO lines)
           SqlCommand cmd = new SqlCommand("SELECT DATEPART(yyyy, DeathDate) AS 'Year',   
                Reason,   
                COUNT(DeathID) AS 'Number of Deaths' FROM [Farmstat_V1.0].[dbo].[Death] 
                WHERE FarmerID = '" + farmerid + "' 
                GROUP BY  Reason, YEAR(DeathDate);", conn);
           SqlDataReader reader = cmd.ExecuteReader();
           dt.Load(reader);
       }
       catch (Exception)
       {
           throw;
       }
       finally
       {
           conn.Close();
       }
       return dt;
   }
  </code></pre>
  
  <p>This gives me the following output;</p>
  
  <p><a href="https://i.stack.imgur.com/CoRt4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CoRt4.png" alt="DataTable with the sql output"></a></p>
  
  <p>When I try to assign the DataTable to my chart on the form, with this;</p>
  
  <pre><code>StatsDataAccess sda = new StatsDataAccess();
  
  chart1.DataSource = sda.deaths_per_reason_per_year(FarmerID);
  chart1.Series["Series1"].XValueMember = "Year";
  chart1.Series["Series1"].YValueMembers = "Number of Deaths";
  chart1.Series["Series2"].XValueMember = "Reason";
  chart1.Series["Series2"].YValueMembers = "Number of Deaths";
  chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
  chart1.Series["Series1"].IsValueShownAsLabel = true;
  chart1.DataBind();
  </code></pre>
  
  <p>I get a drawn graph that looks like this, I have added the series in there through the properties pane of the chart;</p>
  
  <p><a href="https://i.stack.imgur.com/SU6Yh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SU6Yh.png" alt="output"></a></p>
  
  <p>But I want an output that should look like this;</p>
  
  <p><a href="https://i.stack.imgur.com/uZkyz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uZkyz.png" alt="actual output"></a></p>
  
  <p>I've tried googleing without success. Can somebody please help me with this?
  I'll appreciate it very much.
  Thanks</p>