2013-03-28 39 views
2

我正在与谷歌可视化一个错误修正为一个组合(列/行)图,此时轴中的一个去奇怪,开始重复数(即:1,1,2,2而不是1,2,3,4)。请参考下面重复的数字垂直轴

duplicate axes http://913a0d0e6c09b4bcc628-22cb2ea15f760b88c7ec5dccd300db1d.r25.cf1.rackcdn.com/duplicate_axes.png

图像以下是图表选项设置:

// Instantiate and draw our chart, passing in some options. 
var frequency_by_day_options = { 
    vAxes: [ 
     {format:'#,###', title:"Call Volume"}, 
     {format: '#%', title:'Missed Call Rate', 
      viewWindow:{ 
      max:1, 
      }} 
     ],  
    legend: {position: 'none'}, 
    chartArea: { height:'60%', width:'60%'}, 
    width: 800, 
    height: 350, 
    backgroundColor: 'transparent', 
    bar: { groupWidth: '90%'}, 
    isStacked: true, 
    seriesType: 'bars', 
    series: {0: {type:'bar', targetAxisIndex:0}, 1: {type:'line', targetAxisIndex:1},}, 
    colors: ['blue', 'green'], 
    animation:{ 
     duration: 1000, 
     easing: 'out',}, 
    }; 

我不知道是怎么回事。即使我注释掉所有vAxis选项,我仍然会观察到这种行为。任何想法我做错了什么?这是我发疯:)

回答

3

我要去猜测,左侧vAxis是 4,但实际上2。5个标签是0,0.5,1,1.5,2

由于您将格式设置为“#,###”,因此不会显示小数。如果将其更改为“#,###。#”,则它将显示0,0.5,1,1.5,2。

有十多种方法可以解决它,但最简单的方法可能是确保您的轴值仅整数值与这样的javascript函数:我面临同样的问题,当我们少箱数

// Take the Max/Min of all data values in all graphs 
var totalMax = 3; 
var totalMin = -1; 

// Figure out the largest number (positive or negative) 
var biggestNumber = Math.max(Math.abs(totalMax),Math.abs(totalMin)); 

// Round to an exponent of 10 appropriate for the biggest number 
var roundingExp = Math.floor(Math.log(biggestNumber)/Math.LN10); 
var roundingDec = Math.pow(10,roundingExp); 

// Round your max and min to the nearest exponent of 10 
var newMax = Math.ceil(totalMax/roundingDec)*roundingDec; 
var newMin = Math.floor(totalMin/roundingDec)*roundingDec; 

// Determine the range of your values 
var range = newMax - newMin; 

// Calculate the best factor for number of gridlines (2-5 gridlines) 
// If the range of numbers divided by 2 or 5 is a whole number, use it 
for (var i = 2; i <= 5; ++i) { 
    if (Math.round(range/i) = range/i) { 
     var gridlines = i 
    } 
} 
+0

很好的答案,非常感谢! – 2013-03-28 05:21:17

+0

没问题,很高兴我能帮到你。让我知道它是如何工作的! – jmac 2013-03-28 05:47:32

7

(让说,1或2)。我用maxValue选项解决了它。 只需在您的vaxis中添加maxValue = 4选项。它会一直添加5(0到4)个网格线。如果你的maxValue多于4,它会自动调整。 我的选项正常工作(标题:'没有框',格式:'#',minValue:0,maxValue:4)。 minValue = 0将不允许为否定框。