title: How to update or manage Annotated Time Line chart through google spreadsheet app's custom code?
body: <p>I am working on a spreadsheet of me at google spreadsheet. <a href="https://docs.google.com/spreadsheet/ccc?key=0At2D9TJiKMY3dDlfRDhGY1I0R1dIX2NvOVFST0w0LWc#gid=3" rel="nofollow">You can visit it here</a>. </p>
  
  <p>If you visit the page you will see 2 charts at the current sheet (Graph Input). The first one is the embedded one and the last or below one is the <code>"Annotated Time Line"</code>. Now, I have got a script (by googling) to automatically update the chart whenever the spreadsheet's rows are edited. By adding and submitting inputs to <a href="https://docs.google.com/spreadsheet/viewform?formkey=dDlfRDhGY1I0R1dIX2NvOVFST0w0LWc6MA#gid=3" rel="nofollow">this form</a> you can add some data/row to the spreadsheet. The inputs will be automatically added to the spreadsheet.</p>
  
  <p>Now when i trigger or run the script <strong>(<code>onEdit</code> function)</strong> then only the first or top chart is getting updated. But the 2nd or below one is not updating.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>function onEdit() {
    var s = SpreadsheetApp.getActiveSheet();
    var c = s.getCharts();
  
    for (var i in c) {
      var ch = c[i];
      var ranges = ch.getRanges();
      var mod = ch.modify();
      for (var j in ranges) {
        var range = ranges[j];
        mod.removeRange(range);
        var newRange = expandRange_(range);
        mod.addRange(newRange);
      }
      s.updateChart(mod.build());
    }
  }
  
  function rangeShouldExpand_(range) {
    var s = range.getSheet();
    var numCol = range.getNumColumns()
    var values = s.getSheetValues(range.getLastRow(), range.getColumn(), 2, numCol);
  
    for (var i = 0; i &lt; numCol; i++) {
      if (!values[0][i] &amp;&amp; !values[1][i] || !!values[0][i] &amp;&amp; !!values[1][i]) {
        continue;
      } else {
        return false;
      }
    }
    return true;
  }
  
  function expandRange_(range) {
    var s = range.getSheet()
    var startRow = range.getRow();
    var startCol = range.getColumn();
    var numRows = range.getNumRows();
    var numCols = range.getNumColumns();
    while (rangeShouldExpand_(range)) {
      numRows++;
      range = s.getRange(startRow, startCol, numRows, numCols);
    }
    return range;
  }
  </code></pre>
  
  <p>Now, what should i do or what changes should i make to get the both charts working?</p>
  
  <p>Thanks,
  Omar Sharif</p>