title: Using Google Analytics (G)API and Google Visualization - Showing data, but from the wrong month
body: <p>I finally wrote a script to get Google Analytics data then insert it into the Google Visualization API to create a graph like on the actual GA website. But for some reason the results on the graph are perfectly right, but the date associated with the number of visitors in this case is always a month ahead. For example today I had 10 visitors (March 29th) and it shows that, but when I hover over it, it says April 29th.</p>
  
  <p>I'm using the default PHP (G)API. The code's a bit long-winded, but it shouldn't be hard to understand.</p>
  
  <p>Any help is appreciated!</p>
  
  <pre><code>try {
      // create an instance of the GoogleAnalytics class using your own Google {email} and {password}
      $ga = new gapi($settings_data-&gt;analytics_username, $settings_data-&gt;analytics_password);
  
      $curr_date = date("Y-m-d", time());
  
      $new_date = strtotime('-1 month', strtotime($curr_date));
  
      // set the Google Analytics profile you want to access - format is 'ga:123456';
      $report = $ga-&gt;requestReportData($settings_data-&gt;analytics_profile_id, array('year', 'month', 'day'),array('visits'), null, null, date("Y-m-d", $new_date), $curr_date);
  
      //echo '&lt;p&gt;Total pageviews: ' . $ga-&gt;getPageviews() . ' total visits: ' . $ga-&gt;getVisits() . '&lt;/p&gt;';
  
  } catch (Exception $e) { 
      print 'Error: ' . $e-&gt;getMessage();
  
      echo '&lt;p&gt;If you have not yet set your Google Analytics account information in the settings panel, you will see an error here.&lt;/p&gt;';
  }
  ?&gt;
  
  &lt;?php
  
  $j_input = "";
  
  foreach ($ga-&gt;getResults() as $result) { 
  
      $date = explode(' ', $result);
  
      $visits = $result-&gt;getVisits();
  
      $j_input .= "[new Date($date[0], $date[1], $date[2]), $visits],";
  
      $output = substr($j_input, 0, -1);
  
  } ?&gt;
  
  &lt;script type='text/javascript' src='https://www.google.com/jsapi'&gt;&lt;/script&gt;
  
  
  &lt;script type='text/javascript'&gt;
      google.load('visualization', '1', {'packages':['annotatedtimeline']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
          var data = new google.visualization.DataTable();
          data.addColumn('date', 'Date');
          data.addColumn('number', 'Visits');
  
          data.addRows([
              &lt;?php echo $output; ?&gt;
          ]);
  
          var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('analytics'));
          chart.draw(data, {displayAnnotations: true});
      }
  &lt;/script&gt;
  
  &lt;div id="analytics" style="width: 100%; height: 200px;"&gt;&lt;/div&gt;
  </code></pre>