本文介绍了Google Bar Chart最大栏宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个固定宽度div内的Google Bar Chart。在某些情况下,我有很多酒吧,但有时我只会得到1或2个酒吧。问题是,在这种情况下,我得到了这样的图表:



我想设置一个最大栏宽度,这样当我只有一个栏时,它不占用整个容器宽度。您是否知道如何达到这个目标?



我正在寻找材料图表的解决方案( google.charts.Bar

解决方案

解决方案是在没有空白列时添加($ i

$ p $ for(var i = 0; i< n; i ++){
if(i %2 == 0)
rows.push([,null])
else
rows.unshift([,null])
}
dataTable.addRows(行);


I have a Google Bar Chart inside a fixed-width div. In some cases, I have many bars, but sometimes I only get 1 or 2 bars. The problem is that in this case, I got a chart like this:

I would like to set a max bar width, so that when I have only one bar, it doesn't take the whole container width. Do you know how to achieve that please?

[edit] I am looking for a solution for a Material chart (google.charts.Bar)

解决方案

The solution is to add blank columns when there are not enough columns initially.

for (var i = 0; i < n; i++) {
    if (i % 2 == 0)
        rows.push([" ", null])
    else
        rows.unshift([" ", null])
}
dataTable.addRows(rows);

这篇关于Google Bar Chart最大栏宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:19