0

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. 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. I researched and found that Sankey's can be generated from CSV data and Json data. 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. I am trying to build it in PHP or asp.net and use the javascript's d3 plugin for Sankey.

Please let me know if this is the only way or there are any other ways that I can program this Sankey from SQL. I appreciate your time and effort for reading the post and thanks in advance for helping.

Thanks and regards, Sathappan Ramanathan

zx485
  • 28,498
  • 28
  • 50
  • 59
sathappan
  • 1
  • 2

2 Answers2

0

JS: (limits only 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) :

 var connectionstring1 = "Data Source=servername\\instancename;Initial Catalog=DBname;Integrated Security=SSPI;Provider=SQLOLEDB";
Igor
  • 263
  • 2
  • 5
  • 13
  • http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript-in-the-browser – Igor Jul 01 '16 at 07:35
  • http://stopbyte.com/1025/whats-the-best-way-connect-to-sql-server-database-from-javascript – Igor Jul 01 '16 at 07:35
  • NODE way: http://stackoverflow.com/questions/4728385/connecting-to-a-remote-microsoft-sql-server-from-node-js – Igor Jul 01 '16 at 07:36
  • Hello Igor, Thanks for your time and reply. I find that this ActiveX can be used only in IE but I need to create a page which can be accessed by anyone using any browser.Also , Can I pass this activeX object as a input to the Sankey diagram.My final output should contain a dynamic sankey diagram. – sathappan Jul 01 '16 at 15:50
  • Then in the future this way isn't suitable for your requirements and prospect. – Igor Jul 01 '16 at 16:26
0

I figured out the way to dynamically pull the data for the Sankey diagram. 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.

I have written a php program and putting the data in Mydata variable and calling this variable to the graph node. // 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 ? in php

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

Best regards, Sathappan Ramanathan

sathappan
  • 1
  • 2