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