NumberFormatting data from Google Spreadsheets via GViz

55 views
Skip to first unread message

David H Ramirez

unread,
Nov 30, 2016, 10:21:38 AM11/30/16
to Google Visualization API
Hello,

I'm using GViz to populate a webpage with data from a Google Spreadsheet. The columns are different types, however. Some are currency and some are percentages. I've tried using GViz's NumberFormat to set a '$' as a 'prefix'; I've even tried to set a 'pattern'. None of which seems to work. Can some help me out? I've included the code below.

var data = response.getDataTable();
 
 
//console.log(data);
 
 
var formatter = new google.visualization.NumberFormat({prefix:'$', pattern:'$###,###'});
 formatter
.format(data, 1); // Apply formatter to second column


 $bud01
.html(data.getValue(0, 0));
 $bud02
.html(data.getValue(1, 0));
 $bud03
.html(data.getValue(2, 0));
 $bud04
.html(data.getValue(3, 0));
 $bud05
.html(data.getValue(4, 0));
 $bud06
.html(data.getValue(5, 0));
 
 $res01
.html(data.getValue(0, 1));
 $res02
.html(data.getValue(1, 1));
 $res03
.html(data.getValue(2, 1));
 $res04
.html(data.getValue(3, 1));
 $res05
.html(data.getValue(4, 1));
 $res06
.html(data.getValue(5, 1));
 
 $bp01
.html(data.getValue(0, 2));
 $bp02
.html(data.getValue(1, 2));
 $bp03
.html(data.getValue(2, 2));
 $bp04
.html(data.getValue(3, 2));
 $bp05
.html(data.getValue(4, 2));
 $bp06
.html(data.getValue(5, 2));

Daniel LaLiberte

unread,
Nov 30, 2016, 10:38:04 AM11/30/16
to Google Visualization API
The value field remains the same, just a value.  What you want to do is getFormattedValue().

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/657c6e1d-9bfe-4c85-be9a-1231030927c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

David H Ramirez

unread,
Nov 30, 2016, 10:49:29 AM11/30/16
to Google Visualization API
Daniel!

Awesome! What an easy fix! Thank you so much!!
To post to this group, send email to google-visua...@googlegroups.com.



--
Reply all
Reply to author
Forward
0 new messages