How-To Guides | Free PHP Chart & Graph http://www.chartphp.com HTML5 Chart & Graph for Web & Mobile using PHP Sun, 29 Oct 2017 10:38:01 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.3 85830749 Creating a Bar Chart using mySQL in PHP http://www.chartphp.com/creating-bar-chart-mysql-php/ Fri, 09 Sep 2016 19:00:47 +0000 http://www.chartphp.com/?p=687 This article will show how to create a mySQL driven bar chart using Charts 4 PHP Framework.

Step 1: Configure Database connectivity in config.php

'.wch_stripslashes('define("CHARTPHP_DBTYPE","pdo");
define("CHARTPHP_DBHOST","mysql:host=localhost;dbname=testdb");
define("CHARTPHP_DBUSER","username");
define("CHARTPHP_DBPASS","password");
define("CHARTPHP_DBNAME","");
').'


Step 2: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 3: Configure Data array using jQuery to fetch data from Database

'.wch_stripslashes('$p->data_sql = "select c.categoryname, sum(a.quantity) as Sales 
                   from products b, `order details` a, categories c 
                   where a.productid = b.productid and c.categoryid = b.categoryid
                   group by c.categoryid 
                   order by c.categoryid"; 
').'


Step 4: Set Chart type

'.wch_stripslashes('$p->chart_type = "bar";
').'


Step 5: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
687
Creating Dashboard with Charts 4 PHP http://www.chartphp.com/how-to-create-dashboard-php-mysql/ Wed, 22 Apr 2015 09:11:53 +0000 http://www.chartphp.com/?p=646 This article will show how to create a dashboard using Charts 4 PHP Framework with or without database (mySQL, Oracle, PDO etc.) at back end.

I. Creating first chart in Dashboard

Step 1: Configure Database connectivity in config.php

'.wch_stripslashes('define("CHARTPHP_DBTYPE","pdo");
define("CHARTPHP_DBHOST","sqlite:../../sampledb/Northwind.db");
define("CHARTPHP_DBUSER","");
define("CHARTPHP_DBPASS","");
define("CHARTPHP_DBNAME","");
').'


Step 2: Include Charts 4 PHP Library in Dashboard HTML

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 3: Select any one of the substep below to configure Data Array

Step 3a: Configure Data array

'.wch_stripslashes('$p->data = array(array(
array('Heavy Industry', 12),
array('Retail', 9), 
array('Light Industry', 14), 
array('Out of home', 16),
array('Commuting', 7), 
array('Orientation', 9)));
').'


Step 3b: Configure Data array using jQuery to fetch data from Database (e.g. for SQLite DB)

'.wch_stripslashes('$p->data_sql = "select c.categoryname, sum(a.UnitPrice * a.Quantity) as Sales
                from products b, `order details` a, categories c 
                where a.productid = b.productid and c.categoryid = b.categoryid
                    group by c.categoryid 
                    order by c.categoryid";
').'


Step 4: Set Chart type

'.wch_stripslashes('$p->chart_type = "pie";
').'


Step 5: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


This will give you a single chart in your dashboard something like this.

Single Chart Dashboard Sample

II. Creating multiple charts in your Dashboard

Step 1: Configure multiple charts into your Dashboard HTML

'.wch_stripslashes('$p = new chartphp();
$p->data = array(array(array("2010/10",48.25),array("2011/01",238.75),array("2011/02",95.50),array("2011/03",300.50),array("2011/04",286.80),array("2011/05",400)));
$p->chart_type = "bar";
$out_bar = $p->render('c2');

$p = new chartphp();
$p->data = array(array(array(60, 123, 1067, "Acura"), array(11, 92, 1236, "Alfa Romeo"), array(30, 200, 610, "AM General"), array(50, 23, 800, "Aston"), array(18, 17, 539, "Audi"), array(50, 89, 1026, "BMW"), array(99, 13, 864, "Bugatti")));
$p->chart_type = "bubble";
$out_bubble = $p->render('c3'); 

$p = new chartphp();
$p->intervals = array(200,300,400,600);
$p->chart_type = "meter";
$p->width = "200px";
$p->height = "150px";
$p->data = array(array(rand(200,600)));
$out_meter = $p->render('c4'); 
$p->data = array(array(rand(200,600)));
$out_meter2 = $p->render('c41'); 
$p->data = array(array(rand(200,600)));
$out_meter3 = $p->render('c42'); 
$p->data = array(array(rand(200,600)));
$out_meter4 = $p->render('c43'); 
').'


Step 2: Render multiple charts in your dashboard to get the final look like this:

dashboard-final

 

For complete code, please visit live demo.

]]>
646
Creating a Line Chart using mySQL in PHP http://www.chartphp.com/how-to-create-line-chart-mysql-php/ Mon, 13 Apr 2015 07:05:18 +0000 http://www.chartphp.com/?p=635 This article will show how to create a mySQL driven line chart using Charts 4 PHP Framework.

Step 1: Configure Database connectivity in config.php

'.wch_stripslashes('define("CHARTPHP_DBTYPE","pdo");
define("CHARTPHP_DBHOST","mysql:host=localhost;dbname=testdb");
define("CHARTPHP_DBUSER","username");
define("CHARTPHP_DBPASS","password");
define("CHARTPHP_DBNAME","");
').'


Step 2: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 3: Configure Data array using jQuery to fetch data from Database

'.wch_stripslashes('$p->data_sql = "select strftime('%Y-%m',o.orderdate) as Year, sum(d.quantity) as Sales 
                    from `order details` d, orders o 
                    where o.orderid = d.orderid 
                    group by strftime('%Y-%m',o.orderdate) limit 50";
').'


Step 4: Set Chart type

'.wch_stripslashes('$p->chart_type = "line";
').'


Step 5: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
635
Creating a Funnel Chart using PHP http://www.chartphp.com/how-to-create-funnel-chart-php/ Wed, 01 Apr 2015 11:41:54 +0000 http://www.chartphp.com/?p=582 data = array(array( array('Heavy Industry', 12), array('Retail', 9), array('Light Industry', 14), array('Out of home', 16), array('Commuting', […]]]> This article will show how to create a simple funnel chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array along with Intervals array

'.wch_stripslashes('$p->data = array(array(
array('Heavy Industry', 12),
array('Retail', 9), 
array('Light Industry', 14), 
array('Out of home', 16),
array('Commuting', 7), 
array('Orientation', 9)
));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "funnel";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
582
Creating a Meter Chart using PHP http://www.chartphp.com/how-to-create-meter-gauge-chart-php/ Mon, 30 Mar 2015 20:07:58 +0000 http://www.chartphp.com/?p=553 data = array(array(266)); $p->intervals = array(200,300,400,600); ').' ‘ Step 3: Set Chart type ‘ '.wch_stripslashes('$p->chart_type = […]]]> This article will show how to create a simple meter chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array along with Intervals array

'.wch_stripslashes('$p->data = array(array(266)); 
$p->intervals = array(200,300,400,600); 
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "meter";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
553
Creating a Pie Chart using PHP http://www.chartphp.com/how-to-create-pie-chart-php/ Mon, 30 Mar 2015 20:05:39 +0000 http://www.chartphp.com/?p=551 data = array(array( array('Heavy Industry', 12), array('Retail', 9), array('Light Industry', 14), array('Out of home', 16), array('Commuting', 7), array('Orientation', 9) )); […]]]> This article will show how to create a simple pie chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array

'.wch_stripslashes('$p->data = array(array(
array('Heavy Industry', 12),
array('Retail', 9), 
array('Light Industry', 14), 
array('Out of home', 16),
array('Commuting', 7), 
array('Orientation', 9)
));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "pie";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
551
Creating a Donut Chart using PHP http://www.chartphp.com/how-to-create-donut-chart-php/ Mon, 30 Mar 2015 20:00:35 +0000 http://www.chartphp.com/?p=547 data = array(array(array('a',6), array('b',8), array('c',14), array('d',20))); ').' ‘ Step 3: Set Chart type ‘ '.wch_stripslashes('$p->chart_type = "donut"; ').' ‘ Step […]]]> This article will show how to create a simple donut chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array

'.wch_stripslashes('$p->data = array(array(array('a',6), array('b',8), array('c',14), array('d',20)));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "donut";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
547
Creating a Bubble Chart using PHP http://www.chartphp.com/how-to-create-bubble-chart-php/ Mon, 30 Mar 2015 19:55:28 +0000 http://www.chartphp.com/?p=540 data = array(array( array(11, 123, 1236, "Acura"), array(45, 92, 1067, "Alfa Romeo"), array(24, 104, 1176, "AM General"), array(50, 23, 610, […]]]> This article will show how to create a simple bubble chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array

'.wch_stripslashes('$p->data = array(array(
array(11, 123, 1236, "Acura"), 
array(45, 92, 1067, "Alfa Romeo"), 
array(24, 104, 1176, "AM General"), 
array(50, 23, 610, "Aston Martin Lagonda"), 
array(18, 17, 539, "Audi"), array(7, 89, 864, "BMW"), 
array(2, 13, 1026, "Bugatti")
));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "bubble";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
540
Creating a Bar Chart using PHP http://www.chartphp.com/how-to-create-bar-chart-php/ Mon, 30 Mar 2015 19:51:24 +0000 http://www.chartphp.com/?p=538 data = array(array( array("2010/10",48.25), array("2011/01",238.75), array("2011/02",95.50), array("2011/03",300.50), array("2011/04",286.80), array("2011/05",400) )); ').' ‘ Step 3: Set Chart type ‘ '.wch_stripslashes('$p->chart_type = […]]]> This article will show how to create a simple bar chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array

'.wch_stripslashes('$p->data = array(array(
array("2010/10",48.25),
array("2011/01",238.75),
array("2011/02",95.50),
array("2011/03",300.50),
array("2011/04",286.80),
array("2011/05",400)
));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "bar";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
538
Creating an Area Chart using PHP http://www.chartphp.com/how-to-create-area-chart-php/ Mon, 30 Mar 2015 19:45:52 +0000 http://www.chartphp.com/?p=535 data = array(array(3,7,9,1,4,6,8,2,5),array(5,3,8,2,6,2,9,2,6)); ').' ‘ Step 3: Set Chart type ‘ '.wch_stripslashes('$p->chart_type = "area"; ').' ‘ Step 4: Render Chart […]]]> This article will show how to create a simple area chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array

'.wch_stripslashes('$p->data = array(array(3,7,9,1,4,6,8,2,5),array(5,3,8,2,6,2,9,2,6));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "area";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
535
Creating a Line Chart using PHP http://www.chartphp.com/how-to-create-line-chart-php/ Mon, 30 Mar 2015 11:49:30 +0000 http://www.chartphp.com/?p=519 data = array(array(3,7,9,1,4,6,8,2,5),array(5,3,8,2,6,2,9,2,6)); ').' ‘ Step 3: Set Chart type ‘ '.wch_stripslashes('$p->chart_type = "line"; ').' ‘ Step 4: Render Chart […]]]> This article will show how to create a simple line chart using Charts 4 PHP Framework.

Step 1: Include Charts 4 PHP Library

'.wch_stripslashes('include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();
').'


Step 2: Configure Data array

'.wch_stripslashes('$p->data = array(array(3,7,9,1,4,6,8,2,5),array(5,3,8,2,6,2,9,2,6));
').'


Step 3: Set Chart type

'.wch_stripslashes('$p->chart_type = "line";
').'


Step 4: Render Chart

'.wch_stripslashes('$out = $p->render("c1");
').'


For complete code, please visit live demo.

]]>
519