以前是pointed out to me如何使用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": {}
}
我还没有尝试通过编程方式更改它们。
这里可以做什么?我想实现以下目标:
这个答案怎么样?
此问题的原因是,在当前阶段,Sheets API中通过“ spreadsheets.get”方法检索的对象中不包括“ Slice标签”的属性。可以在图表的以下对象中看到。通过Sheets API中的“ spreadsheets.get”方法检索此对象。
{
"chartId": ###,
"spec": {
"title": "sample title",
"pieChart": {
"legendPosition": "LABELED_LEGEND",
"domain": {
"sourceRange": {
"sources": [
{
"sheetId": ###,
"startRowIndex": 0,
"endRowIndex": 5,
"startColumnIndex": 0,
"endColumnIndex": 1
}
]
}
},
"series": {
"sourceRange": {
"sources": [
{
"sheetId": ###,
"startRowIndex": 0,
"endRowIndex": 5,
"startColumnIndex": 1,
"endColumnIndex": 2
}
]
}
},
"threeDimensional": true,
"pieHole": 0.5
},
"hiddenDimensionStrategy": "SKIP_HIDDEN_ROWS_AND_COLUMNS",
"titleTextFormat": {
"fontFamily": "Roboto"
},
"fontName": "Roboto"
},
"position": {
"overlayPosition": {
"anchorCell": {
"sheetId": ###,
"rowIndex": 1,
"columnIndex": 1
},
"offsetXPixels": 69,
"offsetYPixels": 17,
"widthPixels": 600,
"heightPixels": 371
}
}
}
从上面的图表对象中,发现不包括“切片标签”的属性。这样,当使用从图表中获取的值更新图表时,将删除“切片标签”。而且,“ UpdateChartSpecRequest”还没有用于设置“切片标签”的属性。这样,尚不能使用解决方法。不幸的是,这些是Google方面的当前规范。 Sheets API现在正在增长。因此,我相信这些属性将在将来的更新中添加。
我以为该问题的原因是由于未使用fields
属性更新“ updateChartSpec”。例如,当可以使用fields
属性时,只能更新图表标题。这样,即使当前“ UpdateChartSpecRequest”中不包含“切片标签”的属性,也只能更新图表标题。在这种情况下,您当前的问题将不会发生。因此,我已经在2020年5月28日的问题跟踪器中将此报告为将来的请求。Ref并且这已经被接受。因此,我认为Google可能会在不久的将来对此进行修改。