谷歌图表 - 避免在yAxis中显示负值 [英] Google Charts - Avoid showing negative values in yAxis

查看:83
本文介绍了谷歌图表 - 避免在yAxis中显示负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数drawVisualization(){
//创建并填充数据表。
var data = google.visualization.arrayToDataTable([
['Year','People'],
['2010',0]
]);

//创建并绘制可视化文件。
new google.visualization.ColumnChart(document.getElementById('visualization'))。
draw(data,
{title:按国家分列的每年咖啡消费量,
width:600,height:400,
hAxis:{title:Year},
backgroundColor:'none'
}
);
}

下面的图表给我提供了



如何避免在yAxis中显示负值?我已经尝试添加
vAxis:{minValue:0} 没有任何运气。



这些图表的操场/沙箱: Google图表游乐场



解决方案

您需要将viewWindowMode设置为显式

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


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.

There is a playground/sandbox for these charts: Google Charts Playground

解决方案

You need to set viewWindowMode as explicit

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

这篇关于谷歌图表 - 避免在yAxis中显示负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆