dpylt7626401 2014-06-11 18:52
浏览 31

too long

We want to create a cardiogram graph with Libchart in PHP which takes data from a text file.

Here is our code:

<?php
include "libchart\libchart\classes\libchart.php";    
$file_handle = fopen("arrythmia1.txt","r");    
$i=0;

while (! feof($file_handle)){
    $file=fgets($file_handle);
    $parts= preg_split("[:|;]",$file);
    $x_values[$i]= (float) $parts[1];
    $y_values[$i]=(float) $parts[2];
    $i=$i+1;

    echo $parts[1]."
". $parts[2]."
";
}

$data_length=sizeof($x_values);
$chart=new LineChart();
$dataset=new XYDataset();

for($i=0; $i<data_length; $i++){ 
    $dataset -> addpoint (new Point(".",$y_values[$i]));
}

$chart->getPlot()->setGraphCaptionRatio(0.62);
$chart ->setDataset($dataset);
$chart -> render ("133.png");
?>

And this is the warning :

Notice: Use of undefined constant data_length - assumed 'data_length' in C:\xampp\htdocs\site\uploads\gr.php on line 24

It shows the graph without the print the values.

Here are some values from arrythmia1.txt

0:00.000; -0.145
0:00.003; -0.145
0:00.006; -0.145
0:00.008; -0.145
0:00.011; -0.145
0:00.014; -0.145
0:00.017; -0.145
0:00.019; -0.145
0:00.022; -0.120
0:00.025; -0.135
0:00.028; -0.145
0:00.031; -0.150
0:00.033; -0.160
0:00.036; -0.155
0:00.039; -0.160
0:00.042; -0.175
0:00.044; -0.180
0:00.047; -0.185
0:00.050; -0.170
0:00.053; -0.155
0:00.056; -0.175
0:00.058; -0.180
0:00.061; -0.190
0:00.064; -0.180
0:00.067; -0.155
0:00.069; -0.135
0:00.072; -0.155
0:00.075; -0.190
0:00.078; -0.205
0:00.081; -0.235
0:00.083; -0.225
0:00.086; -0.245
0:00.089; -0.250
0:00.092; -0.260
0:00.094; -0.275
0:00.097; -0.275
0:00.100; -0.275
0:00.103; -0.265
0:00.106; -0.255
0:00.108; -0.265
  • 写回答

1条回答 默认 最新

  • dongmie3987067 2014-06-11 19:00
    关注

    The problem is clearly explained in the error; emphasis mine:

    Notice: Use of undefined constant data_length - assumed 'data_length' in C:\xampp\htdocs\site\uploads\gr.php on line 24

    So look here:

    for($i=0; $i<data_length; $i++){ 
        $dataset -> addpoint (new Point(".",$y_values[$i]));
    }
    

    That data_length is the issue. When you use text like data_length without a $ preceding it in PHP, it thinks the string is a constant. So that is what the error means when it says, Use of undefined constant data_length - assumed 'data_length'.

    To solve the issue data_length should be changed to be the variable $data_length like this:

    for($i=0; $i<$data_length; $i++){ 
        $dataset -> addpoint (new Point(".",$y_values[$i]));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏