How to create Sankey Diagrams in PHP

Sankey Diagrams

Sankey Diagrams are a type of diagram that shows flows and their quantities proportionally to one another. Dashboard Builder helps you to create sankey diagrams with a drag and drop tool and a SQL engine with ease. Dashboard Builder generates PHP source code for you to use it anywhere in your application.

 

Requirements

  • PHP Version 5.6 or later
  • Apache 2 or later
  • Windows 7 or later /Linux 3 or later
  • Firefox 52, Chrome 57, IE 8

 

Installation

 

Create your first Sankey Diagrams

 

 

 

  • Now Click the Database icon
  • The following screen will appear. Select Database from data source tab. Select SQLite from the drop down list of Database, Enter your "../data/Northwind.db" in the DB name field and Save changes    as mentioned in the screen.

 

 

 

  • A green tick mark with Database  will appear when your database is successfully connected.

 

 

  • Select the gear icon for your Dashboard preference.

 

 

  • The following screen will appear. List of the tables will appear.

 

 

  • Enter your SQL statement in text box, SQL field as the following manner or just click on snakey tabel

SELECT * FROM sankey;

  • Click the Run Query button

 

  • Query Result will appear. Now Select your x-axis data from the drop down list of  , y-axis data from the drop down list of Y , Value data the drop down list of Value and Text data from the drop down list of Text
  • Select Sankey from the drop down list of Type
  • Click Save Changes

 

 

  • Charts will be appeared on the screen as shown below.

 

 

  • Now extend the Generate button and click on the PHP Code

 

 

  • PHP code for the chart will automatically generate, you may copy past this code to your PHP application.

 

PHP Code


/**
 * DashboardBuilder
 *
 * @author Diginix Technologies www.diginixtech.com
 * Support  - http://www.dashboardbuilder.net
 * @copyright (C) 2018 Dashboardbuilder.net
 * @version 2.1.8
 * @license: license.txt
 */

include("inc/dashboard_dist.php");  // copy this file to inc folder 


// for chart #1


$data = new dashboardbuilder(); 
$data->type =  "sankey";

$data->source =  "Database"; 
$data->rdbms =  "sqlite"; 
$data->servername =  "";
$data->username =  "";
$data->password =  "";
$data->dbname =  "../data/Northwind.db";
$data->xaxisSQL[0]=  "SELECT * FROM sankey;";
$data->xaxisCol[0]=  "X";
$data->yaxisSQL[0]=  "SELECT * FROM sankey;";
$data->yaxisCol[0]=  "Y";
$data->sizeSQL[0]=  "SELECT * FROM sankey;";
$data->sizeCol[0]=  "Value";
$data->textSQL[0]=  "SELECT * FROM sankey;";
$data->textCol[0]=  "TEXT";

$data->name = "0";
$data->title = "";
$data->orientation = "";
$data->xaxistitle = "";
$data->yaxistitle = "";
$data->showgrid = "";
$data->showline = "";
$data->height = "380";
$data->width = "";
$data->col = "0";

$result[0] = $data->result();?>


<!DOCTYPE html>
<html> 
<head> 
	<script src="assets/js/dashboard.min.js"></script> <!-- copy this file to assets/js folder --> 
	<!--<link rel="stylesheet" href="assets/css/bootstrap.min.css"> Bootstrap CSS file, change the path accordingly --> 


</head>
<body> 

<div class="container">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading"></div>
    <div class="panel-body">
        <?php echo $result[0];?>
    </div>
</div>
</div>
</div>
</body>


 

 

The project also offers free and paid plans. The code for Dashboard Builder can be found on GitHub under this license