 							i--;
 						}
 					}
-					
 					coefficients.reverse();
-
+					
+					getCallbackCollection(this).triggerCallbacks();	
+				}
+				
+				if (currentTrendline.value == EXPONENTIAL)
+				{
+					
+				}
+				
+				if (currentTrendline.value == POWER)
+				{
+					
+				}
+				
+				if (currentTrendline.value == LOGARITHMIC)
+				{
+					
+					
+				}
+			}
+		}
+		
+		private function handleLinearRegressionFault(event:FaultEvent, token:Object = null):void
+		{
+			if (this.requestID != int(token))
+			{
+				// ignore outdated results
+				return;
+			}
+			
+			reportError(event);
+			intercept = NaN;
+			slope = NaN;
+			coefficients = null;
+			getCallbackCollection(this).triggerCallbacks();
+		}
+		
+		public function getSlope():Number { return slope; }
+		public function getIntercept():Number { return intercept; }
+		public function getCoefficients():Array { return coefficients; }
+		
+		private var intercept:Number = NaN;
+		private var slope:Number = NaN;
+		private var rSquared:Number = NaN;
+		private var coefficients:Array = null;
+		
+		private var tempRange:Range = new Range();
+		private var tempPoint:Point = new Point();
+		private var tempPoint2:Point = new Point();
+
+		override public function drawBackground(dataBounds:IBounds2D, screenBounds:IBounds2D, destination:BitmapData):void
+		{
+			var g:Graphics = tempShape.graphics;
+			g.clear();
+			
+			if(currentTrendline.value == LINEAR)
+			{
+				g.clear();
+				if(!isNaN(intercept))
+				{
+					tempPoint.x = dataBounds.getXMin();
+					tempPoint2.x = dataBounds.getXMax();
+					
+					tempPoint.y = (slope*tempPoint.x)+intercept;
+					tempPoint2.y = (slope*tempPoint2.x)+intercept;
+					
+					tempRange.setRange( dataBounds.getYMin(), dataBounds.getYMax() );
+					
+					// constrain yMin to be within y range and derive xMin from constrained yMin
+					tempPoint.x = tempPoint.x + (tempRange.constrain(tempPoint.y) - tempPoint.y) / slope;
+					tempPoint.y = tempRange.constrain(tempPoint.y);
+					
+					// constrain yMax to be within y range and derive xMax from constrained yMax
+					tempPoint2.x = tempPoint.x + (tempRange.constrain(tempPoint2.y) - tempPoint.y) / slope;
+					tempPoint2.y = tempRange.constrain(tempPoint2.y);
+					
+					dataBounds.projectPointTo(tempPoint,screenBounds);
+					dataBounds.projectPointTo(tempPoint2,screenBounds);
+					lineStyle.beginLineStyle(null,g);
+					//g.lineStyle(lineThickness.value, lineColor.value,lineAlpha.value,true,LineScaleMode.NONE);
+					g.moveTo(tempPoint.x,tempPoint.y);
+					g.lineTo(tempPoint2.x,tempPoint2.y);
+					
+					destination.draw(tempShape);
+				}
+			}	
+			else if (currentTrendline.value == POLYNOMIAL)
+			{
+				points = new Vector.<Number>;
+				drawCommand = new Vector.<int>;
+				var previousPoint:Point = null;
+				
+				if (coefficients != null)
+				{
+//					// ToDo Use screenBounds to determine how many points should be drawn
+//					var flag:Boolean = true;
+//					 for (var x:int = dataBounds.getXMin(); x <= dataBounds.getXMax(); x++)
+//					 {
+//						tempPoint.x = x;
+//						tempPoint.y = polynomial(coefficients, x);
+//						dataBounds.projectPointTo(tempPoint, screenBounds);
+//						points.push(tempPoint.x);
+//						points.push(tempPoint.y);
+//						
+//						if (flag == true)
+//						{
+//							drawCommand.push(1);
+//							flag = false;
+//						}
+//						else if (screenBounds.containsPoint(previousPoint) && screenBounds.containsPoint(tempPoint))
+//							drawCommand.push(2);
+//						else
+//							drawCommand.push(1);
+//						
+//						previousPoint = tempPoint.clone();
+//					}
+//
+//					g.lineStyle(1);
+//					g.drawPath(drawCommand, points);					
+//					
+//					destination.draw(tempShape);
+					
+					
+					
+					// Draw lines for every 3 pixels
+					var numberOfPoint:Number = Math.floor(screenBounds.getXCoverage() / 3);
+					var increment:Number = dataBounds.getXCoverage() / numberOfPoint;
 					var flag:Boolean = true;
-					 for (var x:int = dataBounds.getXMin(); x < dataBounds.getXMax(); x++)
-					 {
+					for (var x:Number = dataBounds.getXMin(); x <= dataBounds.getXMax(); x = x + increment)
+					{
 						tempPoint.x = x;
 						tempPoint.y = polynomial(coefficients, x);
 						dataBounds.projectPointTo(tempPoint, screenBounds);

							drawCommand.push(1);
							flag = false;
						}
//						else if (tempPoint.y > screenBounds.getYMax() || tempPoint.y < screenBounds.getYMin())
//							drawCommand.push(1);
						else drawCommand.push(2);
					}

					g.lineStyle(1);
					g.drawPath(drawCommand, points);					
					

	import flash.geom.Point;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ArrayUtil;
	
	import weave.Weave;
	import weave.api.WeaveAPI;
	import weave.api.disposeObjects;
	import weave.api.getCallbackCollection;
	import weave.api.newLinkableChild;
