douci2516 2012-12-22 02:28
浏览 70
已采纳

Jpgraph:数据库数据无法使用php插入条形图

here is my code :

<?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();
?>

here jpgrpah doesn't display..error shows : JpGraph Error: 25067 Your manually specified scale and ticks is not correct. The scale seems to be too small to hold any of the specified tick marks. but I gave direct data for above $datay array.this code is working perfectly..like this

$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;

wht's the wrong with my code ....can't understand....help me...thanxx in advanced...

  • 写回答

1条回答 默认 最新

  • dsmgcse8876 2012-12-22 03:23
    关注

    I think now that i understand you :

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

    should be:

    case "A-":
      $datay['2']=$ors['No_Of_grades'];
      break;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B