如何通过Google Apps Script设置柱形图纵轴网格线的主步长值?
I’ve dealt with this exact frustration before—when you set vAxis.minValue via script, it wipes out any manual gridline step adjustments because the script resets the axis config without explicitly defining the step. Here’s how to lock in the 1-unit step permanently via code:
The Correct Approach: Use vAxis.tickInterval
The gridlines.minSpacing option you tried controls pixel distance between lines, not numerical intervals—so it won’t align with your integer project counts. Instead, use vAxis.tickInterval to force the vertical axis to increment by 1, which also sets the gridline step to match. This setting won’t get overwritten when you set minValue.
Updated Script Code
Add the new option to your existing chart modification chain:
chart = chart.modify() .setOption('title', "Today's date: " + dateString) .setOption('vAxis.minValue', 0) // Using a number instead of string avoids type-related issues .setOption('vAxis.tickInterval', 1) // Enforces 1-unit steps for ticks and gridlines .build(); sheet.updateChart(chart);
Why This Works
tickIntervaldirectly defines the numerical gap between each axis tick (and its paired gridline). Since your project counts are integers, this ensures gridlines only appear at whole numbers, eliminating confusion from 0.5 increments.- Unlike hardcoding gridline counts, this setting adapts automatically to daily data changes. If one day’s max project count is 6, you’ll get gridlines at 0,1,...,6; if it jumps to 15, the axis will extend to 15 while keeping the 1-unit step intact.
- Your baseline
vAxis.minValuesetting stays active, and thetickIntervalpersists alongside it—no more losing your preferred gridline setup after script runs.
内容的提问来源于stack exchange,提问作者TIsConfused

