如何實現,JPGRAPH組件,用動態的數值產生相應的圖形:例如,我要實現,用內個數據,實現柱形圖,但是數據來源是數據庫,如何實現呢???

解决方案 »

  1.   

    以这为例.只需要构造个一维数组就可以了.
    $datay=array(12,26,9,17,31);
    从数据库里读出数据,将数据传给数组,这个应该很简单吧.include_once ("../jpgraph.php");
    include_once ("../jpgraph_bar.php");$datay=array(12,26,9,17,31);// Create the graph. 
    // One minute timeout for the cached image
    // INLINE_NO means don't stream it back to the browser.
    $graph = new Graph(310,250,'auto');
    $graph->SetScale("textlin");
    $graph->img->SetMargin(60,30,20,40);
    $graph->yaxis->SetTitleMargin(45);
    $graph->yaxis->scale->SetGrace(30);
    $graph->SetShadow();// Turn the ticks
    $graph->xaxis->SetTickSide(SIDE_DOWN);
    $graph->yaxis->SetTickSide(SIDE_LEFT);// Create a bar pot
    $bplot = new BarPlot($datay);// Create targets for the image maps. One for each column
    $targ=array("bar_clsmex1.php#1","bar_clsmex1.php#2","bar_clsmex1.php#3","bar_clsmex1.php#4","bar_clsmex1.php#5","bar_clsmex1.php#6");
    $alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
    $bplot->SetCSIMTargets($targ,$alts);
    $bplot->SetFillColor("orange");// Use a shadow on the bar graphs (just use the default settings)
    $bplot->SetShadow();
    $bplot->value->SetFormat(" $ %2.1f",70);
    $bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
    $bplot->value->SetColor("blue");
    $bplot->value->Show();$graph->Add($bplot);$graph->title->Set("Image maps barex1");
    $graph->xaxis->title->Set("X-title");
    $graph->yaxis->title->Set("Y-title");$graph->title->SetFont(FF_FONT1,FS_BOLD);
    $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);// Send back the HTML page which will call this script again
    // to retrieve the image.
    $graph->StrokeCSIM();