Learning & Integrating web technology and code help directory

How to use PHP & Chart/Graph - Exploded pie 3D

No comments
How to use PHP & Chart/Graph - Exploded pie 3D This learn / tutorial php programming how to using  PHP Create Chart/Graph - Exploded pie 3D
ShotDev Focus:
- PHP  & Create Chart/Graph - Exploded pie 3D
Example
php_chart_pie3d.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 = 3;  
  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 = "My Customer";  
  46. $xlBook->ActiveSheet->Cells(1,1)->Font->Bold = True;  
  47. $xlBook->ActiveSheet->Cells(1,1)->Font->Name = "Tahoma";  
  48. $xlBook->ActiveSheet->Cells(1,1)->Font->Size = 16;  
  49.   
  50. $xlBook->ActiveSheet->Cells(2,1)->Value = "Customer Name";  
  51. $xlBook->ActiveSheet->Cells(2,1)->Font->Name = "Tahoma";  
  52. $xlBook->ActiveSheet->Cells(2,1)->BORDERS->Weight = 1;  
  53. $xlBook->ActiveSheet->Cells(2,1)->Font->Size = 10;  
  54. $xlBook->ActiveSheet->Cells(2,1)->MergeCells = True;  
  55.   
  56. $xlBook->ActiveSheet->Cells(2,2)->Value = "Used";  
  57. $xlBook->ActiveSheet->Cells(2,2)->BORDERS->Weight = 1;  
  58. $xlBook->ActiveSheet->Cells(2,2)->Font->Name = "Tahoma";  
  59. $xlBook->ActiveSheet->Cells(2,2)->Font->Size = 10;  
  60. $xlBook->ActiveSheet->Cells(2,2)->MergeCells = True;  
  61.   
  62. $i = 0;  
  63. While($result = mysql_fetch_array($objQuery))  
  64. {  
  65. $xlBook->ActiveSheet->Cells($intStartRows+$i,1)->Value = $result["Name"];  
  66. $xlBook->ActiveSheet->Cells($intStartRows+$i,2)->Value = $result["Used"];  
  67. $xlBook->ActiveSheet->Cells($intStartRows+$i,2)->NumberFormat = "$#,##0.00";  
  68. $i++;  
  69. }  
  70. //*** End Data Rows ***//  
  71.   
  72. //*** Creating Chart ***//  
  73. $xlBook->Charts->Add;  
  74.   
  75. $xlBook->ActiveChart->ChartType = 70;  
  76.   
  77. $xlBook->ActiveChart->SetSourceData ($xlBook->Sheets("MyReport")->Range("A".$intStartRows.":B".$intEndRows.""));  
  78.   
  79. //*** Set Localtion Sheet ***//  
  80. $xlBook->ActiveChart->Location(2,"MyReport");  
  81.   
  82. //*** Sheet Properties ***//  
  83. $xlBook->ActiveChart->PlotBy = 2;  
  84. $xlBook->ActiveChart->HasTitle = True;  
  85. $xlBook->ActiveChart->ChartTitle->Characters->Text = "My Chart";  
  86.   
  87. //*** Location  ***//  
  88. $xlBook->ActiveSheet->Shapes("Chart 1")->IncrementLeft(20);  
  89. $xlBook->ActiveSheet->Shapes("Chart 1")->IncrementTop(-97.5);  
  90.   
  91. //'*** Set Height & Width ***'  
  92. $xlBook->ActiveSheet->Shapes("Chart 1")->ScaleHeight(1.0, 0,0);  
  93. $xlBook->ActiveSheet->Shapes("Chart 1")->ScaleWidth(1.0, 0,0);  
  94.   
  95. //*** Save Charts ***//  
  96. @unlink($strPath."/".$FileName);  
  97. $xlApp->ActiveChart->Export($strPath."/".$FileName,$Ext);  
  98.   
  99. //*** Save Excel ***//  
  100. @unlink($strPath."/".$XlsName);  
  101. $xlBook->SaveAs($strPath."/".$XlsName);  
  102. //$xlBook->SaveAs(realpath($XlsName));  
  103.   
  104. $xlApp->Application->Quit;  
  105. }  
  106. ?>  
  107. <strong>Charts Created</strong><br><br>  
  108. <img src="<?=$FileName?>">  
  109. </body>  
  110. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP & Chart/Graph - Exploded pie 3D
.

No comments :

Post a Comment