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 7179835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:13:17+00:00 2026-05-28T17:13:17+00:00

Hello I’m trying to populate a mschart from sql but even if the series

  • 0

Hello I’m trying to populate a mschart from sql but even if the series have different values the chart is the same. So all the series have the same line overlapping each other.

        sqlConnection.Open();
        SqlCommand cmd = new SqlCommand(query, sqlConnection);
        cmd.CommandType = CommandType.Text;
        cmd.CommandTimeout = 300;
        rdr = cmd.ExecuteReader();
         DataTable table = new DataTable();

        // Add three columns to the table.
        table.Columns.Add("Channel", typeof(String));
        table.Columns.Add("Date", typeof(String));
        table.Columns.Add("Value", typeof(Int32));


        // Add data rows to the table.
        while (rdr.Read())
        {

            table.Rows.Add(new object[] { rdr[0], rdr[1], rdr[2] });

        }
        chart1.DataSource = table;
        //add series
        for (int i = 0; i < table.Rows.Count; i++)
        {
            if (chart1.Series.Where(x => x.Name == table.Rows[i][0].ToString()).Count() > 0)
            {

            }
            else
            {
                chart1.Series.Add(table.Rows[i][0].ToString());

            }
        }
        //set x,y axis for each series
        for (int i = 0; i < chart1.Series.Count; i++)
        {

            chart1.Series[i].XValueMember = "Date";
            chart1.Series[i].YValueMembers = "Value";

            chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

        }
        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-05-28T17:13:18+00:00Added an answer on May 28, 2026 at 5:13 pm

    Found Another way without databinding

       #region get values from database
            string query = "declare @start datetime, @end datetime select @start = '" + start + "', @end = '" + end + "' select Name,DataDT,Rating,DataGroupID from DATA inner join Channels on Channels.ID = DATA.ChannelID where DataDT >= @start and DataDT < @end and ChannelID<'4'";
            SqlDataReader rdr = null;
            sqlCon = new SqlConnection(Properties.Settings.Default.ConectionString);
            sqlConnection.Open();
            SqlCommand cmd = new SqlCommand(query, sqlConnection);
            cmd.CommandType = CommandType.Text;
            cmd.CommandTimeout = 300;
            rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            DataTable table = new DataTable();
            // Add three columns to the table.
            table.Columns.Add("Channel", typeof(String));
            table.Columns.Add("Date", typeof(String));
            table.Columns.Add("Value", typeof(Int32));
    
            // Add data rows to the table.
            while (rdr.Read())
            {
                table.Rows.Add(new object[] { rdr[0], rdr[1], rdr[2] });
            }
            sqlCon.Close();
    
    
            #endregion
    
    
    
            // Create a data series
    
    
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (chart1.Series.Where(x => x.Name == table.Rows[i][0].ToString()).Count() > 0)
                {
    
                }
                else
                {
                    Series series = new Series(table.Rows[i][0].ToString());
                    chart1.Series.Add(series);
    
                }
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                foreach (Series series in chart1.Series)
                {
                    if (table.Rows[i][0].ToString() == series.Name)
                    {
                        series.Points.AddXY(Convert.ToDateTime(table.Rows[i][1]).ToShortTimeString(),Convert.ToDouble(table.Rows[i][2]));
                    }
    
                }
            }
            //Set Properties for chart series
            for (int i = 0; i < chart1.Series.Count; i++)
            {
    
                chart1.Series[i].XValueMember = "Date";
                chart1.Series[i].YValueMembers = "Value";
    
                chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                chart1.Series[i].XValueType = ChartValueType.Time;
                chart1.Series[i].ChartType = SeriesChartType.Line;
    
                chart1.Series[i].MarkerStyle = MarkerStyle.Star10;
                chart1.Series[i].MarkerSize = 8;
                chart1.Series[i].MarkerColor = chart1.Series[0].BorderColor;
                chart1.Series[i].BorderWidth = 3;
                chart1.Series[i].IsValueShownAsLabel = true;
                chart1.Series[i].ToolTip = "#VALY => #AXISLABEL";
            }
    
            chart1.ChartAreas[0].AxisX.IsMarginVisible = true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm trying to write some values to my SQL through the C# WinForm
Hello we have an SQL server application running over a low bandwith connection. We
Hello i have Mschart on a winform y axis is value 1,2 ... and
Hello I have this query... if (isset($_REQUEST['deletePost'])) { $q = $dbc -> prepare(DELETE FROM
Hello I'm trying to take backup from mysql command line client. I'm using mysqldump
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I am compiling a program with make but I get the error of
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =

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.