I retrieve several datatables from my DB, which vary in size. This one of 2 is just an example.
See the structure here!
I managed to create the 2 different series and have them show up on the legend.
My question is on how to bind that data to the respective series. The series name are created from column doman_namn and the amount of series are created from the "antal" column which holds the number of unique URLS.
QUESTION HOW TO BIND ADDY and ADDX to the chart it fails now.
This is my code so far...
Chart1.DataSource = dt;
int amountofrows = Convert.ToInt32(dt.Rows[0]["antal"].ToString());
for (int i = 0; i < amountofrows; i++)
{
string serieName = dt.Rows[i]["doman_namn"].ToString();
Chart1.Series.Add(serieName);
Chart1.Series[i].ChartType = SeriesChartType.Line;
foreach(DataRow dr in dt.Rows)
{
try
{
if (String.Equals(serieName,dr["doman_namn"].ToString(), StringComparison.Ordinal))
{
Chart1.Series[serieName].Points.AddY(Convert.ToDouble(dr["ranking_position"]));
Chart1.Series[serieName].Points.AddY(Convert.ToDouble(dr["ranking_date"]));
}
}
catch (Exception)
{
throw new InvalidOperationException("Failed when adding points");
}
}
}
Chart1.DataBind();
Chart1.Visible = true;
CODE AFTER HELP FROM GREGOR
for (int i = 0; i < amountofrows; i++)
{
string serieName = dt.Rows[i]["doman_namn"].ToString();
Chart1.Series.Add(serieName);
Chart1.Series[i].ChartType = SeriesChartType.Line;
Chart1.Series[serieName].XValueMember = "ranking_date";
Chart1.Series[serieName].YValueMembers = "ranking_position";
}
Chart1.DataBind();