Learning & Integrating web technology and code help directory

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

No comments
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
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. //*** Connect to MySQL Database ***//  
  8. $objConnect = mysql_connect("localhost","root","root"or die(mysql_error());  
  9. $objDB = mysql_select_db("mydatabase");  
  10. $strSQL = "SELECT * FROM customer";  
  11. $objQuery = mysql_query($strSQL);  
  12. if($objQuery)  
  13. {  
  14. //*** Get Document Path ***//  
  15. $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp  
  16.   
  17. //*** File Name Gif,Jpeg,... ***//  
  18. $FileName = "MyXls/MyChart.Gif";  
  19. $Ext = "Gif";  
  20.   
  21. //*** Excel Name ***//  
  22. $XlsName = "MyXls/MyChart.xls";  
  23.   
  24. //*** Connect to Excel.Application ***//  
  25. $xlApp = new COM("Excel.Application");  
  26. $xlBook = $xlApp->Workbooks->Add();  
  27.   
  28. $intStartRows = 2;  
  29. $intEndRows = mysql_num_rows($objQuery)+($intStartRows-1);  
  30.   
  31. $xlSheet = $xlBook->Worksheets(1);  
  32.   
  33. $xlApp->Application->Visible = False;  
  34.   
  35. //*** Delete Sheet (2,3) - Sheet Default ***//  
  36. $xlBook->Worksheets(2)->Select;  
  37. $xlBook->Worksheets(2)->Delete;  
  38. $xlBook->Worksheets(2)->Select;  
  39. $xlBook->Worksheets(2)->Delete;  
  40.   
  41. //*** Sheet Data Rows ***//  
  42. $xlBook->Worksheets(1)->Name = "MyReport";  
  43. $xlBook->Worksheets(1)->Select;  
  44.   
  45. $xlBook->ActiveSheet->Cells(1,1)->Value = "Customer Name";  
  46. $xlBook->ActiveSheet->Cells(1,1)->Font->Name = "Tahoma";  
  47. $xlBook->ActiveSheet->Cells(1,1)->BORDERS->Weight = 1;  
  48. $xlBook->ActiveSheet->Cells(1,1)->Font->Size = 10;  
  49. $xlBook->ActiveSheet->Cells(1,1)->MergeCells = True;  
  50.   
  51. $xlBook->ActiveSheet->Cells(1,2)->Value = "Budget";  
  52. $xlBook->ActiveSheet->Cells(1,2)->BORDERS->Weight = 1;  
  53. $xlBook->ActiveSheet->Cells(1,2)->Font->Name = "Tahoma";  
  54. $xlBook->ActiveSheet->Cells(1,2)->Font->Size = 10;  
  55. $xlBook->ActiveSheet->Cells(1,2)->MergeCells = True;  
  56.   
  57. $xlBook->ActiveSheet->Cells(1,3)->Value = "Used";  
  58. $xlBook->ActiveSheet->Cells(1,3)->BORDERS->Weight = 1;  
  59. $xlBook->ActiveSheet->Cells(1,3)->Font->Name = "Tahoma";  
  60. $xlBook->ActiveSheet->Cells(1,3)->Font->Size = 10;  
  61. $xlBook->ActiveSheet->Cells(1,3)->MergeCells = True;  
  62.   
  63. $i = 0;  
  64. While($result = mysql_fetch_array($objQuery))  
  65. {  
  66. $xlBook->ActiveSheet->Cells($intStartRows+$i,1)->Value = $result["Name"];  
  67. $xlBook->ActiveSheet->Cells($intStartRows+$i,2)->Value = $result["Budget"];  
  68. $xlBook->ActiveSheet->Cells($intStartRows+$i,3)->Value = $result["Used"];  
  69. $xlBook->ActiveSheet->Cells($intStartRows+$i,2)->NumberFormat = "$#,##0.00";  
  70. $xlBook->ActiveSheet->Cells($intStartRows+$i,3)->NumberFormat = "$#,##0.00";  
  71. $i++;  
  72. }  
  73. //*** End Data Rows ***//  
  74.   
  75. $objRange = $xlBook->Sheets("MyReport")->UsedRange;  
  76. $objRange->Select;  
  77.   
  78. $colCharts = $xlApp->Charts;  
  79. $colCharts->Add();  
  80. $objChart = $colCharts{1};  
  81.   
  82. $xlApp->ActiveChart->Name = "MyChart";  
  83.   
  84. $objChart->ChartType = 92;  
  85. $objChart->HasLegend = True;  
  86. $objChart->HasTitle = 1;  
  87. $objChart->PlotBy = 2;  
  88. $objChart->ChartTitle->Text = "Customer Report";  
  89. $objChart->ChartTitle->Characters->Text = "Customer Report";  
  90. $objChart->ChartTitle->Font->Name = "Tahoma";  
  91. $objChart->ChartTitle->Font->FontStyle = "Bold";  
  92. $objChart->ChartTitle->Font->Size = 30;  
  93. $objChart->ChartTitle->Font->ColorIndex = 3;  
  94. $objChart->Activate;  
  95.   
  96. //*** Save Charts ***//  
  97. @unlink($strPath."/".$FileName);  
  98. $xlApp->ActiveChart->Export($strPath."/".$FileName,$Ext);  
  99.   
  100. //*** Save Excel ***//  
  101. @unlink($strPath."/".$XlsName);  
  102. $xlBook->SaveAs($strPath."/".$XlsName);  
  103. //$xlBook->SaveAs(realpath($XlsName));  
  104.   
  105. $xlApp->Application->Quit;  
  106. }  
  107. ?>  
  108. <strong>Charts Created</strong><br><br>  
  109. <img src="<?=$FileName?>">  
  110.   
  111. </body>  
  112. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP & Chart/Graph - Cylinder Column Clustered

No comments :

Post a Comment