我想删除谷歌图表工具提示中的小数。我希望它舍入到最接近的整数。
这是我的Google图表代码。如果可能的话,我想我还会在我的选项中添加更多内容?我不想调整我的数据进入图表。所以它应该发生在图表中。
var drawChart = function (data, type, firstIsAverage, vAxisHeader) {
var shift = (firstIsAverage === true) ? 0 : 1;
var fontname = 'Roboto';
var fontsize = 14;
var chartObject = {
type: type,
display: false,
data: data,
options: {
chartArea: {
left: 100,
top: 30,
width: 800,
height: 240
},
vAxis: {
title: vAxisHeader,
titleTextStyle: {
italic: false
}
},
fontName: fontname,
fontSize: fontsize,
legend: 'none',
colors: colors.slice(shift),
isStacked: "true",
fill: 20,
displayExactValues: false,
},
formatters: {}
};
setAllColumnsVisible(chartObject);
return chartObject;
};
答案 0 :(得分:2)
您可以在此示例中使用NumberFormat,并在评论中指出
google.load('visualization', '1', {packages:['corechart'], callback: drawChart});
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours', 'Other'],
['Work', 7007.08, 7427.41],
['Eat', 8227.88, 6427.80],
['Commute', 9447.48, 9427.23],
['Watch TV', 6667.28, 6427.66],
['Sleep', 7887.18, 7427.79]
]);
var formatter = new google.visualization.NumberFormat({pattern: '#,##0'});
// format number columns
for (var i = 1; i < data.getNumberOfColumns(); i++) {
formatter.format(data, i);
}
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(data);
}
&#13;
<script src="https://www.google.com/jsapi"></script>
<div id="chart"></div>
&#13;