title: javascript canvasjs Get data points dynamically from file.txt
body: <p>Objective:</p>
  
  <p>I want to get data from file.txt thats is saved local in /var/www/html/file.txt and use it for the doughnut chart on my webpage dynamically on a interval of 2 seconds</p>
  
  <p>file.txt only has one entry and  looks like:</p>
  
  <pre><code>34
  </code></pre>
  
  <p>the javascript i have tried:</p>
  
  <pre><code>$.get("file.txt", function(data) {
  var x = 0;
  var allLines = data.split('\n');
  if(allLines.length &gt; 0) {
      for(var i=0; i&lt; allLines.length; i++) {
          dataPoints.push({y: parseInt(allLines[i])});
          x += .25;
      }
  }
  var chart = new CanvasJS.Chart("chartContainer",{
      title :{
          text: "Chart using Text File Data"
      },
      data: [{
          type: "doughnut",
          dataPoints : dataPoints,
      }]
  });
  chart.render();
  });
  }
  </code></pre>
  
  <p>Entire html looks like</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Chart using txtfile Data&lt;/title&gt;
    &lt;script type="text/javascript" src="http://canvasjs.com/assets/script            /jquery-1.11.1.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="http://canvasjs.com/assets/script/canvasjs.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
   &lt;script type="text/javascript"&gt;
  $.get("graph.txt", function(data) {
  var xVal = 0;
  var allLines = data.split('\n');
  var chart = new CanvasJS.Chart("chartContainer",{
      title :{
          text: "Chart using Text File Data"
      },
      data: [{
          type: "line",
          dataPoints : [function()
          {
          if(allLines.length &gt; 0) {
             for(var i=0; i&lt; allLines.length; i++) {
             xVal +=.25;
             dataPoints.push({x : xVal, y: parseInt(allLines[i])});
      }
  }
  }]
      }]
  });
  chart.render();
  },'text');
  &lt;/script&gt;
  &lt;script type="text/javascript" src="canvasjs.min.js"&gt;&lt;/script&gt;
  &lt;div id="chartContainer" style="height: 300px; width: 100%;"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>