Index: usage/includes/pages.inc
===================================================================
--- usage/includes/pages.inc	(revision 2277)
+++ usage/includes/pages.inc	(working copy)
@@ -302,6 +302,7 @@
   $project_rows = array();
   foreach ($weeks as $week) {
     $project_rows[$week] = $blank_row;
+    $project_rows[$week][0]['timestamp'] = $week;
     $project_rows[$week][0]['data'] = format_date($week, 'custom', variable_get('project_usage_date_long', PROJECT_USAGE_DATE_LONG), 0);
   }
 
@@ -365,8 +366,14 @@
   $query = db_query("SELECT timestamp, count FROM {project_usage_week_release} WHERE nid = %d ORDER BY timestamp DESC", $node->nid);
   while ($row = db_fetch_object($query)) {
     $rows[] = array(
-      array('data' => format_date($row->timestamp, 'custom', variable_get('project_usage_date_long', PROJECT_USAGE_DATE_LONG), 0)),
-      array('data' => number_format($row->count), 'class' => 'project-usage-numbers'),
+      array(
+        'data' => format_date($row->timestamp, 'custom', variable_get('project_usage_date_long', PROJECT_USAGE_DATE_LONG), 0),
+        'timestamp' => $row->timestamp,
+      ),
+      array(
+        'data' => number_format($row->count),
+        'class' => 'project-usage-numbers',
+      ),
     );
   }
   $output = theme('project_usage_release_page', $project, $node, $header, $rows);
@@ -462,7 +469,7 @@
 }
 
 /**
- * Convert the usage table data into a Google Chart image.
+ * Convert the usage table data into a graph.
  *
  * First column should be the weeks, each subsequent column should be a data
  * series.
@@ -487,76 +494,47 @@
   // Pull the API versions from the table header for use as a legend. Since the
   // table is keyed strangely, make note of which tid is in which order so we
   // can efficiently iterate over the columns.
-  $legend = array();
+  $series = array();
   $mapping = array();
   foreach ($header as $tid => $cell) {
-    $legend[] = $cell['data'];
+    $series[] = array(
+      'label' => $cell['data'],
+    );
     $mapping[] = $tid;
   }
   // Drop the date column from the legend and mapping since it's the other axis.
-  unset($legend[0]);
+  unset($series[0]);
   unset($mapping[0]);
 
   // Rotate the table so each series is in a row in the array and grab the
   // dates for use as axis labels.
-  $series = array();
-  $date_axis = array();
   foreach (array_values($rows) as $i => $row) {
-    $date_axis[$i] = $row[0]['data'];
+    $timestamp = $row[0]['timestamp'];
     foreach ($mapping as $j => $tid) {
       // FIXME: The table values have commas in them from number_format(). We
       // need to remove them because we'll use commas to separate the values
       // in the URL string. It might be better to pass in clean number values
       // and format them here rather than have to uncook them.
-      $series[$j][$i] = (int) str_replace(',', '', $row[$tid]['data']);
+      $series[$j]['data'][] = array($timestamp * 1000, (int) str_replace(',', '', $row[$tid]['data']));
     }
   }
 
-  // Now convert the series into strings with the data. Along the way figure
-  // out the range of data.
-  $min = $max = 0;
-  $data = array();
-  foreach ($series as $s) {
-    $data[] = implode(',', $s);
-    $max = max($max, max($s));
-  }
-
-  // Round the max up to the next decimal place (3->10, 19->20, 8703->9000) so
-  // that the labels have round numbers and the entire range is visible. We're
-  // forced to build the number as a string because PHP's round() function
-  // can round down (3->0, not 3->10) and it returns floats that loose
-  // precision (causing 90,000 to display as 89,999.99). We pull off the first
-  // digit, add 1 to that, and then pad the rest with zeros.
-  $zeros = strlen($max) - 1;
-  $max = ($zeros > 0) ? (substr($max, 0, 1) + 1 . str_repeat('0', $zeros)) : 10;
-  $value_axis = range($min, $max, '1'. str_repeat('0', $zeros));
-
   // Might need more colors than this.
-  $colors = array('EDAA00', '0062A0', 'A17300', 'ED8200', '38B4BA', '215D6E');
+  $colors = array('#EDAA00', '#0062A0', '#A17300', '#ED8200', '#38B4BA', '#215D6E');
 
-  // The key values in this array are dictated by the Google Charts API:
-  // http://code.google.com/apis/chart/
-  $args = array(
-    // Chart title.
-    'chtt' => check_plain($title),
-    // Dimensions as width x height in pixels.
-    'chs' => '600x200',
-    // Chart type
-    'cht' => 'lc',
-    // Pick some colors.
-    'chco' => implode(',', array_slice($colors, 0, count($series))),
-    'chd' =>  't:'. implode('|', $data),
-    // Set the range of the chart
-    'chds' => implode(',', array_fill(0, count($series), $min .','. $max)),
-     // Legend is the header titles after excluding the date.
-    'chdl' => implode('|', $legend),
-  );
-  project_usage_chart_axis_labels($args, array(
-    'x' => project_usage_chart_label_subset($date_axis, 5),
-    'y' => array_map('number_format', project_usage_chart_label_subset($value_axis, 5)),
+  return theme('flot_graph', array('style' => 'width:100%; height:200px'), array_values($series), array(
+    'xaxis' => array(
+      'mode' => 'time',
+    ),
+    'colors' => $colors,
+    'series' => array(
+    ),
+    'legend' => array(
+      'show' => 1,
+      'position' => 'ne',
+      'noColumns' => 2,
+    ),
   ));
-
-  return theme('project_usage_chart', $args);
 }
 
 /**
@@ -601,24 +579,6 @@
 }
 
 /**
- * Convert the array of Google Chart paramters into an image URL.
- *
- * @param $args
- *   Array of key, value pairs to turn into a Google Charts image.
- * @return
- *   HTML image element.
- */
-function theme_project_usage_chart($args) {
-  $params = array();
-  foreach ($args as $key => $value) {
-    $params[] = $key .'='. $value;
-  }
-  // If the chart has a title use that for the image's alt and title values.
-  $title = empty($args['chtt']) ? '' : $args['chtt'];
-  return theme('image', 'http://chart.apis.google.com/chart?'. implode('&', $params), $title, $title, NULL, FALSE);
-}
-
-/**
  * Begin crap old project code.
  *
  * This is old project module code that project_usage is still leveraging.
