2013-03-28 32 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將不允許爲否定框。