2012-12-22 39 views
1

此數據庫中的數據不能插入到條形圖是我的代碼:jpgraph的:使用PHP

<?php 
// content="text/plain; charset=utf-8" 
require_once ('jpgraph/jpgraph.php'); 
require_once ('jpgraph/jpgraph_bar.php'); 
include("mysql _connect .php"); 

$code="CSC1113"; 
$ac_yr="2010/2011"; 
$sql = "SELECT results, COUNT(*) 'No_Of_grades' FROM std_results WHERE code='$code' && ac_year='$ac_yr' GROUP BY results ORDER BY results ASC"; 
    $result = mysql_query($sql) or die(mysql_error()); 
    while($ors = mysql_fetch_array($result)) { 
    $grd=$ors['results']; 
    switch ($grd) 
{ 
case "A": 
    $datay[1]=$ors['No_Of_grades']; 
    break; 
case "A+": 
    $datay[0]=$ors['No_Of_grades']; 
    break; 
case "A-": 
    $datay=$ors['No_Of_grades']; 
    break; 
    case "B": 
    $datay[4]=$ors['No_Of_grades']; 
    break; 
    case "B+": 
    $datay[3]=$ors['No_Of_grades']; 
    break; 
    case "B-": 
    $datay[5]=$ors['No_Of_grades']; 
    break; 
case "C": 
    $datay[7]=$ors['No_Of_grades']; 
    break; 
    case "C+": 
    $datay[6]=$ors['No_Of_grades']; 
    break; 
    case "C-": 
    $datay[8]=$ors['No_Of_grades']; 
    break; 
    case "D": 
    $datay[10]=$ors['No_Of_grades']; 
    break; 
    case "D+": 
    $datay[9]=$ors['No_Of_grades']; 
    break; 
    case "E": 
    $datay[11]=$ors['No_Of_grades']; 
    break; 
    case "AB": 
    $datay[12]=$ors['No_Of_grades']; 
    break; 
    case "NE": 
    $datay[13]=$ors['No_Of_grades']; 
    break; 
default: 
    $datay[14]=$ors['No_Of_grades']; 
} 

    } 

    //set vlaue zero for othe grades.. 
    for($i=0;$i<15;$i++){ 
     if(!isset($datay[$i])){ 
      $datay[$i]=0; 
      } 

     } 


// Create the graph. These two calls are always required 
$graph = new Graph(550,320,'auto'); 
$graph->SetScale("textlin"); 

//$theme_class="DefaultTheme"; 
//$graph->SetTheme(new $theme_class()); 

// set major and minor tick positions manually 
$graph->yaxis->SetTickPositions(array(0,4,8,12,16,20), array(2,6,10,14,18)); 
$graph->SetBox(false); 

//$graph->ygrid->SetColor('gray'); 
$graph->ygrid->SetFill(false); 
$graph->xaxis->SetTickLabels(array('A+','A','A-','B+','B','B-','C+','C','C-','D+','D','E','AB','NE','MC')); 
$graph->yaxis->HideLine(false); 
$graph->yaxis->HideTicks(false,false); 

// Create the bar plots 
$b1plot = new BarPlot($datay); 

// ...and add it to the graPH 
$graph->Add($b1plot); 


$b1plot->SetColor("white"); 
$b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION); 
$b1plot->SetWidth(25); 
$graph->title->Set("Bar Gradient(Left reflection)"); 

// Display the graph 
$graph->Stroke(); 
?> 

這裏jpgrpah不display..error顯示:jpgraph的錯誤:25067你手動指定的規模和蜱不正確。規模似乎太小,不能容納任何指定的刻度線。 但我給上面$ DATAY array.this代碼直接數據正在perfectly..like這個

$datay[0]=2; 
$datay[1]=5; 
$datay[2]=1; 
$datay[3]=2; 
$datay[4]=0; 
$datay[5]=0; 
$datay[6]=3; 
$datay[7]=0; 
$datay[8]=3; 
$datay[9]=0; 
$datay[10]=1; 
$datay[11]=1; 
$datay[12]=0; 
$datay[13]=1; 
$datay[14]=1; 

西隧是錯我的代碼....無法理解....幫助我。 ..thanxx先進...

+0

這裏是我的桌子:http://i.imgur.com/qcTQL.png – Robinson

+0

這是什麼:'No_Of_grades'? –

+0

一個列名我從上面的sql查詢得到...看到這個imgage:http://i.imgur.com/YjJbr.png – Robinson

回答

0

我覺得現在我明白你:

case "A-": 
    $datay=$ors['No_Of_grades']; 
    break; 

應該是:

case "A-": 
    $datay['2']=$ors['No_Of_grades']; 
    break; 
+0

thxx frnd ....你明白了...... – Robinson

+0

歡迎你! –