title: Plotting graph with FLOT using mysql and ajax
body: <p>I am trying to use flot to plot some data that is pulled from a MySQL db. I am log users login visits and I have a SQL function that will retreive the number of visits per day for a given month, getStats($day). I have read some examples online how to properly do this but for some reason when I try and graph the array data in my javascript file ' it comes up empty --> 'data: '. Below is my code. I am using the CI framework so if there are some questions about my code it is most likely because of that. I have hardcoded data in and it works fine. Any help on this matter would be appreciated there is not much about using flot with databases out there currently. </p>
  
  <p>Model---> metrics.php</p>
  
  <pre><code>function showUsers() {
  
      //get the number of days in the current month and the first day
      $num_days = cal_days_in_month(CAL_GREGORIAN, date(m), date(Y));
      $first_day = strtotime(date('Y').'-'.date('m').'-01');
  
      //iterate through all of the days
      while( $i &lt; $num_days ) {
  
           //get the user visits for each day of the month
           $log = $this-&gt;db-&gt;getStats($first_day);
  
           //add +1 day to the current day
           $first_day += 86400;
           $flot_visits[] = '['.($first_day*1000).','.$log-&gt;fields['total'].']';
           $i++;
      }
  
      //format in acceptable format for flot
      $content['visits'] = '['.implode(',',$flot_visits).']';
  
      //load the view and pass the array
      $this-&gt;load-&gt;vars($content);
      $this-&gt;load-&gt;view('metrics/user_metrics', $content);
  }
  </code></pre>
  
  <p>View ---> user_metrics.php</p>
  
  <pre><code> &lt;div id ="visits_graph" style="width:600px; height:300px"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Javascript ---> user_metrics.js</p>
  
  <pre><code>function metrics() {
  
     $.ajax({
              type: "POST",
              url: pathurl + "metrics/showUsers",
              data: "",
              success: function(data) {
                     graph_visits();
              }
           });
  }
  
  function graph_visits() {
  
       $.plot($('#visits_graph'), [
           { label: 'Visits', data: &lt;?php echo $visits ?&gt; }
           ], {
                 xaxis: {
                           mode: "time",
                           timeformat: "%m/%d/%y"
                        },
                 lines: { show: true },
                 points: { show: true },
                 grid: { backgroundColor: #fffaff' }
           });
  }
  </code></pre>