Wan to display the google column chart vAxis as whole number..
它会自动显示0.0,0.5,1.0 ......就像这样。我不是vAxis的最大数量。
我使用下面的代码表示整数。需要像0,1,2,3,4 ....
的解决方案chart.draw(data, {
width: 800,
height: 480,
orientation: 'horizontal',
vAxis: {format: '0'}
}
);
给我一些解决这个问题的想法..提前感谢..
答案 0 :(得分:1)
您可以通过hAxis.ticks
property指定它:
用指定的替换自动生成的X轴刻度 阵列。数组的每个元素都应该是有效的tick值 (例如数字,日期,日期时间或时间)或对象。如果 它是一个对象,它应该有一个v属性的tick值,和一个 包含要显示为的文字字符串的可选f属性 标签。
示例:
hAxis: { ticks: [5,10,15,20] } hAxis: { ticks: [{v:32, f:'thirty two'}, {v:64, f:'sixty four'}] } hAxis: { ticks: [new Date(2014,3,15), new Date(2013,5,15)] } hAxis: { ticks: [16, {v:32, f:'thirty two'}, {v:64, f:'sixty four'}, 128] }
此选项仅支持连续轴。
类型:元素数组默认值:auto
示例强>
google.load('visualization', '1', {packages: ['corechart', 'bar']});
google.setOnLoadCallback(drawBasic);
function drawBasic() {
var data = new google.visualization.DataTable();
data.addColumn('timeofday', 'Time of Day');
data.addColumn('number', 'Motivation Level');
data.addRows([
[{v: [8, 0, 0], f: '8 am'}, 0.1],
[{v: [9, 0, 0], f: '9 am'}, 0.5],
[{v: [10, 0, 0], f:'10 am'}, 1.3],
[{v: [11, 0, 0], f: '11 am'}, 8.4],
[{v: [12, 0, 0], f: '12 pm'}, 6.5],
[{v: [13, 0, 0], f: '1 pm'}, 0.6],
[{v: [14, 0, 0], f: '2 pm'}, 2.7],
[{v: [15, 0, 0], f: '3 pm'}, 1.2],
[{v: [16, 0, 0], f: '4 pm'}, 2.9],
[{v: [17, 0, 0], f: '5 pm'}, 1.0],
]);
var options = {
title: 'Motivation Level Throughout the Day',
hAxis: {
title: 'Time of Day',
format: 'h:mm a',
},
vAxis: {
title: 'Rating (scale of 0-10)',
minValue: 0,
ticks: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
},
orientation: 'horizontal'
};
var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="chart_div" style="height: 480px"></div>