Google Sheet Pie Chart JS:切片偏移方法不起作用?

时间:2017-07-28 10:27:34

标签: google-apps-script google-sheets google-visualization pie-chart google-sheets-api

我花了很多时间试图弄清楚如何在Google表格中爆炸/拆分饼图/ (例如Using the slices setoption in Google Apps Scripthttp://fiddle.jshell.net/6d5fLwnm/4/ 这可以使用谷歌可视化

在谷歌工作表之外

e.g。饼形图     .setOption(' slices',Value)     例如{3:{offset:0.3};

但Google Chart Builder / Embedding的这种方法 在我的" google sheet指定的脚本中没有全部工作" (见下面的代码)

有关于此的任何想法/经验吗?以某种方式弃用了吗? (其他.setOption方法有效:例如颜色)

我的工作表有3列(因此选择B2:C5),4行,为测试目的而简化。 这是代码:

function GeneratePie() {  
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("B2:C5");  
var pie = sheet.newChart()
.setChartType(Charts.ChartType.PIE)
.addRange(range)
.setPosition(5,6 ,5, 5)
//.setTitle("This is the title of my chart")
.setOption('slices', {
  0: {offset: 0.05},
  1: {offset: 0.15},
  2: {offset: 0.25},
  3: {offset: 0.35}
})

.setOption('title', 'Updated!');

// another try
slicces[0] = '{offset: 0.2}'; 
pie.setOption('slices', slicces); // wrapper is the ChartWrapper */   
pie.setOption('title', 'Updated2!');
sheet.insertChart(pie.build());   

var chart = sheet.getCharts()[1];
chart = chart.modify()
.setOption('title', 'Updated ZZZZZZZ!')
.setPosition(5,6,6,6)
.setOption('slices', {
 0: {offset: 0.05},
 1: {offset: 0.15},
 2: {offset: 0.25},
 3: {offset: 0.35}
})

 .build();
sheet.updateChart(chart); 
}

欢迎所有评论......

谢谢!

1 个答案:

答案 0 :(得分:1)

来自Google Charts API的Visualization: Pie Chart的代码尚未与App Script版本完全互换。因此,我不认为它现在支持Apps脚本。

reverseCategories()是与切片相关的Apps脚本方法,并不是很多。