Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:40:29+00:00 2026-06-15T03:40:29+00:00

I retrieve several datatables from my DB, which vary in size. This one of

  • 0

I retrieve several datatables from my DB, which vary in size. This one of 2 is just an example.

See the structure here!
enter image description 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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:40:30+00:00Added an answer on June 15, 2026 at 3:40 am

    I managed to do it myself, but you Gregor Primar pushed me in the right direction!

    What was important was that you set the valuetype for the X and Y-axis. As decimal type was not an option I used auto as type.

    Chart1.DataSource = dt;
    
    int amountofrows = Convert.ToInt32(dt.Rows[0]["antal"].ToString());
    
    for (int i = 0; i < amountofrows; i++)
    {
        List<string> xvals = new List<string>();
        List<decimal> yvals = new List<decimal>();
        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))     
            {                    
                xvals.Add(dr["ranking_date"].ToString());
                yvals.Add(Convert.ToDecimal(dr["ranking_position"].ToString()));              
            }
    
            }
            catch (Exception)
            {
    
                throw new InvalidOperationException("Diagrammet kunde inte ritas upp");
            }
        }
        try
        {
            Chart1.Series[serieName].XValueType = ChartValueType.String;
            Chart1.Series[serieName].YValueType = ChartValueType.Auto;
            Chart1.Series[serieName].Points.DataBindXY(xvals.ToArray(), yvals.ToArray());
        }
        catch (Exception)
        {
    
            throw new InvalidOperationException("Kunde inte bind punkterna till Diagrammet");
        }    
    }
    
    Chart1.DataBind();
    Chart1.Visible = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In several recent answers I see this code given as the way to retrieve
I have several web services. One of this services is used for retrieve a
I tried several ways to retrieve datetime2(3) equivalent from C# code but in vain.
Lest say that we have several pages that retrieve items from the same EntitySet.
To retrieve k random numbers from an array of undetermined size we use a
I am using Zend_Db_Select currently to retrieve hierarchical data from several joined tables. I
I need to retrieve data from several rows and then insert the results into
I currently use the Linq to SharePoint to retrieve data from several SharePoint lists.
I have several php scripts which connect to my sql server and retrieve some
I would like to retrieve several items in one cell of a table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.