web 2.0

How to use PHP & Chart/Graph - Cylinder Column Clustered

How to use PHP & Chart/Graph - Cylinder Column Clustered This learn / tutorial php programming how to using  PHP Create Chart/Graph - Cylinder Column Clustered

ShotDev Focus:
- PHP  & Create Chart/Graph - Cylinder Column Clustered

Example

php_chart_cylinder.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
//*** Connect to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp

//*** File Name Gif,Jpeg,... ***//
$FileName = "MyXls/MyChart.Gif";
$Ext = "Gif";

//*** Excel Name ***//
$XlsName = "MyXls/MyChart.xls";

//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();

$intStartRows = 2;
$intEndRows = mysql_num_rows($objQuery)+($intStartRows-1);

$xlSheet = $xlBook->Worksheets(1);

$xlApp->Application->Visible = False;

//*** Delete Sheet (2,3) - Sheet Default ***//
$xlBook->Worksheets(2)->Select;
$xlBook->Worksheets(2)->Delete;
$xlBook->Worksheets(2)->Select;
$xlBook->Worksheets(2)->Delete;

//*** Sheet Data Rows ***//
$xlBook->Worksheets(1)->Name = "MyReport";
$xlBook->Worksheets(1)->Select;

$xlBook->ActiveSheet->Cells(1,1)->Value = "Customer Name";
$xlBook->ActiveSheet->Cells(1,1)->Font->Name = "Tahoma";
$xlBook->ActiveSheet->Cells(1,1)->BORDERS->Weight = 1;
$xlBook->ActiveSheet->Cells(1,1)->Font->Size = 10;
$xlBook->ActiveSheet->Cells(1,1)->MergeCells = True;

$xlBook->ActiveSheet->Cells(1,2)->Value = "Budget";
$xlBook->ActiveSheet->Cells(1,2)->BORDERS->Weight = 1;
$xlBook->ActiveSheet->Cells(1,2)->Font->Name = "Tahoma";
$xlBook->ActiveSheet->Cells(1,2)->Font->Size = 10;
$xlBook->ActiveSheet->Cells(1,2)->MergeCells = True;

$xlBook->ActiveSheet->Cells(1,3)->Value = "Used";
$xlBook->ActiveSheet->Cells(1,3)->BORDERS->Weight = 1;
$xlBook->ActiveSheet->Cells(1,3)->Font->Name = "Tahoma";
$xlBook->ActiveSheet->Cells(1,3)->Font->Size = 10;
$xlBook->ActiveSheet->Cells(1,3)->MergeCells = True;

$i = 0;
While($result = mysql_fetch_array($objQuery))
{
$xlBook->ActiveSheet->Cells($intStartRows+$i,1)->Value = $result["Name"];
$xlBook->ActiveSheet->Cells($intStartRows+$i,2)->Value = $result["Budget"];
$xlBook->ActiveSheet->Cells($intStartRows+$i,3)->Value = $result["Used"];
$xlBook->ActiveSheet->Cells($intStartRows+$i,2)->NumberFormat = "$#,##0.00";
$xlBook->ActiveSheet->Cells($intStartRows+$i,3)->NumberFormat = "$#,##0.00";
$i++;
}
//*** End Data Rows ***//

$objRange = $xlBook->Sheets("MyReport")->UsedRange;
$objRange->Select;

$colCharts = $xlApp->Charts;
$colCharts->Add();
$objChart = $colCharts{1};

$xlApp->ActiveChart->Name = "MyChart";

$objChart->ChartType = 92;
$objChart->HasLegend = True;
$objChart->HasTitle = 1;
$objChart->PlotBy = 2;
$objChart->ChartTitle->Text = "Customer Report";
$objChart->ChartTitle->Characters->Text = "Customer Report";
$objChart->ChartTitle->Font->Name = "Tahoma";
$objChart->ChartTitle->Font->FontStyle = "Bold";
$objChart->ChartTitle->Font->Size = 30;
$objChart->ChartTitle->Font->ColorIndex = 3;
$objChart->Activate;

//*** Save Charts ***//
@unlink($strPath."/".$FileName);
$xlApp->ActiveChart->Export($strPath."/".$FileName,$Ext);

//*** Save Excel ***//
@unlink($strPath."/".$XlsName);
$xlBook->SaveAs($strPath."/".$XlsName);
//$xlBook->SaveAs(realpath($XlsName));

$xlApp->Application->Quit;
}
?>
<strong>Charts Created</strong><br><br>
<img src="<?=$FileName?>">

</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_chart_cylinder.php

Screenshot

PHP & Chart/Graph - Cylinder Column Clustered

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.