Click here to Skip to main content
15,914,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1) i have table named "supply chain" in which data of customers like sellers and buyers relationship

2) i want to display these multiple relation ship into a chart like "Organizational chart".

What I have tried:

Html
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("visualization", "1", { packages: ["orgchart"] });
            google.setOnLoadCallback(drawChart);
            function drawChart() {
                $.ajax({
                    type: "POST",
                    url: "CS.aspx/GetChartData",
                    data: '{}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (r) {
                        var data = new google.visualization.DataTable();
                        data.addColumn('string', 'Entity');
                        data.addColumn('string', 'ParentEntity');
                        data.addColumn('string', 'ToolTip');
                       
                        for (var i = 0; i < r.d.length; i++)
                        {
                            //var employeeId = r.d[i][0].toString();
                            //var employeeName = r.d[i][1];
                            //var designation = r.d[i][2];
                            //var reportingManager = r.d[i][3] != null ? r.d[i][3].toString() : '';
                            //data.addRows
                            var employeeId = r.d[i][0].toString();
                            var employeeName = r.d[i][1]
                            var designation = r.d[i][2];
                            var reportingManager = r.d[i][3];
                            var reportingManager = r.d[i][3] != null ? r.d[i][3].toString() : '';
                            data.addRows
                                ([[{
                                f: employeeName,
                                v: employeeId,
                                 //+ '<div>(<span>' + designation + '</span>)</div><img src = "Pictures/' + employeeId + '.jpg" />'
                            }, reportingManager, designation]]);
                        }
                        var chart = new google.visualization.OrgChart($("#chart")[0]);
                        chart.draw(data, { allowHtml: true });
                    },
                    failure: function (r) {
                        alert(r.d);
                    },
                    error: function (r) {
                        alert(r.d);
                    }
                });
            }
        </script>

cs code
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using SPM.BLL;
using DevExpress.Web;

namespace SPM
{
    public partial class CS : System.Web.UI.Page
    {

        public static string TypeID, ID;

        [WebMethod]
        
        public static List<object> GetChartData()
        {
            string query = "SELECT     SupplyChain.SellerID, SupplyChain.BuyerID, ViewAllCustomerForSpplyChain_1.CompanyName AS SellerName,  ViewAllCustomerForSpplyChain.CompanyName AS BuyerName FROM         SupplyChain INNER JOIN ViewAllCustomerForSpplyChain AS ViewAllCustomerForSpplyChain_1 ON SupplyChain.MasterID = ViewAllCustomerForSpplyChain_1.ID AND SupplyChain.MasterTypeID = ViewAllCustomerForSpplyChain_1.TypeID INNER JOIN  ViewAllCustomerForSpplyChain ON SupplyChain.ChildID = ViewAllCustomerForSpplyChain.ID AND SupplyChain.ChildTypeID = ViewAllCustomerForSpplyChain.TypeID WHERE     (SupplyChain.DeleteStatus = 0)";
            //query += " FROM EmployeeHierarchy";
            string constr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand(query))
                {
                    List<object> chartData = new List<object>();
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                    con.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            chartData.Add(new object[]
                {
                     sdr["SellerID"], sdr["SellerName"], sdr["BuyerName"] , sdr["BuyerID"]
                });
                        }
                    }
                    con.Close();
                    return chartData;

                }
            }
        }
    }
}
Posted
v2
Comments
Nice!!! So, what is the question?
Noman Suleman 20-Jun-16 3:12am    
i have mentioned above what i need
Maciej Los 20-Jun-16 4:26am    
We know what you want to achieve, but we don't know what kind of issue do you get...
Noman Suleman 20-Jun-16 4:51am    
i have multiple parent child records in table means my child record in some cases become a parent of other child record and other child record would be parent of other child record.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900