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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度