2014-10-10 59 views
0

我已经使用phpGraphlib成功创建了一个线图。但我不知道如何使用这个库来绘制多线图。这里x-y值存储在数组中。我的代码在这里如何使用phpGraphlib绘制多线图

<?php 
    include("phpgraphlib.php"); 
    $graph=new PHPGraphLib(1000,1000); 
    include("db_connect.php"); 
    $dataArray=array(); 
    $graph_array=array(); 
    $sql="SELECT name,mark1,mark2, entered_time FROM student "; 
    $result = mysql_query($sql,$con) ; 
    if ($result) { 
    while ($row = mysql_fetch_assoc($result)) { 

    $without_comma_value=explode(',', $row['mark1']); 
    $count=count($without_comma_value); 

    for($i=0;$i<$count;$i++) 
    { 
    $Val_onebyone= $without_comma_value[$i]; 
    $num=$i+1; 
    $dataArray[$num]=$Val_onebyone; 
    } 

    } 
    } 

    $graph->setBackgroundColor("#F78181"); 
    $graph->addData($graph_array); 
    $graph->setBars(false); 
    $graph->setLine(true); 
    $graph->setupYAxis(20, 'black'); 
    $graph->setupXAxis(20, 'black'); 
    $graph->setTextColor('black'); 
    $graph->setDataPoints(true); 
    $graph->setDataPointColor('maroon'); 
    $graph->setLineColor('maroon'); 
    $graph->createGraph(); 
    ?> 

它绘制了一个带有mark1值的图。我也想显示mark2值。怎么可能?

回答

2

喜欢这张

include('phpgraphlib.php'); 
$graph = new PHPGraphLib(650,200); 
$dataX = range(1, 15); 
$dataY1 = array(); 
$dataY2 = array(); 
foreach($dataX as $x => $y) 
{ 
    $dataY1[$x] = rand(-10, 10); 
    $dataY2[$x] = rand(-10, 10);  
} 
$graph->addData($dataY1, $dataY2); 
$graph->setDataPointColor('red'); 
$graph->setLineColor('red', 'blue'); 
$graph->setBars(false); 
$graph->setLine(true); 
$graph->setDataPoints(true); 
$graph->createGraph(); 

结果(线的颜色可以是不同的,但数据点的颜色保持不变) enter image description here