早些时候有人向我指出如何使用 pieHole 更改 3D 饼图中的标题或副标题,并将标题保留为浮动文本框。
对此
我为此使用的代码是
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");
}
代码中似乎没有任何内容可以显式调整切片标签。文档中也没有关于如何将它们放回去的任何内容。
我在捕获浏览器会话的 HAR 和提取描述图形的 JSON 结构方面取得了一些成功。
{
"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": {}
}
我还没有尝试以编程方式更改它们中的任何一个。
在这里可以做什么?我想实现以下目标:
- 保持标题或副标题框可移动。
- 保持切片命名。
- 找到一种方法使标题或副标题在图像中居中。
- 在图表框架内保持图像最大化(图像似乎表明上述代码会影响图像大小。)

