Arnaud Arnaud - 2 years ago 276
Javascript Question

Google Bar Chart max bar width

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:

enter image description here

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 (


Answer Source

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])
        rows.unshift([" ", null])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download