2012-06-07 31 views
15

Tôi có đoạn mã sau:Charts Google - Tránh hiển thị giá trị âm trong yAxis

function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
    ['Year', 'People'], 
    ['2010',0] 
    ]); 

    // Create and draw the visualization. 
    new google.visualization.ColumnChart(document.getElementById('visualization')). 
     draw(data, 
      {title:"Yearly Coffee Consumption by Country", 
      width:600, height:400, 
      hAxis: {title: "Year"}, 
      backgroundColor: 'none' 
      } 
    ); 
} 

nào mang lại cho tôi bảng xếp hạng sau chart

Làm thế nào tôi có thể làm gì để tránh cho thấy giá trị âm trong yAxis? Tôi đã thử thêm vAxis: {minValue:0} mà không có bất kỳ may mắn nào.

Có một sân chơi/sandbox cho các bảng xếp hạng: Google Charts Playground

Trả lời

51

Bạn cần phải thiết lập viewWindowMode như rõ ràng

vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }} 
+0

Bây giờ điều này trên o có tay dường như để sửa chữa vấn đề của tôi. Cảm ơn bạn! – slarti42uk

+4

đây là câu trả lời đúng –

+0

'viewWindowMode:" explicit "' không còn cần thiết vì nó hiện không còn được dùng nữa. https://developers.google.com/chart/interactive/docs/gallery/linechart#configuration-options – etoxin

3

viewWindowMode: "explicit" bị phản đối trong phiên bản hiện tại trong đó sử dụng: vaxis.viewWindow.min:

vAxis: { 
    viewWindow: { 
     min: 0 
    } 
} 
+0

Nói đúng, 'viewWindowMode:" explicit "' không được dùng nữa. [Soure] (https://developers.google.com/chart/interactive/docs/gallery/linechart#configuration-options) – mshakeel

Các vấn đề liên quan