通过脚本为电子表格图表设置“包含隐藏/过滤数据”选项

时间:2018-04-09 13:06:16

标签: google-apps-script google-sheets

使用谷歌应用脚​​本完成将数据写入谷歌电子表格并创建图表。当我将多个图表绘制到同一张纸上时,我将1行设置为图表的高度,使用该图表的数据隐藏所有行,对每个图表重复此操作,因此将属于每个图表的所有数据隐藏在“后面” 。

除了默认情况下图表没有显示隐藏数据外,一切正常。打开谷歌电子表格并编辑图表,“包含隐藏/过滤数据”对话框将显示一个复选框。通过检查,图表显示我想要的数据。我想通过谷歌应用程序脚本设置此选项,并期望有一个类似的选项 .setOption('includeHidden', true)

一些代码来说明我目前的工作:

var headerRow = ['h-Axis', 'data A', 'datalabel A', 'data B', 'datalabel B', 'data C']
var chart = mySheet.newChart().asComboChart()
.addRange(mySheet.getRange(rangeStartAfterHeaderRow, startColumn, numOfRowsExcludingHeader, numOfColumns))
.setTitle('My Chart')
.setLegendPosition(Charts.Position.TOP)
.setPosition(startRow, startColumn, 0, 0)
.setOption('isStacked', true)
.setOption('width', 800)
.setOption('height', 500)

// axis and data label columns are automatically interpreted as such; series index correspond as: 0=ColB, 1=ColD, 2=ColF
.setOption('series', 
           {0:{type:'bars', color:'#80ba27', labelInLegend:headerRow[1], targetAxisIndex:0},
            1:{type:'bars', color:'#CC3816', labelInLegend:headerRow[3]},
            2:{type:'steppedArea', color:'#4F80FF', labelInLegend:headerRow[5]}
           })

.setOption('vAxes', 
           {0:{title:'Vertical axis label'}})        

;

mySheet.insertChart(chart.build());

谢谢你, 约兰

0 个答案:

没有答案