Format object for chart tooltip not working in Chrome

195 views
Skip to first unread message

Emily Yount

unread,
May 10, 2012, 1:07:10 PM5/10/12
to google-visua...@googlegroups.com
Has anyone had issues with a format object not working in Chrome? The following code works to re-format the text in the tooltip in Firefox, but not in Chrome.

//reformat numbers in the tooltip
var formatter = new google.visualization.NumberFormat({
pattern: '#,###' 
}); 
formatter.format(data, 1);

asgallant

unread,
May 10, 2012, 3:07:21 PM5/10/12
to google-visua...@googlegroups.com
It works just fine for me.  Can you post your code or a link to the page?

Emily Yount

unread,
May 10, 2012, 5:41:54 PM5/10/12
to google-visua...@googlegroups.com
Here's more of my code. I'm weary of posting a link because it goes with a newspaper story running this Sunday. The data is being pulled in from an XML document. 

plotCharts = function() {
var columns = ['Total compensation', 'Closing stock price', 'Net earnings']; 
var tagSets = ['totalComps', 'closeStocks', 'earnings']; 
var tags = ['totalComp', 'closeStock', 'earning'];
var divs = ['totalComp', 'stock', 'earnings']; 
var maxVals = [100000, 5, 1000000];  
$(columns).each(function(index) {
//Define the data table + add columns to the data table
var data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
   data.addColumn('number', columns[index]);
//Data array + add rows to the data table
var selectA = [];
var findMax = []; 
var selections = xmlDoc.getElementsByTagName(tagSets[index])[cSelectIDNUM].getElementsByTagName(tags[index]); 
$(selections).each(function(index) {
var selectYear = selections[index].getAttribute('label'); 
var selectValue = Number(selections[index].firstChild.nodeValue); 
findMax.push(selectValue); 
selectA.push([selectYear, selectValue]);  
data.addRow(selectA[index]); 
});
//Variable for max value
var maxVal = maxVals[index] + Math.max.apply(Math, findMax);
//Variable for the color value
var currentColor = $(companies)[cSelectIDNUM].getAttribute("color");

//Set up options
var options = {
chartArea: {left: 0, right: 0, top: 15, width: "100%", height: "80%"}, 
fontName: 'Verdana', 
hAxis: {textPosition: 'out', gridlines: {color: '#000', count: 5}},
// legend: {position: 'top'},
colors: ['#464646'], 
pointSize: 3, 
vAxis: {maxValue: maxVal, minValue: 0, textPosition: 'in', showTextEvery: 2}
};
//Instantiate and draw chart into the selected div 
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById(divs[index]));
chart.draw(data, options);
//reformat numbers in the tooltip
var formatter = new google.visualization.NumberFormat({
pattern: '#,###' 
}); 
formatter.format(data, 1);
})
}//plotCharts

asgallant

unread,
May 11, 2012, 9:20:38 AM5/11/12
to google-visua...@googlegroups.com
You need to move the formatting code to before you call chart.draw(); that should take care of the problem.

//reformat numbers in the tooltip
var formatter = new google.visualization.NumberFormat({
pattern: '#,###' 
}); 

formatter.format(data, 1);

//Instantiate and draw chart into the selected div 
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById(divs[index]));
chart.draw(data, options);

Emily Yount

unread,
May 11, 2012, 11:15:17 AM5/11/12
to google-visua...@googlegroups.com
Thanks! It's working now!
Reply all
Reply to author
Forward
0 new messages