When formatting your data, you have to call the formatter before you draw
the chart, or it won't affect the data in the chart. Also, when using the
"pattern" property of a NumberFormatter, the formatter ignores all other
properties (except negativeColor), so you have to include the $ in the
pattern. Then, when you draw the chart, you have to specify the format for
the axis to use (hAxis.format takes a pattern like the one used in the
NumberFormatter). The final result would look something like this:
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Year', '19102', '19103', '19106', '19107'],
['2009', 1690, 1664, 1586, 1227],
['2010', 1979, 1774, 1539, 1400],
['2011', 1964, 1764, 1477, 1464],
['2012', 2270, 1727, 1658, 1453]
]);
var formatter = google.visualization.NumberFormat({pattern:'$#,###'});
formatter.format(data);
// Create and draw the visualization.
new
google.visualization.BarChart(document.getElementById('visualization')).
draw(data, {
title : 'Average One Bedroom Apartment Rent',
width: 700,
height: 400,
vAxis: {title: "Year"},
hAxis: {
title: "Rent (In Dollars)",
format: '$#,###'
}
});
}
On Tuesday, March 12, 2013 1:15:44 PM UTC-4, RJ White wrote:
>
> Messing around with the visualization API and having trouble getting the
> dollar signs to show up on the tooltip and the values at the bottom of the
> chart. Here's my coding-
>
> function drawVisualization() {
> // Create and populate the data table.
> var data = google.visualization.arrayToDataTable([
> ['Year', '19102', '19103', '19106', '19107'],
> ['2009', 1690, 1664, 1586, 1227],
> ['2010', 1979, 1774, 1539, 1400],
> ['2011', 1964, 1764, 1477, 1464],
> ['2012', 2270, 1727, 1658, 1453],
> ]);
>
> // Create and draw the visualization.
> new google.visualization.BarChart(document.getElementById(
> 'visualization')).
> draw(data,
> {
> title : 'Average One Bedroom Apartment Rent',
> width: 700,
> height: 400,
> vAxis: {title: "Year"},
> hAxis: {title: "Rent (In Dollars)"}
> });
>
> var formatter = google.visualization.NumberFormat(
> {suffix: '$', pattern:'#,###'});
> formatter.format(data);
> }
>
> What am I doing wrong here? Thanks.
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.