如何在Google Chart中设置轴步长?

发布于 2025-01-01 04:13:12 字数 240 浏览 5 评论 0原文

我想知道如何在由 JavaScript 构建的谷歌图表中设置轴步长? 我用它来设置最小值和最大值:

vAxis: {
title: 'temps (ms)',
    viewWindowMode: 'explicit',
    viewWindow: {
        max: 180,
        min: 0
    },
}

例如,我需要添加另一个约束来将垂直步长固定为 0.1。

I'm wondering how to set axis step in a google chart built from JavaScript?
I use this to set min and max:

vAxis: {
title: 'temps (ms)',
    viewWindowMode: 'explicit',
    viewWindow: {
        max: 180,
        min: 0
    },
}

And I need to add an other constraint to fix vertical step to 0.1 for example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

☆獨立☆ 2025-01-08 04:13:12

最后我发现了一个技巧:

     vAxis: {
        title: 'temps (ms)',
        viewWindowMode: 'explicit',
        viewWindow: {
          //max: 180,
          min: 0,
        },
        gridlines: {
          count: 10,
        }
      }

它不设置步骤,而是告诉

最大/(nb步)=计数(这里是10

因此,例如将 max 设置为 180,则每个步骤的值为 18 > 使用计数:10

Finally I found a trick using :

     vAxis: {
        title: 'temps (ms)',
        viewWindowMode: 'explicit',
        viewWindow: {
          //max: 180,
          min: 0,
        },
        gridlines: {
          count: 10,
        }
      }

It don't set steps but instead, tell that

max / (nb steps) = count (here it's 10)

So for example with max set to 180, each steps will have a value of 18 using count: 10.

聚集的泪 2025-01-08 04:13:12

你可以用刻度线来做到这一点:

vAxis: {
    title: 'temps (ms)',
    viewWindow: {
        min: 0,
        max: 180
    },
    ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180] // display labels every 10
}

You can do it with ticks:

vAxis: {
    title: 'temps (ms)',
    viewWindow: {
        min: 0,
        max: 180
    },
    ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180] // display labels every 10
}
诠释孤独 2025-01-08 04:13:12

我基本上做了 alain 所做的事情,计算最大值,将其乘以 1.1(考虑图表上最大元素上方的填充),然后除以我想要的步骤,得到我需要的步骤。

vAxis: {
  title: 'vAxis',
  minValue: 0,
  gridlines: {
    count: Math.ceil(max * 1.1 / interval) // try to pick the correct number to create intervals of 50000 
  }
}

其中 max 是最大值,interval 是所需的间隔。
这尚未经过彻底测试,因此 1.1 的常量和使用 Math.ceil 可能需要调整。

I essentially did what alain did, calculating the max value, multiplying it by 1.1 (to account for the padding above the max element on the chart) and dividing it by the steps I wanted to give me the steps I needed.

vAxis: {
  title: 'vAxis',
  minValue: 0,
  gridlines: {
    count: Math.ceil(max * 1.1 / interval) // try to pick the correct number to create intervals of 50000 
  }
}

where max is the max value and interval is the desired interval.
This has not been thoroughly tested, so the constant of 1.1 and using Math.ceil may need to be tweaked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文