Your "for" loop is broken.  You probably want something like this:

for (j = 0; j < 5; j++) {                         //  with for (j = 0; j = 
5; j++) {}, j always equals 5
     for (k = 0; k < 4; k++) {                 //  k < 3 doesn't give fill 
every cell in the row
          data.setValue(j, k, <value>);
     }
}

If you want to use the same data multiple times, there several ways to do 
so:

1) use the data to build different charts in the same function:

function drawCharts() {
     var data = new google.visualization.DataTable();
     // populate data
     var table = new new 
google.visualization.Table(document.getElementById('table_vis'));
     var chart = new new 
google.visualization.BarChart(document.getElementById('chart_vis'));
     table.draw(data, {<options>});
     chart.draw(data, {<options>});
}

2) store the data globally (not recommended) and call it within multiple 
functions:

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

function drawTable() {
     var table = new new 
google.visualization.Table(document.getElementById('table_vis'));
     table.draw(data, {<options>});
}

function drawChart() {
     var chart = new new 
google.visualization.BarChart(document.getElementById('chart_vis'));
     chart.draw(data, {<options>});
}

3) store the data in a function, and return it on call:

function getData() {
     var data = new google.visualization.DataTable();
     // populate data
     return data;
}

function drawChart() {
     var chart = new new 
google.visualization.BarChart(document.getElementById('chart_vis'));
     chart.draw(getData(), {<options>});
}

Use #1 if it will work for you, as #2 can cause scope problems and #3 is 
inefficient.  If #1 won't work, then I'd suggest learning how to construct 
the data table in JSON, and then storing the JSON in a function like #3. 
 There are other options, like setting up data queries or AJAX requests, but 
they are probably more inefficient than #3 if your data is static.

If anyone else has better ideas, feel free to chime in.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to