我已使用以下格式将Google分析API响应“ga:avgTimeOnPage”格式化为“00:00:00”。
var referral_pages_Config = {
query: {
metrics: 'ga:sessions, ga:bounceRate, ga:avgTimeOnPage',
dimensions: 'ga:fullReferrer',
'max-results': 6,
sort: '-ga:sessions',
'output': 'dataTable'
},
chart: {
options: {
width: '100%'
}
}
};
referral_pages.on('success', function(response) {
response.dataTable.cols[0].label = 'Page';
response.dataTable.cols[1].label = 'Page Views';
response.dataTable.cols[2].label = 'Bounce Rate';
response.dataTable.cols[3].label = 'Avg. Time on Page';
var referral_pages = new google.visualization.DataTable(response.dataTable);
var formatter = new google.visualization.NumberFormat({
fractionDigits: 2,
suffix:'%'
});
var formatter_visiter = new google.visualization.NumberFormat({
pattern:'###,###'
});
formatter_visiter.format(referral_pages, 1);
formatter.format(referral_pages, 2);
// Format Time as per the User-end
for (var k = 0, profile; profile = response.dataTable.rows[k]; k++) {
//alert(profile.c[3].v);
var avg_time_val = profile.c[3].v;
var formatt_time_val = avg_time_val.toHHMMSS();
profile.c[3].v = formatt_time_val;
}
var referral_pages_table = new google.visualization.Table(document.getElementById('referral_pages_container'));
referral_pages_table.draw(referral_pages);
});
如果我们更改了格式,则显示为NAN。任何人都指导我解决方案来解决它。