我正在尝试格式化以下谷歌图表底部访问以显示为货币:
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'horizontalBar',
data: {
labels: [["California", "2,105 salaries"], ["Texas", "1,461 salaries"], ["New York", "1,253 salaries"], ["Illinois", "946 salaries"], ["Florida", "922 salaries"], ["Ohio", "699 salaries"], ["Pennsylvania", "696 salaries"]],
datasets: [{
label: 'National Salary Data',
data: [100599, 83851, 93192, 87198, 73294, 77068, 81690],
backgroundColor: [
'rgba(210, 16, 52, 1)',
'rgba(210, 16, 52, 1)',
'rgba(210, 16, 52, 1)',
'rgba(210, 16, 52, 1)',
'rgba(210, 16, 52, 1)',
'rgba(210, 16, 52, 1)',
'rgba(210, 16, 52, 1)'
]
}]
},
options: {
postLabelFontSize: 20,
title: {
display: true,
text: ['Employees with a Master of Business Administration (M.B.A.) | degree median salary by job']
}
}
});
我希望“数据”格式化为$和逗号,如下所示:$ 100,599。
我曾试图使用类似的东西,却无法让它发挥作用:
var formatter = new google.visualization.NumberFormat(
{prefix: '$', negativeColor: 'red', negativeParens: true});
formatter.format(data, 1);