[ class tree: phpchartPlus ] [ index: phpchartPlus ] [ all elements ]

Source for file PieChart.php

Documentation is available at PieChart.php

  1. <?php
  2.  
  3. /*
  4. **************************************************
  5. Class: PieChart.php
  6. **************************************************
  7. Author: Tsiavos Chris <jaames@freemail.gr>
  8. Date: October 2004
  9. **************************************************/
  10.  
  11. /**
  12. *Includes the Rectangle class
  13. */
  14. require_once("Circle.php");
  15.  
  16. /**
  17. *Includes the chart base class
  18. */
  19. require_once("Chart.php");
  20.  
  21. /**
  22. *PieChart generation
  23. */
  24. class PieChart extends Chart {
  25.  
  26. protected function draw_Grids() { return; }
  27. protected function draw() {
  28. $ItemNames=$this->DataParser_->get_GroupItemsName();
  29. $ItemColors=$this->ConfigParser_->get_LegendColors();
  30. $GroupNames=$this->DataParser_->get_GroupsName();
  31. $ChartData=array();
  32. $Pie=array();
  33. $ShadePie=array();
  34. $PieNum=$this->DataParser_->get_GroupsNum();
  35. $PieArea=$this->Area_xsize-2*5-(3*($PieNum-1));
  36. $PieWidth=$PieArea/$PieNum;
  37. if ($PieWidth>$this->Area_ysize)
  38. {
  39. $PieHeight=$this->Area_ysize-5;
  40. $PieWidth=$PieHeight;
  41. }
  42. else
  43. $PieHeight=$PieWidth;
  44. $PieCenterYPos=$this->ConfigParser_->get_ChartVmargin()+$this->Area_ysize/2;
  45. $PieUseAntialias=$this->ConfigParser_->get_ChartUseAntialias();
  46. for ($group=0;$group<$this->DataParser_->get_GroupsNum();$group++) {
  47. $CenterXPos=$this->ConfigParser_->get_ChartHmargin()+5+(3*$group)+$PieWidth*$group+($PieWidth/2);
  48. $FontColor=$this->ConfigParser_->get_FontColor();
  49. $FontMetrics=$this->Font_->get_FontMetrics($GroupNames[$group]);
  50. $GroupName_YPos=$this->ConfigParser_->get_ChartVmargin()+$this->Area_ysize+2;
  51. $GroupName_XPos=$CenterXPos-($FontMetrics["FontWidth"]/2);
  52. $this->Font_->draw_String($GroupName_XPos,$GroupName_YPos,$GroupNames[$group],$FontColor);
  53. $Pie[$group]=new Circle($this->Chart_Image,$this->ColorAllocator_,$PieUseAntialias,$CenterXPos,$PieCenterYPos,$PieWidth,$PieHeight);
  54. }
  55. for ($item=0;$item<$this->DataParser_->get_GroupItemsNum();$item++) {
  56. $ChartData=$this->DataParser_->get_ItemFromGroups($ItemNames[$item]);
  57. for ($group=0;$group<$this->DataParser_->get_GroupsNum();$group++) {
  58. $ChunkColor=explode(",",$ItemColors[$item]);
  59. $ChunkValue=(100*$ChartData[$group])/$this->ConfigParser_->get_GridMaxValue();
  60. $ChunkAngle=360*($ChunkValue/100);
  61. $Chunk=new Chunk();
  62. $Chunk->set_Angle($ChunkAngle);
  63. $Chunk->set_Color($ChunkColor[0],$ChunkColor[1]);
  64. $Chunk->set_Caption($this->Font_,$ChunkValue." %",$this->ConfigParser_->get_GridColor());
  65. $Pie[$group]->addChunk($Chunk);
  66. }
  67. }
  68. for ($group=0;$group<$this->DataParser_->get_GroupsNum();$group++) {
  69. $Pie[$group]->draw_Filled();
  70. $Pie[$group]->draw($this->ConfigParser_->get_GridColor());
  71. }
  72. }
  73.  
  74. }
  75.  
  76. ?>

Documentation generated on Sun, 3 Oct 2004 14:59:27 +0300 by phpDocumentor 1.3.0RC3