Reputation: 7769
When I first create a chart in Google Sheets, the Title is in a movable box that I can select and drag around inside the chart box.
If I then change that title programmatically, e.g.
chart = chart.modify()
.setOption('title',ChartTitleNameReplacement)
.build();
selectedSheet.updateChart(chart);
the Title jumps up to the top of the chart box and cannot be dragged anywhere.
What option setting do I need in the Google Apps Script code to keep that box movable? Alternatively, is there any way of specifying a position in the chart box for the Title?
Upvotes: 3
Views: 1993
Reputation: 201388
I have experienced the same issue with your situation. I think that this might be a bug. In this case, I achieved to modify the title without locking the title position using Sheets API. The sample script is as follows.
Before you run the script, please enable Sheets API at Advanced Google services.
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
, there is no fields
. I think that this might be the reason of the issue. So I added the existing properties to the request body by modifying the title. Please be careful this.Upvotes: 3