2017-05-29 66 views
0

如何避免從谷歌圖表的負值Y軸負值,我試圖viewWindow:{分鐘:0,}在我的Y軸,但仍僅示出負值。 請幫助一下。在此先感謝如何避免從谷歌圖表

<div class="timeline-item"> 
        <div id="top_x_div" style="width: 100%; height: 300px;"></div> 
</div> 

<script type="text/javascript"> 
google.charts.load('current', {packages: ['corechart', 'bar']}); 
google.charts.setOnLoadCallback(drawStacked); 

function drawStacked() { 
     var data = new google.visualization.arrayToDataTable([ 
      ['Courses', 'Students'], 

      ["Electronics", 2 ], 
      ]); 

     var options = { 



    legend: { position: 'none' }, 
       isStacked: true, 
        colors: ['green'], 

        bars: 'vertical', // Required for Material Bar Charts. 
        axes: { 
         x: { 
         0: { side: 'bottom', label: 'Percentage'} // Top x-axis. 
         } 
        }, 

        axes: { 
         y: { 
         0: { side: 'bottom', label: 'Students'}, // Top x-axis. 
         /* viewWindow: { 
            min: 0, 
            },*/ 
         } 
        }, 
       vAxis: { 
        viewWindow: { 
         min: 0 
        } 
       }, 

        bar: { groupWidth: "90%" } 
        }; 
     var chart = new google.charts.Bar(document.getElementById('top_x_div')); 
     chart.draw(data, options); 
}; 
</script> 
+0

數據是否包含負值?當我繪製上面的圖表時,看不到任何 - 也有_meterial_圖表不支持多種選項,請參閱 - [跟蹤材料圖特徵奇偶校驗的問題](https://github.com/google/谷歌的可視化,問題/問題/ 2143) - 推薦使用_core_圖與選項 - >'主題:「material',而不是... – WhiteHat

+0

其實圖表不包含任何負值的數據,但現在我認爲負值談到因爲當沒有爲特定課程@WhiteHat – SKM

回答

1

您需要在vAxis選項上設置viewWindow。

vAxis: { 
    viewWindow: { 
     min: 0 
    } 
} 

Source

+0

我想,沒有學生(零名同學),但它不工作 – SKM

+0

您的代碼不顯示?您已將viewWindow添加到軸對象 – Colwin

+0

,但確實沒有變化 – SKM