简体   繁体   English

具有SQL Server 2012中数据的动态Sankey图

[英]Dynamic Sankey diagram with data from SQL server 2012

Please suggest me ideas on the below requirement. 请就以下要求向我提出建议。

My requirement is to create a dynamic Sankey diagram which gets generated from the SQL Server Data. 我的要求是创建一个从SQL Server数据生成的动态Sankey图。 For example, when user clicks a dropdown, the dropdown should be passed as input to the SQL Server Database and would return data with which the Sankey chart would be built. 例如,当用户单击一个下拉列表时,该下拉列表应作为输入传递到SQL Server数据库,并将返回用于构建Sankey图表的数据。 I researched and found that Sankey's can be generated from CSV data and Json data. 我研究发现,可以从CSV数据和Json数据生成Sankey。 I am thinking to extract the data from SQL server and convert it into Json and then giving this Json as input for generating the Sankey diagram. 我正在考虑从SQL Server提取数据并将其转换为Json,然后将此Json作为生成Sankey图的输入。 I am trying to build it in PHP or asp.net and use the javascript's d3 plugin for Sankey. 我正在尝试在PHP或asp.net中构建它,并为Sankey使用javascript的d3插件。

Please let me know if this is the only way or there are any other ways that I can program this Sankey from SQL. 请让我知道这是唯一的方法还是可以通过SQL对Sankey进行编程的任何其他方法。 I appreciate your time and effort for reading the post and thanks in advance for helping. 感谢您花费时间和精力阅读该帖子,并在此先感谢您的帮助。

Thanks and regards, Sathappan Ramanathan 感谢和问候,Sathappan Ramanathan

JS: (limits only IE) JS :(仅限IE)

// STEP 1: Initialize a new ActiveXObject for the SQL Server connection.
var connection = new ActiveXObject("ADODB.Connection") ;

// Your connection string: and this is the reason why you shouldn't do this
// in live website, "everyone has access to this connection string".
// replace the values within "<>" to your values.
var your_connection_string = "Data Source=<SQL Server (IP or host)>;Initial Catalog=<your catalog (a.k.a Database)>;User ID=<your username>;Password=<your password>;Provider=SQLOLEDB";

// STEP 2: Now open the connection using the connection string above.
connection.Open(your_connection_string);

// STEP 3: Initialize a new activeX object, this time for a recordset,
// so we can read data from database.
var rs = new ActiveXObject("ADODB.Recordset");

// STEP 4: Manipulate your data the way you want.
rs.Open("SELECT * FROM <your table>", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}

// STEP 5: be nice and Finalize the recordset and the connection.
rs.close;
connection.close;

working connection string (test on SQL 2008R2, 2014 integrated security) : 工作连接字符串(在SQL 2008R2上进行测试,2014年集成安全性):

 var connectionstring1 = "Data Source=servername\\instancename;Initial Catalog=DBname;Integrated Security=SSPI;Provider=SQLOLEDB";

I figured out the way to dynamically pull the data for the Sankey diagram. 我想出了为Sankey图动态提取数据的方法。 The d3 plugin uses a function called d3.json in which we have to give the file URL and instead of using the function ,if we put the json in a php variable and then pass the variable to the 'Graph' variable ,then it would pickup the data from the variable and hence the dynamic sankey is figured out.Thank you experts for your posts.This made me find the solution. d3插件使用了一个名为d3.json的函数,在该函数中,我们必须提供文件URL,而不是使用该函数,如果我们将json放在php变量中,然后将该变量传递给'Graph'变量,则它将从变量中提取数据,从而找出动态sankey。感谢专家的帮助。这使我找到了解决方案。

I have written a php program and putting the data in Mydata variable and calling this variable to the graph node. 我已经编写了一个php程序,并将数据放在Mydata变量中,然后将此变量调用到graph节点。 // load the data--Getting the data from the 'Mydata' Variable from the php code and using it in our graph variable.We should add a < in front of the ? //加载数据-从php代码的'Mydata'变量中获取数据,并在我们的graph变量中使用它。我们应该在?前面添加< in php 在PHP中

var graph = ?php echo ($Mydata);?>; var graph =?php echo($ Mydata);?>;

Best regards, Sathappan Ramanathan 最好的问候,Sathappan Ramanathan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM