如何设置水平(或垂直)轴数格式的谷歌工作表图表?



我正在生成一个电子表格、几个数据透视表和图表来可视化结果。我有一切工作,除了我还没有找到一种方法来设置图表水平/垂直轴的数字格式。我希望坐标轴显示的是整数,而不需要我更改后台数据的数字格式。

遗憾的是,Google提供的文档没有涵盖此功能:https://developers.google.com/apps-script/chart-configuration-options#line-chart-configuration-options.

可以手动设置数字格式,但是,由于我正在生成大量图表,因此对所有图表都这样做太麻烦了。

下面是一个应用程序脚本代码的例子,用来生成我的图表:
embeddedChartBuilder.setChartType(Charts.ChartType.LINE)
.setPosition(chartRow, chartColumn, 0, 0)
.setNumHeaders(1)
.setOption('backgroundColor', '#222222')
.setOption('height', chartHeightPx)
.setOption('width', chartWidthPx)
.setOption('series', [
{color:'#4ebcbb', pointSize:6, lineWidth:4},
{color:'#cccccc', pointSize:6, lineWidth:4},
{color:'#666666', pointSize:6, lineWidth:4},
{color:'#34a853', pointSize:6, lineWidth:4}])
.setOption('applyAggregateData', 0)
.setOption('vAxis.gridlines.color', '#434343')
.setOption('vAxis.minValue', 0)
.setOption('vAxis.maxValue', 5)
.setOption('vAxis.textStyle', { color: '#efefef', fontName: 'Arial', fontSize: 12, bold: false, italic: false })
.setOption('hAxis.textStyle', { color: '#efefef', fontName: 'Arial', fontSize: 12, bold: false, italic: false });

在配置选项下的折线图页面中,您有以下描述的hAxis.format:

A format string for numeric or date axis labels.
For number axis labels, this is a subset of the decimal formatting ICU pattern set . For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5. You can also supply any of the following:
{format: 'none'}: displays numbers with no formatting (e.g., 8000000)
{format: 'decimal'}: displays numbers with thousands separators (e.g., 8,000,000)
{format: 'scientific'}: displays numbers in scientific notation (e.g., 8e6)
{format: 'currency'}: displays numbers in the local currency (e.g., $8,000,000.00)
{format: 'percent'}: displays numbers as percentages (e.g., 800,000,000%)
{format: 'short'}: displays abbreviated numbers (e.g., 8M)
{format: 'long'}: displays numbers as full words (e.g., 8 million)
For date axis labels, this is a subset of the date formatting ICU pattern set . For instance, {format:'MMM d, y'} will display the value "Jul 1, 2011" for the date of July first in 2011.
The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale .
In computing tick values and gridlines, several alternative combinations of all the relevant gridline options will be considered and alternatives will be rejected if the formatted tick labels would be duplicated or overlap. So you can specify format:"#" if you want to only show integer tick values, but be aware that if no alternative satisfies this condition, no gridlines or ticks will be shown.
This option is only supported for a continuous axis.
Type: string
Default: auto

还有以下格式的vAxis.format选项:

A format string for numeric axis labels. This is a subset of the ICU pattern set . For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5. You can also supply any of the following:
{format: 'none'}: displays numbers with no formatting (e.g., 8000000)
{format: 'decimal'}: displays numbers with thousands separators (e.g., 8,000,000)
{format: 'scientific'}: displays numbers in scientific notation (e.g., 8e6)
{format: 'currency'}: displays numbers in the local currency (e.g., $8,000,000.00)
{format: 'percent'}: displays numbers as percentages (e.g., 800,000,000%)
{format: 'short'}: displays abbreviated numbers (e.g., 8M)
{format: 'long'}: displays numbers as full words (e.g., 8 million)
The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale .
In computing tick values and gridlines, several alternative combinations of all the relevant gridline options will be considered and alternatives will be rejected if the formatted tick labels would be duplicated or overlap. So you can specify format:"#" if you want to only show integer tick values, but be aware that if no alternative satisfies this condition, no gridlines or ticks will be shown.
Type: string
Default: auto

最新更新