I just ran into this issue myself. I decided to use a modifier to change the value to the formatted value using the original dataTable to find the formatted values. This isn't terribly efficient, but it works and computers are fast.
First create a lookup function:
function getFormatForValue(dataTable, column, value) {
// we need to spin through column in the dataTable looking
// for the matching value and then return the formatted value
var rowcount = dataTable.getNumberOfRows();
for (var i=0; i<rowcount; i++) {
if (dataTable.getValue(i, column) === value) {
// we found it, this will look much better
return dataTable.getFormattedValue(i, column);
}
}
// better than nothing
return value;
}
Then call that in a modifier, changing your original group call:
var countryData = google.visualization.data.group(
rawData,
[
{
'column': 0,
'modifier': function(value) { return getFormatForValue(rawData, 0, value); },
'type': 'string'
},
{
'column': 1,
'modifier': function(value) { return getFormatForValue(rawData, 1, value); },
'type': 'string'
}
],
[{'column': 4, 'aggregation': google.visualization.data.sum, 'type': 'number'}]
);
Update: It seems that you need the value and the formatted value preserved. In my case of displaying pie charts, I don't care to preserve the original value. I guess this won't work for you, but I'll leave this answer here for others that may have a simpler case like mine.
I spent a few more minutes on this and here is an alternative that will copy the formatted value while keeping the original cell value.
Create a copy function that uses the lookup function:
function copyFormattedValues(oldDataTable, oldColumn, newDataTable, newColumn) {
var rowcount = newDataTable.getNumberOfRows();
for (var i=0; i<rowcount; i++) {
var value = newDataTable.getValue(i, newColumn);
var formatted = getFormatForValue(oldDataTable, oldColumn, value);
newDataTable.setFormattedValue(i, newColumn, formatted);
}
}
Then in your case, call it once for each column you want to copy.
copyFormattedValues(rawData, 0, countryData, 0);
copyFormattedValues(rawData, 1, countryData, 1);
Your source and destination columns are the same but in some cases they may be different.
Of course, ideally all of this would have just happened automatically.