Home forums Using CanvasJS How can I plot values from .txt file ? Reply To: How can I plot values from .txt file ?

#6773

hitmanbaby2007
Participant

Why it doesn’t work ?

<!DOCTYPE html>

<?PHP

$file_handle = fopen("testgraph.txt", "r");

while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);
$parts = explode(' ', $line_of_text);

//print $parts[0]. "<BR>";
// $parts[0]. $parts[1].
}

fclose($file_handle);

?>

<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generating DataPoints in a loop - jsFiddle demo by anjalij</title>
  
  <script type='text/javascript' src='/js/lib/dummy.js'></script>
  
  
  
  
  <link rel="stylesheet" type="text/css" href="/css/result-light.css">
  
  <style type='text/css'>
    
  </style>
  

<script type='text/javascript'>//<![CDATA[ 
window.onload=function(){
    var limit = 100;    //increase number of dataPoints by increasing this
    var y = 0;
    var x=0;
    var data = []; var dataSeries = { type: "line" };
    var dataPoints = [];
    for (var i = 0; i < limit; i += 1) {
      y = <?php echo $parts[i] ?>;
      dataPoints.push({
          x: i,
          y: y                
      });
      x+= 0.25;       
    }

    dataSeries.dataPoints = dataPoints;
    data.push(dataSeries);
      

  var chart = new CanvasJS.Chart("chartContainer",
    {
      zoomEnabled: true,
      title:{
        text: "Generating DataPoints in a loop" 
      },
      axisX:{
        //minimum: 0, 
        //maximum: 300 ,
        valueFormatString:"0.00"     
      },
      data: data,
   });
  chart.render();

}//]]>  

</script>

</head>
<body>
  <script type="text/javascript" src="http://canvasjs.com/assets/script/canvasjs.min.js"></script> 
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
  
</body>

</html>

My .txt file is here :
http://ladykillernicky.uni.me/testgraph.txt