title: Creating chart with Apps Script fails to be inserted into spreadsheet
body: <p>The goal here to programmatically create a chart from a pre-existing data, when a Spreadsheet has loaded.</p>
  
  <p>The <a href="https://google-developers.appspot.com/apps-script/reference/spreadsheet/embedded-chart" rel="nofollow">documentation for the EmbeddedChart class</a> has two examples, both modifying existing  charts, and, as I require, creating a new one:</p>
  
  <pre class="lang-js prettyprint-override"><code>function newChart(range, sheet){
     var sheet = SpreadsheetApp.getActiveSheet();
     var chartBuilder = sheet.newChart();
     chartBuilder.addRange(range)
         .setChartType(Charts.ChartType.Line)
         .setOption('title', 'My Line Chart!');
     sheet.insertChart(chartBuilder.build());
   }
  </code></pre>
  
  <p><strong>Google example is missing:</strong> <code>.setPosition()</code></p>
  
  <p>I've tried implementing this function, as so:</p>
  
  <pre class="lang-js prettyprint-override"><code>function makeChart(sheet, range) {
    Logger.log('MAKING CHART');  
    var chart = sheet.newChart();
    chart.addRange(range)
      .setChartType(Charts.ChartType.BAR)
      .setOption('title','I love Google Apps Script');
    sheet.insertChart(chart.build());
  }
  </code></pre>
  
  <p>Where sheet and range are defined as:</p>
  
  <pre class="lang-js prettyprint-override"><code>var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange("C1:D16");
  </code></pre>
  
  <p><code>makeChart()</code> is called from <code>onOpen()</code>, which I can see is being executed. Despite this, the chart never appears in the spreadsheet.</p>
  
  <p>I've noticed nothing will be logged after the <code>.build()</code> method has been called, but there's little in the docs about this method, beyond stating that it must be called after making a chart.</p>
  
  <p>Edit: The script fails because <code>.insertChart()</code> expects an <code>EmbeddedChart</code> object, but is given an <code>EmbeddedChartBuilder</code>. The <code>.build()</code> method, according to the docs, should return an EmbeddedChart. But it doesn't.</p>