在Google Apps脚本中使用片段设置选项 [英] Using the slices setoption in Google Apps Script

查看:120
本文介绍了在Google Apps脚本中使用片段设置选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌图表服务进行一些测试,并且我正试图展开我的饼图的某些片段。然而,这不是我想要的。



我的数据源是一个范围A1:B30,当我尝试在范围内爆炸时,举例来说,前4个切片,我认为这将做到这一点:

  setOption('slices',['0 ',{offset:0.75},'1',{offset:0.75},'2',{offset:0.75},
'3',{offset:0.75},'4',{offset:0.75 }])

然而,这似乎并不奏效 - p>



这很奇怪 - 它有什么关系吗?两个元素(范围中的A和B列值)??这可以解释,如果模式总是跳过一片,但有一点跳过 - 奇怪!任何建议?

祝愿

Dave

解决方案

可以使用几个选项来定义切片



一个对象( {} )与每个切片的命名键

  pieChart .setOption('slices',{
0:{offset:0.05},
1:{offset:0.15},
2:{offset:0.25},
3: {offset:0.35}
});

或数组( [] )每片的对象

  pieChart.setOption('slices',[
{offset:0.05},
{抵消:0.15},
{抵消:0.25},
{抵消:0.35}
]);

每个代码都与代码有所不同,请参阅以下工作代码片段...



google.charts.load('current',{callback:function(){var data ='google'visualization.arrayToDataTable([['语言','Speakers(百万)'],['Assamese',13],['Bengali',83],['Bodo',14] ,''古吉拉特'',46],['印地语',300],['卡纳达',38],['Kashmiri',5.5],['Konkani',5],['Maithili',20 ],['Malayalam',33],['Manipuri',1.5],['Marathi',72],['Nepali',2.9],['Oriya',33],['Punjabi',29], ['Sanskrit',0.01],['Santhali',6.5],['Sindhi',2.5],['泰米尔',61],['泰卢固语',74],['乌尔都语',52]]) var pieC hart = new google.visualization.ChartWrapper({chartType:'PieChart',containerId:'chart_div',dataTable:data,options:{height:400,width:400}}); pieChart.setOption('slices',{0:{offset:0.05},1:{offset:0.15},2:{offset:0.25},3:{offset:0.35}}); pieChart.draw(); },packages:['controls','corechart']}); <$ code>

 < script src =https://www.gstatic.com/charts/loader.js>< / script>< div id =chart_div>< / div> code> 


I'm doing some testing with Google Charts service, and I'm trying to explode certain slices of my piechart. However, this isn't working as I'd hoped.

My data source is a range A1:B30, and when I try to explode a range within it, for example the first 4 slices, I'd have thought this would do the trick:

setOption('slices',['0',{offset: 0.75},'1',{offset: 0.75},'2',{offset: 0.75},
                        '3',{offset: 0.75},'4',{offset: 0.75}])

However, that doesn't seem to work - I end up with this:

It's weird - Has it got something to do with there being two elements (the A and B column values in the range) ?? That would explain if the pattern was it always skipped one slice, but at one point it skips two - strange! Any advice?

best wishes

Dave

解决方案

there are a couple options for defining slices

you can use an object ({}) with named keys for each slice

pieChart.setOption('slices', {
  0: {offset: 0.05},
  1: {offset: 0.15},
  2: {offset: 0.25},
  3: {offset: 0.35}
});

or an array ([]) of objects for each slice

pieChart.setOption('slices', [
  {offset: 0.05},
  {offset: 0.15},
  {offset: 0.25},
  {offset: 0.35}
]);

each a little different from the code in question, see following working snippet...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Language', 'Speakers (in millions)'],
      ['Assamese', 13], ['Bengali', 83], ['Bodo', 14],
      ['Dogri', 23], ['Gujarati', 46], ['Hindi', 300],
      ['Kannada', 38], ['Kashmiri', 5.5], ['Konkani', 5],
      ['Maithili', 20], ['Malayalam', 33], ['Manipuri', 1.5],
      ['Marathi', 72], ['Nepali', 2.9], ['Oriya', 33],
      ['Punjabi', 29], ['Sanskrit', 0.01], ['Santhali', 6.5],
      ['Sindhi', 2.5], ['Tamil', 61], ['Telugu', 74], ['Urdu', 52]
    ]);

    var pieChart = new google.visualization.ChartWrapper({
      chartType: 'PieChart',
      containerId: 'chart_div',
      dataTable: data,
      options: {
        height: 400,
        width: 400
      }
    });

    pieChart.setOption('slices', {
      0: {offset: 0.05},
      1: {offset: 0.15},
      2: {offset: 0.25},
      3: {offset: 0.35}
    });

    pieChart.draw();
  },
  packages:['controls', 'corechart']
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

这篇关于在Google Apps脚本中使用片段设置选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆