Javascript 谷歌可视化-柱状图间隔问题(重复间隔)

Javascript 谷歌可视化-柱状图间隔问题(重复间隔),javascript,google-visualization,Javascript,Google Visualization,我使用以下代码生成上述谷歌图表: var data = google.visualization.arrayToDataTable([ ['Date', 'Tickets'], ['11/05/15',1], ['10/05/15',0], ['09/05/15',0], ['08/05/15',0], ['07/05/15',0], ['06/05/15',0], ['05/05/15',0], ['04/05/15',0], ]); var columnChartOptions = { t

我使用以下代码生成上述谷歌图表:

var data = google.visualization.arrayToDataTable([
['Date', 'Tickets'],
['11/05/15',1],
['10/05/15',0],
['09/05/15',0],
['08/05/15',0],
['07/05/15',0],
['06/05/15',0],
['05/05/15',0],
['04/05/15',0],
]);

var columnChartOptions = {
title: "",
legend: { position: 'none' },
width: '100%',
height: '100%',
colors: ["#27ae60", "#2980b9", "#e67e22", "#e74c3c", "#e74c3c"],
chartArea: { left: '8%', top: '8%', width: "85%", height: "70%" },

vAxis: {
minValue: 1,
format:'#'
},

new google.visualization.ColumnChart(document.getElementById('ticket-history-graph')).
draw(data,columnChartOptions);
但是,它会产生以下错误的间隔计数:


我需要对vAxis的定义做什么修改才能纠正这个问题?我尝试过改变最小值和最大值,但都无济于事。我还必须补充一点,当使用更高的数字时,这不是问题,只是计数较低。

您的问题是
格式:“#”
,这就是为什么您会得到两个零和三个一(当您四舍五入到零小数时,图形试图表示四舍五入到[0,0.25,0.5,0.75,1]的值),因此复制它们)

我的建议是您检查属性vAxis.gridlines.count

我做了一个提琴,检查图表中的maxValue是1还是2,如果是,我指定网格线的计数为2或3,如果不是1或2,它使用谷歌自己的自动生成。 查看您是否了解我的做法:
请记住尝试将某些值更改为更高/更低,以了解其工作原理

//Get all distinct ticketsales, sorted ascending by default, so you have to get the last value to get the highest one.
    var maxValue = data.getDistinctValues(1)[data.getDistinctValues(1).length - 1]

    // Specify gridCount to null, so if it doesn't enter any of the if's below, it will still be null
    var gridCount = null

    //check if the highest value is 1 or 2 else leave gridCount to null
    if (maxValue == 1) {
        gridCount = 2
    }
    if (maxValue == 2) {
        gridCount = 3
    }
以及对ColumnChart选项的添加:

 vAxis: {
            gridlines: {
                //specify the amount of gridlines to var gridCount, if it's still specified as null, it will use googles automatic generation.
                count: gridCount
            },

为什么不
gridCount=maxValue+1?根据售出的门票数量,它可能会迅速升级为一个相当混乱的图表。请参见此示例中的
maxValue=20
gridCount=maxValue+1
:啊,好的。请在答案中包含相关代码,而不仅仅是JSFIDLE的链接-