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...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender)...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender) Primary key = Id Friends (Id1, Id2, Startdate) Primary key = (Id1, Id2) Foreign keys are also Id1, Id2 pointing to User(Id) Comments (CommentId, Poster, Recipient, Text, PostDate) Primary key = (CommentId) Foreign Keys are Poster, Recipient pointing to User(Id) I need to answer the following queries: 5. List Users who have posted comments to all female users 6. List User(s) who have received...
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...
I am coding in MySQL and two of my tables are populating find but the other...
I am coding in MySQL and two of my tables are populating find but the other two "Employee" and "Assignment" won't. I keep getting an error code saying I can't alter a child table and I can't figure out what to fix. Here is my code: CREATE TABLE DEPARTMENT ( DepartmentName Char(35) NOT NULL, BudgetCode Char(30) NOT NULL, OfficeNumber Char(15) Not Null, DepartmentPhone Char(12) NOT NULL, CONSTRAINT DEPARTMENT_PK primary key(DepartmentName) ); CREATE TABLE EMPLOYEE( EmployeeNumber Int NOT NULL AUTO_INCREMENT, FirstName...
subject DBA use mysql workbench and select my guitar shop database as default schema Problem8 Write...
subject DBA use mysql workbench and select my guitar shop database as default schema Problem8 Write a script that implements the following design in a database named my_web_db:     users                                                       downloads                                                                 Products *user_id INT                                         * download_id INT                                                   * product_id INT                      *email_address VARCHAR(100)          * user_id INT                                                         * product_name VARCHAR(45) *first_name VARCHAR(45)                  *download_date DATETIME *last_name VARCHAR(45)                  * filename VARCHAR(50)                                                                *product_id INT Details In the downloads table, the user_id and product_id columns are the foreign keys. Include a statement to drop the...
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!!! ?????
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT