Use the formatter on the new column: formatter.format(data, 2);
use that in addition to the other format call. The syntax there is #format(<DataTable>, <column index>), so you can reuse the formatter on multiple columns and multiple tables. On Tuesday, February 5, 2013 9:58:25 AM UTC-5, Todd Lee wrote: > > Hi again. I was wondering how to correct a problem with my new code. > Everything works, but I went and added some more data, and I don't really > understand how to get the currency going for the "median sold price" column. > > Here is the code: > > <div id="chart"></div> > <script type="text/javascript" src="https://www.google.com/jsapi > "></script> > <script type="text/javascript"> > google.load("visualization", "1", {packages:["corechart"]}); > google.setOnLoadCallback(drawChart); > function drawChart() { > var data = google.visualization.arrayToDataTable([ > ['Years', 'Average Sold Price', 'Median Sold Price'], > ['2002', 342371, 312000], > ['2003', 365556, 330000], > ['2004', 402310, 360000], > ['2005', 430962, 385000], > ['2006', 460739, 410000], > ['2007', 490932, 432000], > ['2008', 507621, 450000], > ['2009', 526248, 468000], > ['2010', 588254, 525000], > ['2011', 623887, 555000], > ['2012', 681408, 600000] > ]); > > var options = { > title: 'none', > vAxis:{ > format: "'$'#,###" > }, > legend:{ > position: '1' > }, > chartArea:{ > top: 60 > }, > titlePosition: 'none', > backgroundColor: 'white' > }; > var formatter = new google.visualization.NumberFormat({prefix: > '$'}); > formatter.format(data, 1); > var chart = new > google.visualization.LineChart(document.getElementById('chart')); > chart.draw(data, options); > } > </script> > <div id="chart" style="width: 650px; height: 50px;"></div> > > > > > On Monday, February 4, 2013 6:00:13 PM UTC-5, asgallant wrote: >> >> Sorry, I missed this scanning your original code, but you have to remove >> the "align: center" line in the chart options, as a) it causes the script >> to fail, and b) there is no align option anyway. See an example here: >> http://jsfiddle.net/asgallant/wcr87/. Also note that the CSS I posted >> contains a syntax error (there shouldn't be a ":" after "#visualization"). >> >> On Monday, February 4, 2013 5:28:06 PM UTC-5, Todd Lee wrote: >>> >>> Thanks for the info and code asgallant. I tried to fix the currency >>> issue by copying and pasting the new code you gave. I think there might be >>> a syntax issue as it does not work. >>> >>> >>> function drawVisualization() { >>> // Create and populate the data table. >>> var data = google.visualization.arrayToDataTable([ >>> ['Years', 'Average Sold Price'], >>> ['2002', 342371], >>> ['2003', 365556], >>> ['2004', 402310], >>> ['2005', 430962], >>> ['2006', 460739], >>> ['2007', 490932], >>> ['2008', 507621], >>> ['2009', 526248], >>> ['2010', 588254], >>> ['2011', 623887], >>> ['2012', 681408] >>> ]); >>> var formatter = new google.visualization.NumberFormat({pattern: >>> '$####'}); >>> formatter.format(data, 1); >>> >>> // Create and draw the visualization. >>> new google.visualization.LineChart(document.getElementById( >>> 'visualization')). >>> draw(data, { >>> curveType: "function", >>> align: center >>> width: 500, >>> height: 400, >>> vAxis: { >>> maxValue: 10, >>> format: '$####' >>> } >>> }); >>> >>> On Monday, February 4, 2013 4:43:30 PM UTC-5, Todd Lee wrote: >>>> >>>> I would like to know how to center the graph below and get the >>>> currency sign to show. >>>> Thanks in advance. >>>> >>>> >>>> >>>> !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " >>>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>> <html xmlns="http://www.w3.org/1999/xhtml"> >>>> <head> >>>> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> >>>> <title> >>>> Average Sale Price History >>>> </title> >>>> <script type="text/javascript" src="http://www.google.com/jsapi >>>> "></script> >>>> <script type="text/javascript"> >>>> google.load('visualization', '1', {packages: ['corechart']}); >>>> </script> >>>> <script type="text/javascript"> >>>> function drawVisualization() { >>>> // Create and populate the data table. >>>> var data = google.visualization.arrayToDataTable([ >>>> ['Years', 'Average Sold Price'], >>>> ['2002', 342371], >>>> ['2003', 365556], >>>> ['2004', 402310], >>>> ['2005', 430962], >>>> ['2006', 460739], >>>> ['2007', 490932], >>>> ['2008', 507621], >>>> ['2009', 526248], >>>> ['2010', 588254], >>>> ['2011', 623887], >>>> ['2012', 681408] >>>> ]); >>>> >>>> // Create and draw the visualization. >>>> new >>>> google.visualization.LineChart(document.getElementById('visualization')). >>>> draw(data, {curveType: "function", >>>> align: center >>>> width: 500, height: 400, >>>> vAxis: {maxValue: 10}} >>>> ); >>>> } >>>> >>>> >>>> google.setOnLoadCallback(drawVisualization); >>>> </script> >>>> </head> >>>> <body style="font-family: Arial;border: 0 none;"> >>>> <div id="visualization" style="width: 500px; height: 400px;"></div> >>>> </body> >>>> </html> >>>> >>>> >>> -- 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.
