diff --git a/flot.module b/flot.module
index 84c5b64..08db153 100644
--- a/flot.module
+++ b/flot.module
@@ -52,6 +52,7 @@ function flot_theme() {
  */
 function theme_flot_graph(&$variables, $loader = FALSE) {
   static $n;
+  
   $element = array();
   if (isset($variables['element'])) {
     $element = $variables['element'];
@@ -62,7 +63,7 @@ function theme_flot_graph(&$variables, $loader = FALSE) {
     $data = $variables['data'];
   }
 
-  $options = array();
+  $options = new stdClass();
   if (isset($variables['options'])) {
     $options = $variables['options'];
   }
@@ -77,17 +78,23 @@ function theme_flot_graph(&$variables, $loader = FALSE) {
   }
  
   if (isset($options->legend) && !isset($options->legend->container)) {
-    $variables['element']['legendid'] = $element['id'] . '-legend';
-    $variables['options']->legend->container = '#' . $variables['element']['legendid'];
+    $element['legendid'] = $element['id'] . '-legend';
+    $options->legend->container = '#' . $element['legendid'];
+    $legend = '<div id="'.$element['legendid'].'"></div>';
+  } else {
+    $legend = '';
   }
 
   flot_add_js('core');
   if (isset($options->selection)) {
     flot_add_js('selection');
   }
-  if (isset($options->bars->stack)) {
+  if (isset($options->series->bars->stack)) {
     flot_add_js('stack');
   }
+  if ($options->series->pie->show) {
+    flot_add_js('pie');
+  }
   foreach ($data as $s => $serie) {
     if (isset($serie->stack)) {
       flot_add_js('stack');
@@ -111,7 +118,7 @@ function theme_flot_graph(&$variables, $loader = FALSE) {
   ';
   drupal_add_js($data, array('type' => 'inline', 'scope' => 'footer'));
 
-  return '<div ' . drupal_attributes($variables['element']) . '> </div>';
+  return '<div ' . drupal_attributes($element) . '> </div>'.$legend;
 }
 
 /**
@@ -143,6 +150,10 @@ function flot_add_js($type = 'core') {
     drupal_add_js($path . '/jquery.flot.stack.js');
     $added['stack'] = TRUE;
   }
+  if (!isset($added['pie']) && $type = 'pie') {
+    drupal_add_js($path . '/jquery.flot.pie.js');
+    $added['pie'] = TRUE;
+  }
   if (!isset($added['selection']) && $type = 'selection') {
     drupal_add_js($path . '/jquery.flot.selection.js');
     $added['selection'] = TRUE;
@@ -157,15 +168,15 @@ function flot_add_js($type = 'core') {
 class flotData {
 
   public $data;
-  public $lines;
-  public $bars;
-  public $points;
+  public $series;
 
   function __construct($data) {
     $this->data = $data;
-    $this->lines = new stdClass();
-    $this->bars = new stdClass();
-    $this->points = new stdClass();
+    $this->series = new stdClass();
+    $this->series->lines = new stdClass();
+    $this->series->bars = new stdClass();
+    $this->series->points = new stdClass();
+    $this->series->pie = new stdClass();
     $this->grid = new stdClass();
   }
 
@@ -180,18 +191,19 @@ class flotStyle {
 
   // Use flot's default colors: public $colors;
   public $grid;
-  public $lines;
-  public $bars;
-  public $points;
+  public $series;
 
   function __construct() {
-    $this->lines = new stdClass();
-    $this->bars = new stdClass();
-    $this->points = new stdClass();
+    $this->series = new stdClass();
+    $this->series->lines = new stdClass();
+    $this->series->bars = new stdClass();
+    $this->series->points = new stdClass();
+    $this->series->pie = new stdClass();
 
-    $this->lines->show = FALSE;
-    $this->bars->show = FALSE;
-    $this->points->show = FALSE;
+    $this->series->lines->show = FALSE;
+    $this->series->bars->show = FALSE;
+    $this->series->points->show = FALSE;
+    $this->series->pie->show = FALSE;
 
     // Use flot's default colors: $this->colors = array('#666', '#999', '#ccc');
     $this->shadowSize = 0;
@@ -235,9 +247,9 @@ class flotStyleLine extends flotStyle {
 
   function __construct() {
     parent::__construct();
-    $this->lines->show = TRUE;
-    $this->lines->lineWidth = 1;
-    $this->lines->fill = .1;
+    $this->series->lines->show = TRUE;
+    $this->series->lines->lineWidth = 1;
+    $this->series->lines->fill = .1;
   }
 
 }
@@ -249,9 +261,9 @@ class flotStyleBar extends flotStyle {
 
   function __construct() {
     parent::__construct();
-    $this->bars->show = TRUE;
-    $this->bars->lineWidth = 0;
-    $this->bars->fill = .5;
+    $this->series->bars->show = TRUE;
+    $this->series->bars->lineWidth = 0;
+    $this->series->bars->fill = .5;
   }
 
 }
@@ -263,9 +275,21 @@ class flotStylePoint extends flotStyle {
 
   function __construct() {
     parent::__construct();
-    $this->points->show = TRUE;
-    $this->points->lineWidth = 1;
-    $this->points->fill = .1;
+    $this->series->points->show = TRUE;
+    $this->series->points->lineWidth = 1;
+    $this->series->points->fill = .1;
+  }
+
+}
+
+/**
+ * Basic pie style class for the flot.
+ */
+class flotStylePie extends flotStyle {
+
+  function __construct() {
+    parent::__construct();
+    $this->series->pie->show = TRUE;
   }
 
 }
diff --git a/views/flot_fields_views_plugin_style.inc b/views/flot_fields_views_plugin_style.inc
index 25f039f..3bcd8ba 100644
--- a/views/flot_fields_views_plugin_style.inc
+++ b/views/flot_fields_views_plugin_style.inc
@@ -15,7 +15,7 @@ class flot_fields_views_plugin_style extends views_plugin_style {
     $form['type'] = array(
       '#type' => 'select',
       '#title' => t('Graph type'),
-      '#options' => array('line' => t('Line'), 'bar' => t('Bar'), 'point' => t('Point')),
+      '#options' => array('line' => t('Line'), 'bar' => t('Bar'), 'point' => t('Point'), 'pie' => t('Pie chart')),
       '#description' => t("Choose the type of chart you would like to display."),
       '#default_value' => $this->options['type'],
     );
@@ -237,10 +237,11 @@ class flot_fields_views_plugin_style extends views_plugin_style {
           foreach ($fields as $field => $info) {
             if ($info) {
               // datetime fields need special care
+              // TODO: Also handle datetime for the Y axis, not just the X axis
               if (isset($fieldx->options['date_format'])) {
                 $datapoint = array(
                   $row->{$fieldx->field_alias} * 1000,
-                  $row->{"count"},
+                  $row->{$info->field_alias}
                 );
               }
               else {
@@ -249,10 +250,10 @@ class flot_fields_views_plugin_style extends views_plugin_style {
                 }
                 $datapoint = array(
                   array_shift(array_keys($ticks, $row->{$fieldx->field_alias})),
-                  $row->{"count"},
+                  $row->{$info->field_alias},
                 );
               }
-              $series[$row->{$info->field_alias}][] = $datapoint;
+              $series[$row->{$fieldx->field_alias}][] = $datapoint;
             }
           }
         }
@@ -293,6 +294,9 @@ class flot_fields_views_plugin_style extends views_plugin_style {
       case 'bar':
         $style = new flotStyleBar();
         break;
+      case 'pie':
+        $style = new flotStylePie();
+        break;
       case 'line':
       default:
         $style = new flotStyleLine();
@@ -302,8 +306,8 @@ class flot_fields_views_plugin_style extends views_plugin_style {
     // force time mode for timestamp data
     if (isset($fieldx->options['date_format'])) {
       $style->xaxis->mode = 'time';
-      $style->lines->fill = FALSE;
-      $style->points->show = TRUE;
+      $style->series->lines->fill = FALSE;
+      $style->series->points->show = TRUE;
     }
     else {
       $min = 0;
@@ -316,9 +320,9 @@ class flot_fields_views_plugin_style extends views_plugin_style {
       $style->axis_ticks('xaxis', $ticklabels);
       $style->xaxis->min = $min - 1;
       $style->xaxis->max = $max + 1;
-      if ($style->bars->show) {
-        $style->bars->barWidth = 0.4;
-        $style->bars->align = 'center';
+      if ($style->series->bars->show) {
+        $style->series->bars->barWidth = 0.4;
+        $style->series->bars->align = 'center';
       }
     }
     
@@ -330,7 +334,6 @@ class flot_fields_views_plugin_style extends views_plugin_style {
     else {
       $style->legend->show = FALSE;
     }
-    
     $vars['options'] = $style;
   }
 }
diff --git a/views/flot_views_plugin_style.inc b/views/flot_views_plugin_style.inc
index fad2d84..924be60 100644
--- a/views/flot_views_plugin_style.inc
+++ b/views/flot_views_plugin_style.inc
@@ -15,7 +15,7 @@ class flot_views_plugin_style extends views_plugin_style {
     $form['type'] = array(
       '#type' => 'select',
       '#title' => t('Graph type'),
-      '#options' => array('line' => t('Line'), 'bar' => t('Bar'), 'point' => t('Point')),
+      '#options' => array('line' => t('Line'), 'bar' => t('Bar'), 'point' => t('Point'), 'pie' => t('Pie chart')),
       '#description' => t("Choose the type of chart you would like to display."),
       '#default_value' => $this->options['type'],
     );
@@ -143,6 +143,9 @@ class flot_views_plugin_style extends views_plugin_style {
       case 'bar':
         $style = new flotStyleBar();
         break;
+      case 'pie':
+        $style = new flotStylePie();
+        break;
       case 'line':
       default:
         $style = new flotStyleLine();
diff --git a/views/flot_views_plugin_summary_style.inc b/views/flot_views_plugin_summary_style.inc
index 2690136..5d13da0 100644
--- a/views/flot_views_plugin_summary_style.inc
+++ b/views/flot_views_plugin_summary_style.inc
@@ -60,6 +60,9 @@ class flot_views_plugin_summary_style extends flot_views_plugin_style {
       case 'bar':
         $style = new flotStyleBar();
         break;
+      case 'pie':
+        $style = new flotStylePie();
+        break;
       case 'line':
       default:
         $style = new flotStyleLine();
