w=$this->roundoff($wd); //to round off the width to integer value $this->h=$this->roundoff($ht); //to round off the height to interger value $this->upper_rnd=$upperrange; //upper range of the graph $this->lower_rnd=$lowerrange; //lower range of the graph $this->im = ImageCreate($this->w,$this->h); //create the source image $this->SetBGColor($colors); //set the background color for image ImageColorTransparent($this->im,$this->graphBGColor); //make image transparent $this->SetAxisCoOrdinates($x_dst,$y_dst); //assign the co-ordinates of the graph $this->FontSize($font); //set font height and width $this->ResizeImage($colors,$x_dst,$y_dst); //resize the source image $this->SetXaxisColor($colors); //set color of X axis $this->SetYaxisColor($colors); //set color of Y axis $this->SetLineColor($colors); //set color of the line graph $this->SetCloseLineColor($colors); //set color of the closing line $this->SetLabelColor($colors); //set color of the labels $this->PrintX_axis(); //print X axis $this->PrintY_axis(); //print Y axis $this->PrintX_axis2(); //print axis parallel to X axis at other end $this->PrintY_axis2(); //print axis parallel to Y axis at other end $this->YFactorMap(); //calculate mapping factor for datas if($this->map_factor!=0) { if($x_interval!=0) { $this->XAxisStep($datas,$x_interval); //calculate the x interval(step) $this->PrintLineGraph($datas,$desc, origin_start); //print the line graph if(isset($closeprice)) { if($datas!=0) $this->PrintCloseLine($closeprice,$x_interval); //print close line } } $this->PrintLabel($font,$y_interval,$dash,$desc); //display the labels $this->PrintYSteps(); //display the intermediate lines parallel to X axis if(isset($horaStart) or isset($horaEnd)) $this->PrintRatio($font,$horaStart,$horaEnd); //display label ratio } } //end of function PrintGraph() function SetBGColor($colors) { $red = $colors[\"bgcolor\"][\"red\"]; $green = $colors[\"bgcolor\"][\"green\"]; $blue = $colors[\"bgcolor\"][\"blue\"]; $this->graphBGColor=ImageColorAllocate($this->im,$red,$green,$blue); } //end of function SetBGColor() function SetResizeColor($colors) { $red = $colors[\"resizecolor\"][\"red\"]; $green = $colors[\"resizecolor\"][\"green\"]; $blue = $colors[\"resizecolor\"][\"blue\"]; $this->graphResizeColor=ImageColorAllocate($this->dst_im,$red,$green,$blue); } //end of function SetBGColor() function SetXaxisColor($colors) { $red = $colors[\"Xaxiscolor\"][\"red\"]; $green = $colors[\"Xaxiscolor\"][\"green\"]; $blue = $colors[\"Xaxiscolor\"][\"blue\"]; $this->graphXaxiscolor=ImageColorAllocate($this->dst_im,$red,$green,$blue); } //end of function SetXaxisColor() function SetYaxisColor($colors) { $red = $colors[\"Yaxiscolor\"][\"red\"]; $green = $colors[\"Yaxiscolor\"][\"green\"]; $blue = $colors[\"Yaxiscolor\"][\"blue\"]; $this->graphYaxiscolor=ImageColorAllocate($this->dst_im,$red,$green,$blue); } //end of function SetYaxisColor() function SetLineColor($colors) { $red = $colors[\"linecolor\"][\"red\"]; $green = $colors[\"linecolor\"][\"green\"]; $blue = $colors[\"linecolor\"][\"blue\"]; $this->graphlinecolor=ImageColorAllocate($this->dst_im,$red,$green,$blue); } //end of function SetLineColor() function SetCloseLineColor($colors) { $red = $colors[\"closecolor\"][\"red\"]; $green = $colors[\"closecolor\"][\"green\"]; $blue = $colors[\"closecolor\"][\"blue\"]; $this->closelinecolor=ImageColorAllocate($this->dst_im,$red,$green,$blue); } //end of function SetLineColor() function SetLabelColor($colors) { $red = $colors[\"labelcolor\"][\"red\"]; $green = $colors[\"labelcolor\"][\"green\"]; $blue = $colors[\"labelcolor\"][\"blue\"]; $this->labeltextcolor=ImageColorAllocate($this->dst_im,$red,$green,$blue); } //end of function SetLineColor() function SetAxisCoOrdinates($x_dst,$y_dst) { $this->dst_x=$x_dst; $this->dst_y=$y_dst; $this->dst_w=$this->w; $this->dst_h=$this->h; $this->src_x=0; $this->src_y=0; $this->src_w=$this->w; $this->src_h=$this->h; $this->origin_x=$x_dst; $this->origin_y=$y_dst+$this->h; $this->x_axis_x=$x_dst+$this->w; $this->x_axis_y=$y_dst+$this->h; $this->y_axis_x=$x_dst; $this->y_axis_y=$y_dst; } //end of function SetAxisCoOrdinates() function FontSize($font) { $this->font_wd=imagefontwidth($font); $this->ft_wd_half=$this->roundoff($this->font_wd/2); $this->font_ht=imagefontheight($font); $this->ft_ht_half=$this->roundoff($this->font_ht/2); } //end of function FontSize() function ResizeImage($colors,$x_dst,$y_dst) { $this->width=$x_dst + $this->w + $this->ft_wd_half; $this->height=$y_dst + $this->h + 2 * $this->font_ht; $this->dst_im=ImageCreate($this->width,$this->height); $this->SetResizeColor($colors); ImageColorTransparent($this->dst_im,$this->graphResizeColor); ImageCopyResized($this->dst_im,$this->im,$this->dst_x,$this->dst_y,$this->src_x,$this->src_y,$this->dst_w,$this->dst_h,$this->src_w,$this->src_h); } //end of function ResizeImage() function PrintX_axis() { imageline($this->dst_im,$this->origin_x,$this->origin_y,$this->x_axis_x,$this->x_axis_y,$this->graphXaxiscolor); } //end of function PrintX_axis() function PrintY_axis() { imageline($this->dst_im,$this->origin_x,$this->origin_y,$this->y_axis_x,$this->y_axis_y,$this->graphYaxiscolor); } //end of function PrintY_axis() function PrintX_axis2() { imageline($this->dst_im,$this->y_axis_x,$this->y_axis_y,$this->x_axis_x,$this->y_axis_y,$this->graphXaxiscolor); } //end of function PrintX_axis() function PrintY_axis2() { imageline($this->dst_im,$this->x_axis_x,$this->x_axis_y,$this->x_axis_x,$this->y_axis_y,$this->graphYaxiscolor); } //end of function PrintY_axis() function XAxisStep($datas,$x_interval) { $this->SizeData=sizeof($datas); $this->x_step=$this->w/$x_interval; } //end of function XAxisStep() function YFactorMap() { $this->y_axis_diff=$this->origin_y - $this->y_axis_y; $this->y_value_diff=$this->upper_rnd - $this->lower_rnd; $this->map_factor=$this->y_value_diff / $this->y_axis_diff; } //end of function YFactorMap() function MapYValue($value,$sequence,$size,$lower_val,$lower_freq,$map) { $j=0; if($sequence==1) { for($i=($size-1);$i>=0;$i--) { $val_diff[$j]=$value[$i] - $lower_val; $freq_diff[$j]=$val_diff[$j] / $map; $freq[$j]=$lower_freq - $freq_diff[$j]; $j++; } } else { for($i=0;$i<$size;$i++) { $val_diff[$j]=$value[$i] - $lower_val; $freq_diff[$j]=$val_diff[$j] / $map; $freq[$j]=$lower_freq - $freq_diff[$j]; $j++; } } return $freq; } //end of function MapYValue() function PrintLineGraph($datas,$desc,$origin_start) { $j=0; $this->y_freq=$this->MapYValue($datas,$desc,$this->SizeData,$this->lower_rnd,$this->origin_y,$this->map_factor); for($i=0;$i<$this->SizeData;$i++) { $this->XAxisValue += $this->x_step; $this->x_freq[$j]=$this->XAxisValue + $this->origin_x; if($i==0) { if($origin_start==1) $initial_y = $this->origin_y; else $initial_y = $this->y_freq[$j]; imageline($this->dst_im,$this->origin_x,$initial_y,$this->x_freq[$j],$this->y_freq[$j],$this->graphlinecolor); } else { imageline($this->dst_im,$this->x_freq[$j-1],$this->y_freq[$j-1],$this->x_freq[$j],$this->y_freq[$j],$this->graphlinecolor); } $j++; } } //end of function PrintLineGraph() function PrintCloseLine($closeprice,$x_interval) { $j=0; $this->close_val_diff = $closeprice - $this->lower_rnd; $this->close_freq_diff = $this->close_val_diff / $this->map_factor; for($i=0;$i<$x_interval;$i++) { $this->XAxisValueClose += $this->x_step; $this->x_frq[$j]=$this->XAxisValueClose + $this->origin_x; $this->y_frq[$j]=$this->origin_y - $this->close_freq_diff; if($i==0) { imageline($this->dst_im,$this->origin_x,$this->y_frq[$j],$this->x_frq[$j],$this->y_frq[$j],$this->closelinecolor); } else { imageline($this->dst_im,$this->x_frq[$j-1],$this->y_frq[$j-1],$this->x_frq[$j],$this->y_frq[$j],$this->closelinecolor); } $j++; } } //end of function PrintCloseLine() function DashPosition() { $this->dash_x=$this->origin_x-$this->font_wd; } //end of function DashPosition() function NumberLength($y_interval) { for($i=0;$i<=$y_interval;$i++) { $this->length=strlen(number_format($this->y_value[$i],2,\".\",\"\")); if($this->length > $this->max_length) $this->max_length=$this->length; } } //end of NumberLength() function LabelPosition($y_interval) { $this->NumberLength($y_interval); $this->x=$this->origin_x-($this->max_length+1)*$this->font_wd; } //end of function LabelPosition() function YLabelPos($desc) { if($desc==1) $seq_label = 0; $this->y_label_pos=$this->MapYValue($this->y_value,$seq_label,$this->y_interval_val,$this->lower_rnd,$this->origin_y,$this->map_factor); for($i=0;$i<$this->y_interval_val;$i++) { $this->y_pos[$i]=$this->y_label_pos[$i] - $this->ft_ht_half; } } //end of function YLabelPos() function PrintLabel($font,$y_interval,$dash,$desc) { $this->y_interval_val=$y_interval+1; $this->y_step=$this->y_value_diff/$y_interval; for($i=0;$i<$this->y_interval_val;$i++) { if($i==0) $this->y_value[$i]=$this->lower_rnd; elseif($i==($y_interval)) $this->y_value[$i]=$this->upper_rnd; else $this->y_value[$i]=$this->y_value[$i-1]+$this->y_step; } $this->DashPosition(); $this->LabelPosition($y_interval); $this->YLabelPos($desc); for($i=0;$i<$this->y_interval_val;$i++) { imagestring($this->dst_im,$font,$this->dash_x,$this->y_pos[$i],$dash,$this->labeltextcolor); imagestring($this->dst_im,$font,$this->x,$this->y_pos[$i],number_format($this->y_value[$i],2,\".\",\"\"),$this->labeltextcolor); } } //end of function PrintLabel() function PrintYSteps() { for($i=1;$i<($this->y_interval_val-1);$i++) { imageline($this->dst_im,$this->y_axis_x,$this->y_label_pos[$i],$this->x_axis_x,$this->y_label_pos[$i],$this->graphXaxiscolor); } } //end of function PrintYSteps() function PrintRatio($font,$horaStart,$horaEnd) { $this->ratio_x = $this->origin_x + $this->w * (20/100); $this->ratio_y = $this->origin_y + $this->ft_ht_half; $this->ratio_label = $horaStart.\"/\".$horaEnd; imagestring($this->dst_im,$font,$this->ratio_x,$this->ratio_y,$this->ratio_label,$this->labeltextcolor); } //end of function PrintRatio() function roundoff($v) { if ($v - floor($v) >= 0.5) { return(ceil($v)); } else { return(floor($v)); } } //end of function roundoff() function DisplayLineGraph() { header(\"Content-Type: image/gif\"); ImagePNG($this->dst_im); } //end of function DisplayLineGraph() } //end of class LineGraph ?>