How to parse PHP variables in Google annotated timeline graph?
<p>I want to generate a Google annotated timeline graph with variables from an PHP array, but always got a "undefined variable" error. </p>

<pre><code>&lt;?php

$years = array(1991, 1992, 1993, 1994);
$graphs = array(20, 30, 40, 50);

echo&lt;&lt;&lt;_END

&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script type='text/javascript' src='http://www.google.com/jsapi'&gt;
&lt;/script&gt;
&lt;script type='text/javascript'&gt;

      google.load('visualization', '1', {'packages':['annotatedtimeline']});

      google.setOnLoadCallback(drawChart);

      function drawChart() {

        var data = new google.visualization.DataTable();

        data.addColumn('date', 'Date');

        data.addColumn('number', 'Data');   

        data.addRows([

    &lt;?php

    for ($i=0; $i&lt;=3; $i++){

    echo "[new Date(" . $years[$i] . ", 1, 1), " . $graphs[$i] . "],";

    /* output 

    [new Date(1991, 1, 1), 20],

    [new Date(1992, 1, 1), 30],

    etc..

    */

    }

    ?&gt;    

        ]);

        var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div1'));

        chart.draw(data, {displayAnnotations: true});

      }

&lt;/script&gt; 
&lt;/head&gt;
&lt;body&gt;

&lt;div id='chart_div1' style='width: 700px; height: 240px;'&gt;
&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
_END;

?&gt;
</code></pre>
