使用以下代码,如何设置格式,以便在图表中以货币值(货币值)显示CurrencyValue1和CurrencyValue2?
function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('date','Date'); data.addColumn('number','CurrencyValue1'); data.addColumn('number','CurrencyValue2'); data.addRows(1); data.setValue(0,new Date(2011,8,12)); data.setValue(0,1,300.0000); data.setValue(0,2,759.1707); var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data,{ width: 660,height: 470,title: 'Heading',is3D: true,backgroundColor: '#f5f3e5' }); }
解决方法
见文档:
http://code.google.com/intl/cs-CZ/apis/chart/interactive/docs/reference.html#numberformatter
var data = new google.visualization.DataTable(); data.addColumn('date','Date'); data.addColumn('number','CurrencyValue1'); data.addColumn('number','CurrencyValue2'); var formatter = new google.visualization.NumberFormat( {prefix: '$',negativeColor: 'red',negativeParens: true}); formatter.format(data,1); formatter.format(data,2);
这将格式列第二和第三列,如金钱(以美元符号为前缀“$15.00”)