2011-05-23 65 views
0

我試圖在php中繪製高斯圖。我找到了jpgraph庫,但我不知道如何使用$x,$y數據。請有人知道如何聲明軸。謝謝。這是我的代碼:高斯圖與jpgraph

while ($row = pg_fetch_assoc($sql)) 
{ 
    $ydata = array(); 
    $xdata = array(); 
    $ydata[] = abs(($row['grade']-$miu)/$sigma); 
    $xdata[] = 0; 
    for ($i = 0; $i <= 60; $i+=10) // put z value 
    { 
     $xdata[] = 0 + $i; 
     $ydata[] = 0 + $i; 
    }  
    $graph = new Graph(600,400,"auto"); 
    $graph->SetScale("linlin");  
    $lplot = new LinePlot($ydata,$xdata); 
    $lplot->SetColor("blue"); 
    $lplot->SetWeight(2); 
    $graph->Add($lplot); 
    // Add data to X coordinate 
    $graph->xaxis->SetTickLabels($xdata);  
    // Display the graph 
    $graph->Stroke(); 
} 

回答

0

我已經解決了它。

while ($row = pg_fetch_assoc($sql)) 
    {  
     $z[$i] = ($row['grade'] - $miu)/$sigma; // $z => arreglo con notas normalizadas 
     $ordenada[$i] = (1/($sigma*sqrt(pi())))*(exp(-0.5*(($row['grade']-$miu)*($row['grade'] - 57))/(12*12)));      
     $i++; 
    } 
//rest of code 
$p1 = new LinePlot($ordenada); 
$graph->Add($p1);