How to pass datatable by reference

52 views
Skip to first unread message

Neil

unread,
Mar 14, 2012, 9:09:22 AM3/14/12
to Google Visualization API
Hi all, I am having trouble working with a data table. I want to have
three functions for the moment, one to draw the table which calls the
other two functions, one to create the datatable object and create the
row headers this bit works. The second part would be to take that
object and pass by reference so that addRow can add values which will
be pulled from code elsewhere and return the updated datatable object.
This currently isn't working. I would finally like to move the other
functions into the table_functions.jsp file.

I am working on updating a really old code base and the original
author is no longer around which involves JSP and other things hence
the need to have things inside jsp files :|

Any help would be fantastic, I have included my attempt thus far for
reference.

Many thanks,
Neil


<% /*Testing the google table*/ %>

<html>
<head>
<jsp:include page="table_functions.jsp"/>
<script type='text/javascript' src='https://www.google.com/jsapi'></
script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);

function drawTable() {
var data = Init( );
data = addRow( data );

var table = new
google.visualization.Table( document.getElementById( 'table_div' ) );
table.draw( data, {showRowNumber: true} );
}

function Init( ) {
var data = new google.visualization.DataTable();
/* Create columns */
data.addColumn('string', 'Suite Name');
data.addColumn('string', 'Updated');
data.addColumn('number', 'Jobs');
data.addColumn('number', 'Pages');
data.addColumn('number', 'Failing');
data.addColumn('string', 'Diff, Fixed, Broke');
data.addColumn('number', 'Crash');
data.addColumn('number', 'Timeouts');
data.addColumn('string', 'Asrts, Errs, Warns');
data.addColumn('string', 'Hrs');
data.addColumn('number', 'Size(MB)');

return( data );
}

function addRow( var data ) {
data.addRows( 1 );
data.setCell( 0, 0, "Suite1" );
data.setCell( 0, 1, "Yesterday at 11:10 GMT" );
data.setCell( 0, 2, 24, '24' );
data.setCell( 0, 3, 48, '48' );
data.setCell( 0, 4, 0, '0' );
data.setCell( 0, 5, '(-23) *,(12) *,(10) *' );
data.setCell( 0, 6, 0, '0' );
data.setCell( 0, 7, 0, '0' );
data.setCell( 0, 8, '(0),(0),(0)' );
data.setCell( 0, 9, '19:20' );
data.setCell( 0, 10, 9999, '9999' );
return( data );
}
</script>
</head>

<body>
<div id='table_div'></div>
</body>
</html>

</html>

NA

unread,
Mar 17, 2012, 9:15:31 PM3/17/12
to google-visua...@googlegroups.com
How about chaning this:

                        data = addRow( data );

to just

  addRow(data);

That way it's clear you're trying to do a by-reference call.  Next, I'd change:
 
                function addRow( var data ) {

to just

   function addRow(data) {

And then I'd remove the line "return( data ); " in that same function; there's no need to return if you're doing this by reference.

That should do the trick.

Reply all
Reply to author
Forward
0 new messages