2015-05-07 130 views
1

我已經開始使用JPGraph並嘗試了以下簡單的線條繪製示例。我只添加了一個新變量$ xdata來繪製一個xy圖。但是,它不繪製正確的圖(x軸上的值顯示爲1,2,3,4,因此不代表$ xdata中的值)。此外,y值無法正確顯示。如果我繪製的圖表沒有x軸值,即$ p1 = new LinePlot($ datay1);JPGraph:不使用xy數據繪製線

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

     $datay1 = array(20,15,23,15); 
     $datay2 = array(12,9,42,8); 
     $datax = array(0,10,20,30); 

     // Setup the graph 
     $graph = new Graph(300,250); 
     $graph->SetScale("textlin"); 

     $theme_class=new UniversalTheme; 

     $graph->SetTheme($theme_class); 
     $graph->img->SetAntiAliasing(false); 
     $graph->title->Set('Filled Y-grid'); 
     $graph->SetBox(false); 
     $graph->img->SetAntiAliasing(); 
     $graph->yaxis->HideZeroLabel(); 
     $graph->yaxis->HideLine(false); 
     $graph->yaxis->HideTicks(false,false); 

     $graph->xgrid->Show(); 
     $graph->xgrid->SetLineStyle("solid"); 
     $graph->xgrid->SetColor('#E3E3E3'); 

     // Create the first line 
     $p1 = new LinePlot($datay1,$datax); 
     $graph->Add($p1); 
     $p1->SetColor("#6495ED"); 
     $p1->SetLegend('Line 1'); 

     // Create the second line 
     $p2 = new LinePlot($datay2,$datax); 
     $graph->Add($p2); 
     $p2->SetColor("#B22222"); 
     $p2->SetLegend('Line 2'); 

     $graph->legend->SetFrameWeight(1); 
     // Output line 
     $graph->Stroke(); 
     ?> 

回答