data.setProperties usage

225 views
Skip to first unread message

mathias...@gmx.net

unread,
Jan 5, 2012, 8:36:26 AM1/5/12
to Google Visualization API
Hello,

I would like use a DataTable:

<html>
<head>
<script type='text/javascript' src='http://www.google.com/
jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawMap_table_div);
function drawMap_table_div() {
var data = new google.visualization.DataTable();
...
for ( var j=0; j<<?php echo $zeilen_table_div ?>; j++)
{
for ( var i=0; i<<?php echo $spalten_table_div ?>; i
++)
{
switch ( spaltentyp_table_div[i] )
{
case "string":
count=count+1;
var text = zellenwert_table_div[count];
data.setCell ( j, i, text );
var stylewert = stylewert_table_div[count];
data.setProperties ( j, i, {'style':
'background-color: green;'} );
count=count+1;
break;
case "number":
var pos = parseFloat
( zellenwert_table_div[count] );
var text = zellenwert_table_div[count+1];
data.setCell ( j, i, pos, text );
var stylewert = stylewert_table_div[count+1];
data.setProperties ( j, i, {'style':
'background-color: green;'} );
count=count+2;
break;
}
}
}

...

and set the cell properties via data.setProperties. No problem if I
set the style fixed burned via {'style': 'background-color: green;'}.
But how can I set the properties based on variable? data.setProperties
( j, i, stylewert ); don't work. Please help.

asgallant

unread,
Jan 5, 2012, 11:30:45 AM1/5/12
to google-visua...@googlegroups.com
Is the structure of the stylewert variable correct?  It should be an object like:

var stylewert = {style: 'background-color: green;'};

mathias...@gmx.net

unread,
Jan 6, 2012, 12:05:30 AM1/6/12
to google-visua...@googlegroups.com
I have tested with


var stylewert = {'style:' 'background-color: green;'};

or


var stylewert = {style: 'background-color: green;'};

but the setting

 
data.setProperties ( j, i, stylewert );
Hallo,

Ich möchte mit einem DataTable:

<html>
   <head>
      <Script type = "text / javascript" src = "http://www.google.com/
JSAPI '> </ script>
      <script type='text/javascript'>
         google.load ('Visualisierung', '1 ', {Pakete: [' table']});
         google.setOnLoadCallback (drawMap_table_div);
            Funktion drawMap_table_div () {
               var data = new google.visualization.DataTable ();
               ...
               for (var j = 0; j <<php echo $ zeilen_table_div>;? j + +)
               {
                  for (var i = 0; i <<php echo $ spalten_table_div>;? i
+ +)
                  {
                     switch (spaltentyp_table_div [i])
                     {
                     Bei "string":
                        count = count +1;
                        var text = zellenwert_table_div [count];
                        data.setCell (j, i, text);
                        var stylewert = stylewert_table_div [count];
                        data.setProperties (j, i, {'style':
'Background-color: green;'});
                        count = count +1;
                        break;
                     Bei "Zahl":
                        var pos = parseFloat
(Zellenwert_table_div [count]);
                        var text = zellenwert_table_div [count +1];
                        data.setCell (j, i, pos, text);
                        var stylewert = stylewert_table_div [count +1];
                        data.setProperties (j, i, {'style':
'Background-color: green;'});
                        count = count +2;
                        break;
                     }
                  }
               }

              ...

und stellen Sie die Eigenschaften von Zellen via data.setProperties. Kein Problem, wenn ich
den Stil fest verbrannt via {'style': 'background-color: green;'}.
Aber wie kann ich die Eigenschaften von Variablen basiert? data.setProperties
(J, i, stylewert); nicht funktionieren. Bitte helfen Sie.

is ignored, without any error message. Any ideas? Thanks.
 

asgallant

unread,
Jan 6, 2012, 8:15:10 AM1/6/12
to google-visua...@googlegroups.com
Can you paste the javascript produced after processing with PHP, or provide a link to the page?

Try calling data.getProperty(row, col, 'style') and see what is returned.  If it returns the style info, then the problem lies elsewhere.

www.mjh-software.org

unread,
Jan 7, 2012, 12:32:37 AM1/7/12
to Google Visualization API
The link to the side is http://www.mjh-software.org/wwb-extension-tabelle-01-inline.php

It's the table after capter "6. Beispiel".

It's the source part, line 330 and 339 from PHP side. I have set for
test the line

stylewert = "{'style': 'border: 1px solid
green;'}";

fixed burned.

for ( var j=0; j<<?php echo $zeilen_table_div ?>; j++)
{
for ( var i=0; i<<?php echo $spalten_table_div ?>; i
++)
{
switch ( spaltentyp_table_div[i] )
{
case "string":
count=count+1;
var text = zellenwert_table_div[count];
data.setCell ( j, i, text );
var stylewert = stylewert_table_div[count];
stylewert = "{'style': 'border: 1px solid
green;'}";
data.setProperties ( j, i, stylewert );
count=count+1;
break;
case "number":
var pos = parseFloat
( zellenwert_table_div[count] );
var text = zellenwert_table_div[count+1];
data.setCell ( j, i, pos, text );
var stylewert = stylewert_table_div[count+1];
stylewert = "{'style': 'border: 1px solid
green;'}";
data.setProperties ( j, i, stylewert );
count=count+2;
break;
}
}
}

asgallant

unread,
Jan 9, 2012, 9:57:47 AM1/9/12
to google-visua...@googlegroups.com
I think the problem is that you put quotes around the object, turning it into a string.

stylewert = "{'style': 'border: 1px solid green;'}";

should be:

stylewert = {'style': 'border: 1px solid green;'};

See this example: http://jsfiddle.net/Gq3Wq/

www.mjh-software.org

unread,
Jan 10, 2012, 2:16:25 AM1/10/12
to Google Visualization API
@asgallant - Many, many thanks for your great help! Greatings from
Germany.

asgallant

unread,
Jan 10, 2012, 9:51:32 AM1/10/12
to google-visua...@googlegroups.com
You're welcome.
Reply all
Reply to author
Forward
0 new messages