Question

In: Computer Science

"How can I connect my hadoop database or mysql database server to my d3 visual?"

"How can I connect my hadoop database or mysql database server to my d3 visual?"

Solutions

Expert Solution

connecting MYSQL database server to d3 visual:

First way:

Note:d3 requires json file as input

The following is a php script that you should be able to save somewhere as a file (let's say you call it 'getdata.php') accessible from your HTML file with your D3 code in it. When called it will return data from your MySQL database in a json format (so long as the database server isn't outside your 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 ( ! $myquery ) {
        echo mysql_error();
        die;
    }

    $data = array();

    for ($x = 0; $x < mysql_num_rows($query); $x++) {
        $data[] = mysql_fetch_assoc($query);
    }

    echo json_encode($data);     

    mysql_close($server);
?>

Obviously you would need to enter appropriate details for username, password, host and database. You would also need to include an appropriate query for your data so that it returned data for 'dateTimeTaken' and 'reading'. Something along the lines of (and this is only a guess);

SELECT `dateTimeTaken`, `reading` FROM `tablename`

Then when you go to read in your json file you would use the following syntax for the code where you would be reading in your json;

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

Hopefully that's close to what you're looking for. I've tested it locally and it all seems to work..

And another way is:

  1. Using Python, connect with database and convert the data in json format. Save this in some .json file.

  2. In d3, read this json file as input and use it in visualization.


Related Solutions

Using PHP and MYSQL and with a simple customer database, how can I create a simple...
Using PHP and MYSQL and with a simple customer database, how can I create a simple log in and registration system for an ecommerce site
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get...
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get the error: ...could not start SASL... no mechanism available: unable to find a callback: 2"
Part 2: Use MySQL Workbench to add a table to your database on the class server...
Part 2: Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table: Field Name Description Data Type Sample Value LoginID User’s login name varchar(10) Bob FirstName User’s first name varchar(50) Bob LastName User’s last name varchar(50) Barker picUrl Filename of the user’s picture varchar(50) bob.gif Bio User’s biography varchar(255) Bob is the best! LoginID should be the Primary Key of the table. Add at...
PHP, JAVASCRIPT, MYSQL below is what I have. Can fill in the details for the database...
PHP, JAVASCRIPT, MYSQL below is what I have. Can fill in the details for the database 5. “Login to DB”, “Logout DB”, sub-menus of “File” 5.1 _____ When the user selects “Login to DB”, a window should popup asking the user to enter login and password. Your program should verify the login and password against the DV_User table in the datamining database. A corresponding message should be shown in the message area when the login failed or successful. If it...
How to Connect an Android Application to Firebase Realtime Database and write a simple database in...
How to Connect an Android Application to Firebase Realtime Database and write a simple database in Java. Please attach screenshots of the activity performed.
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE edu; Create a script which will create the tables listed below: STUDENT(STUDENT_ID, STUDENT_NAME, MAJOR_ID, DOB, PHONE_NUMBER) MAJOR(MAJOR_ID, MAJOR_NAME) ENROLLMENT(STUDENT_ID, COURSE_ID, GRADE) COURSE(COURSE_ID, COURSE_NAME) RESPONSIBILITY(FACULTY_ID, COURSE_ID) TEACHER(FACULTY_ID, DEPT_ID, TEACHER_NAME) DEPARTMENT(DEPT_ID, DEPARTMENT_NAME) Start the script with a series of DROP statements so that as you correct mistakes you will start fresh each time. To avoid referential integrity errors, the table drops should be in the opposite...
how can i lower my expences when i know my income is vere good but my...
how can i lower my expences when i know my income is vere good but my expences always ALMOST reaches my income but i know i cant do anything as i know i need this liabilities. what can i do or what strategy can i make in order to lower my expences!!! ?????
the mysql lyrics database is provided below 1.)What is a primary key used for? Can you...
the mysql lyrics database is provided below 1.)What is a primary key used for? Can you give me an example of a primary key in the Lyrics database? 2.)What is the purpose of doing a join between two tables. Ex. Why would I ever want to join the Tracks and Titles tables together? 3.)Why is isolation important in database design? DROP TABLES IF EXISTS Artists,Genre, Members, Titles, Tracks,SalesPeople,Studios,XrefArtistsMembers; DROP TABLES IF EXISTS Authors,Publishers,Titles,Title_Authors,Royalties; DROP TABLES IF EXISTS Products,Customers,Orders,Order_details; DROP TABLES...
how can i convert this to work in visual basic ? what are the formulas for...
how can i convert this to work in visual basic ? what are the formulas for that? You must create a Windows Forms application as the Conversion project including a picture of money on your form.  Create a textbox for the user to entry a dollar amount. Determine the number of quarters, dimes, nickels, and pennies using label controls to display the results.  In your calculation, you should use constant variables. ex) Enter dollar amount for conversion of 4.69 Number...
using PDO, MYSQL, and Html, how can i create a simple registration and login form for...
using PDO, MYSQL, and Html, how can i create a simple registration and login form for cPanel?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT