javascript Google Charts - 避免在 yAxis 中显示负值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10937342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Charts - Avoid showing negative values in yAxis
提问by Hommer Smith
I have the following code:
我有以下代码:
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'
}
);
}
Which gives me the following chart
这给了我以下图表
How can I do to avoid showing negative values in the yAxis? I have tried adding
vAxis: {minValue:0}
without any luck.
如何避免在 yAxis 中显示负值?我尝试添加
vAxis: {minValue:0}
但没有任何运气。
There is a playground/sandbox for these charts: Google Charts Playground
这些图表有一个游乐场/沙盒:Google Charts Playground
?
?
回答by OscarMedina
You need to set viewWindowMode as explicit
您需要将 viewWindowMode 设置为显式
vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }}
回答by billynoah
viewWindowMode: "explicit"
is deprecated in current version which uses: vAxis.viewWindow.min
:
viewWindowMode: "explicit"
在当前版本中已弃用vAxis.viewWindow.min
:
vAxis: {
viewWindow: {
min: 0
}
}