json - How to pull data from mysql database and visualize with D3.JS? -


i have database in mysql want visualize in d3.js. in order that, first want parse data in json format, write basic code pulls data database , visualize d3.js. around couldn't find want since i'm new d3.js.

how can achieve that? or clue appreciated.

the following php script should able save somewhere file (let's call 'getdata.php') accessible html file d3 code in it. when called return data mysql database in json format (so long database server isn't outside domain);

<?php     $username = "******";      $password = "******";        $host = "******";     $database="***dbase_name***";      $server = mysql_connect($host, $user, $password);     $connection = mysql_select_db($database, $server);      $myquery = "     query here     ";      $query = mysql_query($myquery);      if ( ! $query ) {         echo mysql_error();         die;     }      $data = array();      ($x = 0; $x < mysql_num_rows($query); $x++) {         $data[] = mysql_fetch_assoc($query);     }      echo json_encode($data);           mysql_close($server); ?> 

obviously need enter appropriate details username, password, host , database. need include appropriate query data returned looking for. along lines of (and guess);

select `datetimetaken`, `reading` `tablename` 

which return list of time stamps , values table called tablename columns called datetimetaken , reading. when go read in json file use following syntax code reading in json;

d3.json("getdata.php", function(error, data) { 

hopefully that's close you're looking for. i've tested locally , seems work..

i've put post go on local installation of simple wamp server , setting query on mysql database d3.js here http://www.d3noob.org/2013/02/using-mysql-database-as-source-of-data.html

this pretty same situation accessing mysql database in d3 visualization


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -