Bug with formatters and Table chart?

43 views
Skip to first unread message

Ambientson

unread,
Nov 19, 2012, 8:08:01 PM11/19/12
to google-visua...@googlegroups.com
Hi,

It took me a long time to finally that my values would not get updated on my table even though the underlying data table was changed because of formatters.

I might be doing something wrong but it sure looks like there is an issue. See following code to run in Google Code Playground (modified Table example):

function drawVisualization({
  // Create and populate the data table.
  var data google.visualization.arrayToDataTable([
    ['Name''Height''Smokes'],
    ['Tong Ning mu'174true],
    ['Huang Ang fa'523false],
    ['Teng nu'86true]
  ]);
  
  var formatter_percentage new google.visualization.NumberFormat({suffix:'%'});
  formatter_percentage.format(data1);

  // Create and draw the visualization.
  var tablenew google.visualization.Table(document.getElementById('table'));
  var tableView new google.visualization.DataView(data);
  table.draw(tableView{showRowNumberfalse});

  data.setValue(0,1,200);
  table.draw(tableView{showRowNumberfalse});
}

If we leave as is, the value in row 0, column 1 will never show as 200 in the table. If we comment ou the two formatter lines, it works.

Any ideas why?

Am I using the formatters in a bad way? Is there a work around (other than me formatting the values through custom code)?

Many thanks.

asgallant

unread,
Nov 19, 2012, 8:27:39 PM11/19/12
to google-visua...@googlegroups.com
The table always displays the formatted value of the cell, regardless of what the actual value is.  When you use a formatter, it sets the formatted value of every cell in the chosen column.  If you update the value of the cell, but not the formatted value, it will still display the original formatted value.  The formatters also won't change an already-formatted value, so you have to clear the formatted value first, and then call the formatter again:

data.setValue(0,1,200);
data.setFormattedValue(01null);
// reformat column 1
formatter_percentage.format(data1);

Ambientson

unread,
Nov 19, 2012, 9:29:39 PM11/19/12
to google-visua...@googlegroups.com
Thanks.
Reply all
Reply to author
Forward
0 new messages