Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is likely with your ajax call:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery-1.7.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var dataSet = [ ['year', 'fixedassets'],['2009', 1],['2010', 1.2],['2011', 1.6]]; var data = google.visualization.arrayToDataTable(dataSet); var options = { title: 'Company Performance' }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="chart_div" style="width: 900px; height: 500px;"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This works, so it's not a problem with any of the existing code. Your format for the ajax call is using a bunch of depreciated jQuery calls, and without access to your server I can't test it, but you could try something like:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { $.get("phpdata.php", function(response_data) { var data = google.visualization.arrayToDataTable([response_data]); var options = { title: 'Company Performance' }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); }); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="chart_div" style="width: 900px; height: 500px;"&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p>and see if that works.</p> <p>I think that the problem you're having is that you have a string: <code>"['year', 'fixedassets'], ['2009', 1], ['2010', 1.2], ['2011', 1.6]"</code> and you want it evaluated as an array: <code>[['year', 'fixedassets'],['2009', 1],['2010', 1.2],['2011', 1.6]]</code>. The easy-but-insecure way to solve this is to use <code>eval()</code>. you'd say:</p> <pre><code>$.get("phpdata.php", function(response_data) { var data = google.visualization.arrayToDataTable(eval('[' + response_data + ']'); </code></pre> <p>This is not-great-but-working as long as you completely control the server, and you're not getting any user input that could be sent from your server.</p> <p>The 'right' way to do this would be to send actual json from your server, instead of sending what you're sending, and then use <code>JSON.parse(response_data)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload