rcowen00
asked on
Fatal error: Call to undefined method PDF_MC_Table::BarDiagram()
Hi,
I have a php script that I believe has been extended correctly but I continue to get Fatal error: Call to undefined method PDF_MC_Table::BarDiagram() when calling BarDiagram()? Any suggestions why? Thank you.
Snippet ID=8227228 mc_table.php
Snippet ID=8227229 diag.php
Snippet ID=82272030 sector.php
I have a php script that I believe has been extended correctly but I continue to get Fatal error: Call to undefined method PDF_MC_Table::BarDiagram()
Snippet ID=8227228 mc_table.php
Snippet ID=8227229 diag.php
Snippet ID=82272030 sector.php
<?php
require('diag.php');
class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;
function SetWidths($w)
{
//Set the array of column widths
$this->widths=$w;
}
function SetAligns($a)
{
//Set the array of column alignments
$this->aligns=$a;
}
function Row($data)
{
//Calculate the height of the row
$nb=0;
for($i=0;$i<count($data);$i++)
$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
$h=5*$nb;
//Issue a page break first if needed
$this->CheckPageBreak($h);
//Draw the cells of the row
for($i=0;$i<count($data);$i++)
{
$w=$this->widths[$i];
$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Draw the border
$this->Rect($x,$y,$w,$h);
//Print the text
$this->MultiCell($w,5,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function CheckPageBreak($h)
{
//If the height h would cause an overflow, add a new page immediately
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function NbLines($w,$txt)
{
//Computes the number of lines a MultiCell of width w will take
$cw=&$this->CurrentFont['cw'];
if($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 and $s[$nb-1]=="\n")
$nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
$c=$s[$i];
if($c=="\n")
{
$i++;
$sep=-1;
$j=$i;
$l=0;
$nl++;
continue;
}
if($c==' ')
$sep=$i;
$l+=$cw[$c];
if($l>$wmax)
{
if($sep==-1)
{
if($i==$j)
$i++;
}
else
$i=$sep+1;
$sep=-1;
$j=$i;
$l=0;
$nl++;
}
else
$i++;
}
return $nl;
}
}
?>
<?php
require('sector.php');
class PDF_Diag extends PDF_Sector {
var $legends;
var $wLegend;
var $sum;
var $NbVal;
function PieChart($w, $h, $data, $format, $colors=null)
{
$this->SetFont('Courier', '', 10);
$this->SetLegends($data,$format);
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$hLegend = 5;
$radius = min($w - $margin * 4 - $hLegend - $this->wLegend, $h - $margin * 2);
$radius = floor($radius / 2);
$XDiag = $XPage + $margin + $radius;
$YDiag = $YPage + $margin + $radius;
if($colors == null) {
for($i = 0; $i < $this->NbVal; $i++) {
$gray = $i * intval(255 / $this->NbVal);
$colors[$i] = array($gray,$gray,$gray);
}
}
//Sectors
$this->SetLineWidth(0.2);
$angleStart = 0;
$angleEnd = 0;
$i = 0;
foreach($data as $val) {
$angle = ($val * 360) / doubleval($this->sum);
if ($angle != 0) {
$angleEnd = $angleStart + $angle;
$this->SetFillColor($colors[$i][0],$colors[$i][1],$colors[$i][2]);
$this->Sector($XDiag, $YDiag, $radius, $angleStart, $angleEnd);
$angleStart += $angle;
}
$i++;
}
//Legends
$this->SetFont('Courier', '', 10);
$x1 = $XPage + 2 * $radius + 4 * $margin;
$x2 = $x1 + $hLegend + $margin;
$y1 = $YDiag - $radius + (2 * $radius - $this->NbVal*($hLegend + $margin)) / 2;
for($i=0; $i<$this->NbVal; $i++) {
$this->SetFillColor($colors[$i][0],$colors[$i][1],$colors[$i][2]);
$this->Rect($x1, $y1, $hLegend, $hLegend, 'DF');
$this->SetXY($x2,$y1);
$this->Cell(0,$hLegend,$this->legends[$i]);
$y1+=$hLegend + $margin;
}
}
function BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
{
$this->SetFont('Courier', '', 10);
$this->SetLegends($data,$format);
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$YDiag = $YPage + $margin;
$hDiag = floor($h - $margin * 2);
$XDiag = $XPage + $margin * 2 + $this->wLegend;
$lDiag = floor($w - $margin * 3 - $this->wLegend);
if($color == null)
$color=array(155,155,155);
if ($maxVal == 0) {
$maxVal = max($data);
}
$valIndRepere = ceil($maxVal / $nbDiv);
$maxVal = $valIndRepere * $nbDiv;
$lRepere = floor($lDiag / $nbDiv);
$lDiag = $lRepere * $nbDiv;
$unit = $lDiag / $maxVal;
$hBar = floor($hDiag / ($this->NbVal + 1));
$hDiag = $hBar * ($this->NbVal + 1);
$eBaton = floor($hBar * 80 / 100);
$this->SetLineWidth(0.2);
$this->Rect($XDiag, $YDiag, $lDiag, $hDiag);
$this->SetFont('Courier', '', 10);
$this->SetFillColor($color[0],$color[1],$color[2]);
$i=0;
foreach($data as $val) {
//Bar
$xval = $XDiag;
$lval = (int)($val * $unit);
$yval = $YDiag + ($i + 1) * $hBar - $eBaton / 2;
$hval = $eBaton;
$this->Rect($xval, $yval, $lval, $hval, 'DF');
//Legend
$this->SetXY(0, $yval);
$this->Cell($xval - $margin, $hval, $this->legends[$i],0,0,'R');
$i++;
}
//Scales
for ($i = 0; $i <= $nbDiv; $i++) {
$xpos = $XDiag + $lRepere * $i;
$this->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
$val = $i * $valIndRepere;
$xpos = $XDiag + $lRepere * $i - $this->GetStringWidth($val) / 2;
$ypos = $YDiag + $hDiag - $margin;
$this->Text($xpos, $ypos, $val);
}
}
function SetLegends($data, $format)
{
$this->legends=array();
$this->wLegend=0;
$this->sum=array_sum($data);
$this->NbVal=count($data);
foreach($data as $l=>$val)
{
$p=sprintf('%.2f',$val/$this->sum*100).'%';
$legend=str_replace(array('%l','%v','%p'),array($l,$val,$p),$format);
$this->legends[]=$legend;
$this->wLegend=max($this->GetStringWidth($legend),$this->wLegend);
}
}
}
?>
<?php
require('fpdf.php');
class PDF_Sector extends FPDF
{
function Sector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90)
{
$d0 = $a - $b;
if($cw){
$d = $b;
$b = $o - $a;
$a = $o - $d;
}else{
$b += $o;
$a += $o;
}
while($a<0)
$a += 360;
while($a>360)
$a -= 360;
while($b<0)
$b += 360;
while($b>360)
$b -= 360;
if ($a > $b)
$b += 360;
$b = $b/360*2*M_PI;
$a = $a/360*2*M_PI;
$d = $b - $a;
if ($d == 0 && $d0 != 0)
$d = 2*M_PI;
$k = $this->k;
$hp = $this->h;
if (sin($d/2))
$MyArc = 4/3*(1-cos($d/2))/sin($d/2)*$r;
else
$MyArc = 0;
//first put the center
$this->_out(sprintf('%.2F %.2F m',($xc)*$k,($hp-$yc)*$k));
//put the first point
$this->_out(sprintf('%.2F %.2F l',($xc+$r*cos($a))*$k,(($hp-($yc-$r*sin($a)))*$k)));
//draw the arc
if ($d < M_PI/2){
$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
$xc+$r*cos($b),
$yc-$r*sin($b)
);
}else{
$b = $a + $d/4;
$MyArc = 4/3*(1-cos($d/8))/sin($d/8)*$r;
$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
$xc+$r*cos($b),
$yc-$r*sin($b)
);
$a = $b;
$b = $a + $d/4;
$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
$xc+$r*cos($b),
$yc-$r*sin($b)
);
$a = $b;
$b = $a + $d/4;
$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
$xc+$r*cos($b),
$yc-$r*sin($b)
);
$a = $b;
$b = $a + $d/4;
$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
$xc+$r*cos($b),
$yc-$r*sin($b)
);
}
//terminate drawing
if($style=='F')
$op='f';
elseif($style=='FD' || $style=='DF')
$op='b';
else
$op='s';
$this->_out($op);
}
function _Arc($x1, $y1, $x2, $y2, $x3, $y3 )
{
$h = $this->h;
$this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c',
$x1*$this->k,
($h-$y1)*$this->k,
$x2*$this->k,
($h-$y2)*$this->k,
$x3*$this->k,
($h-$y3)*$this->k));
}
}
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get
Warning: Missing argument 1 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/re ports/rMgm tSummary_A llFindings ByCat.php on line 71 and defined in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/fp df/diag.ph p on line 60
Warning: Missing argument 2 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/re ports/rMgm tSummary_A llFindings ByCat.php on line 71 and defined in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/fp df/diag.ph p on line 60
Warning: Missing argument 3 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/re ports/rMgm tSummary_A llFindings ByCat.php on line 71 and defined in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/fp df/diag.ph p on line 60
Warning: Missing argument 4 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/re ports/rMgm tSummary_A llFindings ByCat.php on line 71 and defined in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/fp df/diag.ph p on line 60
Fatal error: Using $this when not in object context in /home/loanmod1/domains/erm qc.com/pri vate_html/ include/fp df/diag.ph p on line 62
Warning: Missing argument 1 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm
Warning: Missing argument 2 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm
Warning: Missing argument 3 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm
Warning: Missing argument 4 for PDF_Diag::BarDiagram(), called in /home/loanmod1/domains/erm
Fatal error: Using $this when not in object context in /home/loanmod1/domains/erm
you need to pass the arguments which BarDiagram() takes also can you attach diag.php here
ASKER
kshna,
How do I pass the arguments?
How do I pass the arguments?
<?php
require('sector.php');
class PDF_Diag extends PDF_Sector {
var $legends;
var $wLegend;
var $sum;
var $NbVal;
function PieChart($w, $h, $data, $format, $colors=null)
{
$this->SetFont('Courier', '', 10);
$this->SetLegends($data,$format);
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$hLegend = 5;
$radius = min($w - $margin * 4 - $hLegend - $this->wLegend, $h - $margin * 2);
$radius = floor($radius / 2);
$XDiag = $XPage + $margin + $radius;
$YDiag = $YPage + $margin + $radius;
if($colors == null) {
for($i = 0; $i < $this->NbVal; $i++) {
$gray = $i * intval(255 / $this->NbVal);
$colors[$i] = array($gray,$gray,$gray);
}
}
//Sectors
$this->SetLineWidth(0.2);
$angleStart = 0;
$angleEnd = 0;
$i = 0;
foreach($data as $val) {
$angle = ($val * 360) / doubleval($this->sum);
if ($angle != 0) {
$angleEnd = $angleStart + $angle;
$this->SetFillColor($colors[$i][0],$colors[$i][1],$colors[$i][2]);
$this->Sector($XDiag, $YDiag, $radius, $angleStart, $angleEnd);
$angleStart += $angle;
}
$i++;
}
//Legends
$this->SetFont('Courier', '', 10);
$x1 = $XPage + 2 * $radius + 4 * $margin;
$x2 = $x1 + $hLegend + $margin;
$y1 = $YDiag - $radius + (2 * $radius - $this->NbVal*($hLegend + $margin)) / 2;
for($i=0; $i<$this->NbVal; $i++) {
$this->SetFillColor($colors[$i][0],$colors[$i][1],$colors[$i][2]);
$this->Rect($x1, $y1, $hLegend, $hLegend, 'DF');
$this->SetXY($x2,$y1);
$this->Cell(0,$hLegend,$this->legends[$i]);
$y1+=$hLegend + $margin;
}
}
function BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
{
$this->SetFont('Courier', '', 10);
$this->SetLegends($data,$format);
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$YDiag = $YPage + $margin;
$hDiag = floor($h - $margin * 2);
$XDiag = $XPage + $margin * 2 + $this->wLegend;
$lDiag = floor($w - $margin * 3 - $this->wLegend);
if($color == null)
$color=array(155,155,155);
if ($maxVal == 0) {
$maxVal = max($data);
}
$valIndRepere = ceil($maxVal / $nbDiv);
$maxVal = $valIndRepere * $nbDiv;
$lRepere = floor($lDiag / $nbDiv);
$lDiag = $lRepere * $nbDiv;
$unit = $lDiag / $maxVal;
$hBar = floor($hDiag / ($this->NbVal + 1));
$hDiag = $hBar * ($this->NbVal + 1);
$eBaton = floor($hBar * 80 / 100);
$this->SetLineWidth(0.2);
$this->Rect($XDiag, $YDiag, $lDiag, $hDiag);
$this->SetFont('Courier', '', 10);
$this->SetFillColor($color[0],$color[1],$color[2]);
$i=0;
foreach($data as $val) {
//Bar
$xval = $XDiag;
$lval = (int)($val * $unit);
$yval = $YDiag + ($i + 1) * $hBar - $eBaton / 2;
$hval = $eBaton;
$this->Rect($xval, $yval, $lval, $hval, 'DF');
//Legend
$this->SetXY(0, $yval);
$this->Cell($xval - $margin, $hval, $this->legends[$i],0,0,'R');
$i++;
}
//Scales
for ($i = 0; $i <= $nbDiv; $i++) {
$xpos = $XDiag + $lRepere * $i;
$this->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
$val = $i * $valIndRepere;
$xpos = $XDiag + $lRepere * $i - $this->GetStringWidth($val) / 2;
$ypos = $YDiag + $hDiag - $margin;
$this->Text($xpos, $ypos, $val);
}
}
function SetLegends($data, $format)
{
$this->legends=array();
$this->wLegend=0;
$this->sum=array_sum($data);
$this->NbVal=count($data);
foreach($data as $l=>$val)
{
$p=sprintf('%.2f',$val/$this->sum*100).'%';
$legend=str_replace(array('%l','%v','%p'),array($l,$val,$p),$format);
$this->legends[]=$legend;
$this->wLegend=max($this->GetStringWidth($legend),$this->wLegend);
}
}
}
?>
when I say pass the arguments ... what I mean is when calling the function pass the values....
here $w,$h etc. must have some values ...
say $w = 200;$h=200;.....and then call like this...
PDF_Diag::BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
here $w,$h etc. must have some values ...
say $w = 200;$h=200;.....and then call like this...
PDF_Diag::BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
ASKER
kshna,
Thank you for your help. The problem turned out to be a silly mistake on my end. The main report should have been
$pdf = new PDF_Diag();
vs.
$pdf = new PDF_MC_Table();
Thank you for your help. The problem turned out to be a silly mistake on my end. The main report should have been
$pdf = new PDF_Diag();
vs.
$pdf = new PDF_MC_Table();
it's different with php versions.
I thinks you should define new class to a variable and then call variable.
i.e: $variable_name = new class_name();
and of it's occur again test following ways:
Read this article -> http://php.net/manual/en/language.oop5.php