首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数组中的pChart输入

数组中的pChart输入
EN

Stack Overflow用户
提问于 2013-12-08 18:17:46
回答 1查看 623关注 0票数 0

我正在尝试将从文件中提取的数据输入到数组字符串中。但它只读取第一个值。这就是我如何撤回数据集;

代码语言:javascript
复制
$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].',';
    }

例如。回波sugar_1是

58,60,62,48,58,60,62,48,58,62,48,58,60,62,48,58,60,62,48,58,60,62,48,58,60,62,48,58,60,62,48,58,60,

现在我试着把这个输入到

代码语言:javascript
复制
/* 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"); 

但就像我说的,它只读取第一个值,但例如,如果我要在那里添加smth,就像

$MyData->addPoints(array($sugar_1**,44,66**),"Probe 1");,然后,这些附加的价值完美地工作。我不喜欢我的类型来想办法。

EN

回答 1

Stack Overflow用户

发布于 2013-12-10 17:34:52

解决了。

代码语言:javascript
复制
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"); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20457085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档