[英]Titles in Google Sheets Charts
當我第一次在 Google 表格中創建圖表時,標題位於一個可移動的框中,我可以 select 並在圖表框內四處拖動。
如果我然后以編程方式更改該標題,例如
chart = chart.modify()
.setOption('title',ChartTitleNameReplacement)
.build();
selectedSheet.updateChart(chart);
標題會跳到圖表框的頂部,並且不能拖動到任何地方。
我需要在 Google Apps 腳本代碼中進行哪些選項設置才能保持該框可移動? 或者,有沒有辦法在標題的圖表框中指定 position?
我遇到了與您的情況相同的問題。 我認為這可能是一個錯誤。 在這種情況下,我使用表格 API 實現了修改標題而不鎖定標題 position。 示例腳本如下。
在運行腳本之前, 請在 Advanced Google services 中啟用表格 API 。
const updatedTitle = "### updated title ###";
const ss = SpreadsheetApp.getActiveSpreadsheet()
const ssId = ss.getId();
const chart = Sheets.Spreadsheets.get(ssId).sheets[0].charts[0];
delete chart.position;
chart.spec.title = updatedTitle;
Sheets.Spreadsheets.batchUpdate({requests: [{updateChartSpec: chart}]}, ssId);
UpdateChartSpecRequest
中,沒有fields
。 我認為這可能是問題的原因。 所以我通過修改標題將現有屬性添加到請求正文中。 請注意這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.