Monday, June 14, 2010

Graphical Pie Chart With Google Chart API in 3 steps


Download the latest version package from this link - http://code.google.com/p/googchart/


Step 1:

Include the API class file in the PHP file where you want to Display the Chart

include( 'GoogChart.class.php' );


Step 2:

Assign the datas which should be charted in the array variable say $data like below

$data = array(
'IE7' => 22,
'IE6' => 30.7,
'IE5' => 1.7,
'Firefox' => 36.5,
'Mozilla' => 1.1,
'Safari' => 2,
'Opera' => 1.4,
);
Set the Graph Color of your choice here in a array variable called $color
// Set graph colors
$color = array(
'#99C754',
'#54C7C5',
'#999999',
);

Step 3:

Finally building the Chart and printing it.

$chart->setChartAttrs( array(
'type' => 'pie',
'title' => 'Browser market 2008',
'data' => $data,
'size' => array( 400, 300 ),
'color' => $color
));

// Print chart
echo $chart;



Output:

















Supported types:

  • Pie
    Standard pie chart
  • Line
    Standard Line chart
  • Sparkline
    Almost identical to Line, except defaults to no axis lines.
  • Bar-horizontal
    Horizontal bar chart
  • Bar-vertical
    Vertical bar chart
Note :Examples for these types are Available in example.php available when you download this package.

Enjoy!



List DB and Tables using PHP

$conn = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
    //List DB
    $result = mysql_list_dbs( $conn );
    while( $row = mysql_fetch_object( $result ) ):
         echo  $row->Database "<br />";
    endwhile;

   //List Tables
  $db_name  = "test";
  $tables = mysql_list_tables("$db_name");
   while (list($table) = mysql_fetch_row($tables)) {
    $treeNodes->add($table,$table,$table,true,false,"","");
   }

  or
 $tables_list = mysql_query("SHOW TABLES FROM $db_name");
 

Followers