Multi-line/multi-column charts

Hi,
I am looking for an example to create a multi column/line chart  with data from a MSSQLSERVER database.
I have successfully created a simple, single line chart from datatable but need a more advanced example to create multiple lines.
I also need an example of the table structure.
rgs
Zack

3 Replies

SK Saravana Kumar Kanagavel Syncfusion Team November 10, 2017 10:45 AM UTC

 Hi Zack, 
 
Thanks for contacting Syncfusion Support. 
 
We have analyzed your query and prepared a sample based on your requirement. In the sample, we have initially created the two rows with data in the Table and then we have dynamically add the hundred data in table using SQL command. 
 
Please find the code snippet below 
 
[C#] 
protected void Page_Load(object sender, EventArgs e) 
        { 
            string connectionString = null; 
            // Create sql adapter 
            SqlDataAdapter adapter = new SqlDataAdapter(); 
            // create data set for storing the data 
            DataSet dataset = new DataSet(); 
            // Getting connection string from database 
            connectionString = @"Data Source=SYNCLAPN7425\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"; 
            SqlConnection con = new SqlConnection(connectionString); 
            // open the connection 
            con.Open(); 
            // Create the sql command 
            SqlCommand cmd = new SqlCommand(); 
            // provide the command 
            cmd.CommandText = "INSERT INTO Table_1(xName, yName,yName1,yName2) VALUES(@xName, @yName,@yName1,@yName2)"; 
            Random r = new Random(); 
            string command2 = "select * from Table_1"; 
            SqlCommand cmd1 = new SqlCommand(command2, con); 
            adapter.SelectCommand = cmd1; 
            // Data set added into the sql adapter 
            adapter.Fill(dataset); 
            int count = dataset.Tables[0].Rows.Count; 
            double value = Double.Parse(dataset.Tables[0].Rows[count - 1].ItemArray[0].ToString()); 
            // Added the data into table 
            for (double i = (value + 1); i <= (value + 100); i++) 
            { 
                cmd.Parameters.Add("@xName", SqlDbType.VarChar).Value = i; 
                cmd.Parameters.Add("@yName", SqlDbType.VarChar).Value = r.Next(1, 30); 
                cmd.Parameters.Add("@yName1", SqlDbType.VarChar).Value = r.Next(30, 60); 
                cmd.Parameters.Add("@yName2", SqlDbType.VarChar).Value = r.Next(60, 100); 
                cmd.Connection = con; 
                cmd.ExecuteNonQuery(); 
                cmd.Parameters.Clear(); 
            } 
            adapter.SelectCommand = cmd1; 
            adapter.Fill(dataset); 
            List<ChartData> data = new List<ChartData>(); 
            bool process = true; 
            // Getting the data from the sql adapter 
            for (int j = 0; j < dataset.Tables[0].Rows.Count; j++) 
            { 
                string x = dataset.Tables[0].Rows[j].ItemArray[0].ToString(); 
                process = (data.Any(z => z.Xvalue == x)) ? false : true; 
                if (process) 
                { 
                    double yValue1 = Double.Parse(dataset.Tables[0].Rows[j].ItemArray[1].ToString()); 
                    double yValue2 = Double.Parse(dataset.Tables[0].Rows[j].ItemArray[2].ToString()); 
                    double yValue3 = Double.Parse(dataset.Tables[0].Rows[j].ItemArray[3].ToString()); 
                    data.Add(new ChartData(x, yValue1,yValue2,yValue3)); 
                } 
            } 
            // Close the sql connection 
            con.Close(); 
            // Binding the data 
            this.Chart1.DataSource = data; 
            this.Chart1.DataBind(); 
        } 
 
Note : You can change the connection string based on your Database connection. 
 
And you can find the sample from the below location. 
 
  
Please find the output of the sample below 
 
 
 
Please find the screenshot of initially created data from the below 
 
 
 
Please find the screenshot after adding the data into the table from the below 
 
 
 
 
Please let us know if you have any concern. 
 
Regards, 
Saravana Kumar K. 




ZS Zack Snyders November 12, 2017 05:02 AM UTC

This is working fine for me, thank you!

kind regards

Zack



SK Saravana Kumar Kanagavel Syncfusion Team November 13, 2017 07:36 AM UTC

Hi Zack, 
 
Thanks for your update. 
 
Please let us know if you need any other assistance on this. 
 
Regards, 
Saravana Kumar K. 


Loader.
Up arrow icon