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
<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];
var reportingManager = r.d[i][3] != null ? r.d[i][3].toString() : '';
data.addRows
([[{
f: employeeName,
v: employeeId,
}, 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
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)";
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;
}
}
}
}
}