Earlier it was pointed out to me how to change a title or subtitle in a 3D pie chart with a pieHole and have the title remain as a floating text box.
One of the unpleasant side effects of this was the removal of the slice labels, that is from this

to this
The code I'm using for this is
function UpdateSubTitleAdvanced(sheetName, chartId, newTitle) {
const active = SpreadsheetApp.getActiveSpreadsheet();
const ssId = active.getId();
const sheets = Sheets.Spreadsheets.get(ssId).sheets;
for (let s in sheets) {
let sheet = sheets[s];
if (sheet.properties.title === sheetName) {
for (let c in sheet.charts) {
let chart = sheet.charts[c];
if (chart.chartId === chartId) {
Logger.log("Sheet %s, Chart %s, Title '%s', SubTitle '%s'", sheet.properties.title, String(chart.chartId), chart.spec.title, chart.spec.subtitle);
delete chart.position;
chart.spec.subtitle = newTitle;
Sheets.Spreadsheets.batchUpdate({requests:[{updateChartSpec: chart}]}, ssId);
}
}
}
}
}
function _UpdateSubTitle() {
UpdateSubTitleAdvanced("Group0",713335354,"### new sub title");
}
There doesn't appear to be anything in the code that explicitly knobbles the slice labels. Nor is there much of anything in the documentation regarding how to put them back.
I have had some success in capturing the HAR of the browser session and extracting the JSON structure describing the graphic.
{
"chartType": "PieChart",
"options": {
"pieSliceTextStyle": {
"fontSize": 10
},
"legend": "none",
"annotations": {
"total": {
"textStyle": {}
},
"domain": {
"textStyle": {}
}
},
"is3D": true,
"title": "### new sub title",
"titleTextStyle": {
"fontName": "serif",
"alignment": "center"
},
"pieSliceText": "label",
"fontName": "serif",
"legendTextStyle": {},
"pieHole": 0.5,
"bubble": {
"textStyle": {}
},
"useFirstColumnAsDomain": true,
"subtitleTextStyle": {
"fontName": "sans-serif",
"color": "#000000",
"fontSize": 16,
"bold": true,
"alignment": "center"
},
"subtitle": "influencer marketing",
"width": 600,
"textStyle": {
"fontName": "serif"
},
"chartArea": {
"top": "1.8585131894484377%",
"left": "1.4962121212121169%",
"width": "98.50378787878789%",
"height": "96.88249400479617%"
},
"height": 371
},
"initialView": {}
}
I haven't tried changing any of them programmatically as yet.
What can be done here? I want to achieve the following:
- Keep the title or subtitle box movable.
- Keep the slices named.
- Find a way to have the title or subtitle centred in the image.
- Keep the image maximised within the chart frame (the images would seem to indicate that the above code affects the image size.)
