2013-12-08 3 views
0

파일에서 데이터를 가져 와서 얻은 배열 문자열을 입력하려고합니다. 그러나 첫 번째 값만 읽습니다. 이것은 내가 데이터를 수집하는 방법입니다;배열의 pChart 입력

$file = explode(" ", file_get_contents("data/data-02")); 
foreach ($file as $content) 
    { 
     $result[] = array_filter(array_map("trim", explode(" ", $content))); 
    } 
//var_dump($result); 
//echo $result[0][1]; 
    $time = ''; 
    for ($id = 1; $id < 20; $id+= 6) 
    { 
     $time .= '"'.$result[0][$id].'"'.','; 
    } 
    $sugar_1 = ''; 
    for ($id = 2; $id <20; $id+=6) 
    { 
     $sugar_1 .= $result[0][$id].','; 
    } 
    $sugar_2 = ''; 
    for ($id = 5; $id <20; $id+=6) 
    { 
     $sugar_2 .= $result[0][$id].','; 
    } 

ex. 에코는 sugar_1

이다 58,6062485860624858624858606248586062485860 , 62,48,58,606248586062485860,

지금은 내가

/* pChart library inclusions */ 
include("pChart/class/pData.class.php"); 
include("pChart/class/pDraw.class.php"); 
include("pChart/class/pImage.class.php"); 

/* Create and populate the pData object */ 
$MyData = new pData(); 
$MyData->addPoints(array($sugar_1),"Probe 1"); 
$MyData->addPoints(array($sugar_2),"Probe 2"); 
$MyData->setSerieTicks("Probe 2",4); 
$MyData->setAxisName(0,"Sugar level in blood"); 
$MyData->addPoints(array($time),"Labels"); 
$MyData->setSerieDescription("Labels","Hours"); 
$MyData->setAbscissa("Labels"); 

하지만 등으로 입력이에 노력하고있어 내가 말했듯이, 그것은 첫 번째 가치만을 읽는 것입니다. 그러나 예를 들어 거기에 똑같은 것을 더하면 다음과 같습니다.

$MyData->addPoints(array($sugar_1**,44,66**),"Probe 1"); 완벽하게 작동합니다. 나는 그것을 알아 내기 위해 내 타입에서 벗어났다.

답변

0

해결되었습니다.

header("Content-type:text/plain"); 
$file = fopen("data/data-02", "r"); 

$result = array(); 
$file = explode(" ", file_get_contents("data/data-02")); 
foreach ($file as $content) 
    { 
     $result[] = array_filter(array_map("trim", explode(" ", $content))); 
    } 
//var_dump($result); 
//echo $result[0][1]; 
$time = array(); 
$k=0; 
    for ($id = 1; $id < 31; $id+= 6) 
    { 
     $time[$k] = '"'.$result[0][$id].'"'.','; 
     $k++; 
    } 
    $sugar_1 = array(); 
    $k=0; 
    for ($id = 2; $id <30; $id+=6) 
    { 
     $sugar_1[$k] = $result[0][$id].','; 
     $k ++; 
    } 
    $sugar_2 = array(); 
    $k=0; 
    for ($id = 5; $id <33; $id+=6) 
    { 
     $sugar_2[$k] = $result[0][$id].','; 
     $k++; 
    } 

/* pChart library inclusions */ 
include("pChart/class/pData.class.php"); 
include("pChart/class/pDraw.class.php"); 
include("pChart/class/pImage.class.php"); 

/* Create and populate the pData object */ 
$MyData = new pData(); 
$MyData->addPoints($sugar_1,"Probe 1"); 
$MyData->addPoints($sugar_2,"Probe 2"); 
$MyData->setSerieTicks("Probe 2",4); 
$MyData->setAxisName(0,"Sugar level in blood"); 
$MyData->addPoints($time,"Labels"); 
$MyData->setSerieDescription("Labels","Hours"); 
$MyData->setAbscissa("Labels");