简体   繁体   English

在Google图表中设置条形图的基线和范围

[英]Setting baseline and range of barchart in Google Charts

I'm drawing a barchart representing the homicide rate in the USA. 我正在画一张代表美国凶杀率的条形图。 I'm trying to truncate this chart by setting the baseline at > 0 but the code: 我试图通过将基线设置为> 0来截断该图表,但代码如下:

    var options = {
      chart: {
        title: 'Intentional homicide rate per 100,000 population, by country/territory (2000-2013) in the US',
        subtitle: 'Intentional homicide is defined as unlawful death purposefully inflicted on a person by another person',
        hAxis: {title: 'Year'},
        vAxis: {
              title: 'Rate per 100,000', 
              viewWindow:{
                max:20,
                min:2
              },
        // ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] 
        },
      }
    };

doesn't do its job and shows the whole range contrarily to my aim. 并没有完成其工作,并且显示了与我的目标相反的整个范围。

This is the complete code of the chart. 是图表的完整代码。 What did I mistake? 我错了什么?

The same procedure works with an area chart ( Pluckr example )... how come? 相同的过程适用于面积图(以Pluckr为例 )。

Your code isn't proper, as stated in other answers. 如其他答案所述,您的代码不正确。

You need to use the function google.charts.Bar.convertOptions when working with material charts. 使用物料图时,需要使用函数google.charts.Bar.convertOptions Source (scroll down a bit, or ctrl + f for convertOptions). 源代码 (向下滚动一点,或为convertOptions向下滚动ctrl + f)。

You're currently drawing the chart with 您目前正在使用

chart.draw(data, options);

while the correct way would be 而正确的方法是

chart.draw(data, google.charts.Bar.convertOptions(options));

Working plunker 工作塞

(This is also why it's working with the area chart.. That's not a material chart). (这也是它与面积图一起使用的原因。这不是实质图)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM