Note that there are some explanatory texts on larger screens.

plurals
  1. POGooglecharts arraytodatatable possible dimension issue?
    text
    copied!<p>I have a 2 arrays which I got from php, put into a single 2D Javascript array. I'm trying to use it to autofill a Google Chart DataTable, but so far I've had no success. The only thing that I can think of is that maybe the array ix MxN dimension, while the function needs a NxM array?</p> <p>Either does it not work because the first array is made of numbers?</p> <pre><code> &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Pressure Monitor&lt;/title&gt; &lt;script type="text/javascript"&gt; var samptable = new Array(); samptable[0] = new Array(2); samptable[0,0]= nbsamples; //first array obtained from php samptable[0,1]= samples; //second array obtained from php. both are merged into a 2d array &lt;/script&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: ['corechart']}); &lt;/script&gt; &lt;script type="text/javascript"&gt; //var data; function drawVisualization() { var data = google.visualization.arrayToDataTable(samptable[0]); // Create and draw the visualization. new google.visualization.LineChart(document.getElementById('visualization')). draw(data, {curveType: "function", width: 500, height: 400, vAxis: {maxValue: 10}} ); } //function draw(){ //} google.setOnLoadCallback(drawVisualization); &lt;/script&gt; &lt;/head&gt; &lt;body style="font-family: Arial;border: 0 none;"&gt; &lt;div id="visualization" style="width: 800px; height: 400px;"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The code used to get nbsamples and samples:</p> <pre><code>echo '&lt;script type="text/javascript"&gt;'; echo 'var samples = new Array("', join($ydata,'","'), '");'; echo 'var nbsamples = new Array("', join($nbsamples,'","'), '");'; echo '&lt;/script&gt;'; </code></pre>
 

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