如何使用谷歌应用程序脚本将图表发布到网络上 [英] How to publish a chart to the web with google apps script

查看:117
本文介绍了如何使用谷歌应用程序脚本将图表发布到网络上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在电子表格上有一个EmbeddedChart,通常我会将其作为图像手动发布并添加到合流页面。通过这种方式,只要图表在电子表格中更新,它也会在汇合页面中更新。现在我试图自动创建用于创建合流页面的合流标记,但是我无法在创建合流标记的apps脚本中发布并获取EmbeddedChart网址。



有没有办法使用谷歌应用程序脚本在网上发布google spreasheet图表(图表 - >发布图表...->)?或者有没有办法获得发布的URL?

您可以使用 图表%20APIrel =nofollow>图表API 在您的html代码中创建图表。从那里您可以调用应用程序脚本从电子表格中检索信息或直接查询电子表格。

在以下示例中,您将调用api并在此情况下设置包是bar包。然后创建一个查询对象,然后您将查询设置为电子表格。



查询工作表后,我们将创建具有所需选项的图表,然后调用函数使用包含从查询和选项中获得的信息的参数data进行绘制。

这个Api为不同的图表提供了很多选项。我希望它有帮助。



< html> < HEAD> <! - 加载AJAX API - > < script type =text / javascriptsrc =https://www.google.com/jsapi>< / script> < script type =text / javascript> //加载Visualization API和控件包。 google.load(visualization,1.1,{packages:[bar]}); //设置一个回调函数,在加载Google Visualization API时运行。 google.setOnLoadCallback(drawDashboard); var columnChart =''; var dashboard ='';函数drawDashboard(){var query = new google.visualization.Query('< Spreadsheet URL>'); query.setQuery('select A,B,C'); query.send(handleQueryResponse); });}函数handleQueryResponse(response){if(response.isError()){alert('Error in query:'+ response.getMessage()+''+ response.getDetailedMessage());返回; } var data = response.getDataTable(); //创建一个列条形图,传递一些选项columnChart = new google.charts.Bar(document.getElementById('chart_div')); options = {width:600,height:400,chart:{legend:'right',title:'Summative Assessment Data'}} columnChart.draw(data,options); }< / script> < /头> <身体GT; < div id =chart_div>< / div> < / body>< / html>

I have an EmbeddedChart on a spreadsheet and usually I publish it manually as an image and add it to a confluence page. This way whenever the chart is updated in the spreadsheet, it is also updated in the confluence page. Now I'm trying to automate the creation of the confluence markup that is used to create the confluence page, but I'm not able to publish and get the EmbeddedChart url in the apps script that is creating the confluence markup.

Is there a way to publish a google spreasheet chart to the web (Chart->Publish Chart...->) using google apps script? Or is there a way to get the published URL?

解决方案

You can also use the Charts API to create the chart inside your html code. From there you can call apps script to retrieve the information from the spreadsheet or directly query the spreadsheet.

In the following example you would call the api and set the package in this case is the "bar" package. Then a query object is created and then you would set the query to the spreadsheet.

After querying the sheet, we will create the chart with the desired options and then call the function draw with the parameters "data" which contains the information obtained from the query and the options.

This Api gives a lot of options for different charts. I hope it helps.

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the controls package.
      google.load("visualization", "1.1", {packages:["bar"]});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawDashboard);

  var columnChart = '';
     var dashboard = '';
      function drawDashboard() {
         var query = new google.visualization.Query(
      '<Spreadsheet URL>');
      
      query.setQuery('select A,B,C');
      
      query.send(handleQueryResponse);
      }

      function handleQueryResponse(response) {
        if (response.isError()) {
          alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
          return;
        }

  var data = response.getDataTable();
   
        // Create a Column Bar chart, passing some options
         columnChart = new google.charts.Bar(document.getElementById('chart_div'));
        
          options= {
            width: 600,
            height: 400,
          chart:{
            legend: 'right',
            title: 'Summative Assessment Data'}
               }

        columnChart.draw(data, options);
      }
      
    </script>
  </head>
  <body>
  <div id="chart_div"></div>
          
  </body>
</html>

这篇关于如何使用谷歌应用程序脚本将图表发布到网络上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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