我有以下代码:
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'
}
);
}
它给出了下面的图表
如何避免在yAxis中显示负值?我已经尝试添加vAxis: {minValue:0}
,但没有任何运气。
这些图表有一个游乐场/沙箱:Google Charts Playground
发布于 2012-06-23 01:25:48
您需要将viewWindowMode设置为explicit
vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }}
发布于 2016-01-19 16:14:54
在使用:vAxis.viewWindow.min
的当前版本中,不推荐使用viewWindowMode: "explicit"
vAxis: {
viewWindow: {
min: 0
}
}
发布于 2021-07-01 17:49:40
这对我来说并不管用。我需要添加最大值:max:1
只有当所有值都为0时,才会出现负轴,因此,为了不限制最大值,我只在没有正值的情况下放置vAxis (使用PHP)。
我的代码示例如下:
$hayPositivos = false;
foreach($valores as $valor){
$html[]=",
['".$valor['dia']."', ".intval($valor['validadas']).", ".intval($valor['totales'])."]";
if(!$hayPositivos && (intval($valor['validadas']) >0 || intval($valor['totales']) >0)){
$hayPositivos = true;
}
}
$html[]="]);
var options = {
title: '".t('News by time:').$periodo_nombre."',
legend: { position: 'bottom' }";
if(!$hayPositivos){
$html[] = ",
vAxis: {
viewWindow: {min: 0, max:1}
}";
}
$html[] = "};
这是如何看待它的:
https://stackoverflow.com/questions/10937342
复制相似问题