⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zoomablelinechart.as

📁 FLASH实现的可根据图例个数自动缩放图表宽度组件
💻 AS
📖 第 1 页 / 共 2 页
字号:
		
		// Increment for sublines
		var loopCount:Number = (numSteps * 2);
		var layoutIncrement:Number = (h / loopCount);
		var layoutY:Number = topPadding;
		var currentStep:Number = upperBoundary;//step * numSteps;
		
		var lineX:Number = 50-(leftBlockW*2);
		var labelX:Number = 50-(leftBlockW*2);
		for (var i:Number=0; i<(loopCount+1); i++)
		{
			var markerLabelName:String = "label" + i + "_txt";
			var markerLabel:String = numberPrefix + String(currentStep) + numberPostfix;
			var lineY:Number = Math.round(layoutY - 0.5);
			var labelY:Number = Math.round(layoutY - 8);
			
			if (i%2 == 0)
			{
				// Draw label
				vAxis_mc.createTextField(markerLabelName, vAxis_mc.getNextHighestDepth(), labelX, labelY, 0, 10);
				var o:TextField = vAxis_mc[markerLabelName];
				o.text = markerLabel;
				o.autoSize = "right";
				o.selectable = false;
				o.setTextFormat(labelFormat);
				
				if (currentStep!=lowerBoundary)
				{
					var lineW:Number = (w-lineX);
				}
				else
				{
					var lineW:Number = leftBlockW;
				}
				
				// Draw full line
				drawRoundRect(vAxis_mc, lineX, lineY, lineW, 1, 0, 0xEEEEEE, 100);
				
				// Decrement step
				currentStep -= step;
			}
			// Draw line on left block
			drawRoundRect(vAxis_mc, 50-leftBlockW, lineY, leftBlockW, 1, 0, 0xFFFFFF, 100);
			
			// Increment layoutY
			layoutY += layoutIncrement;
		}
		
		/*
		Line boundaries:
		x: 50,             
		y: topPadding      
		w: w-50            
		h: h               
		*/
		
		var dif:Number = upperBoundary - lowerBoundary;
		
		var lowerBoundaryEquivalentPlotY:Number = -((h * lowerBoundary) / dif);
		var upperBoundaryEquivalentPlotY:Number = -((h * upperBoundary) / dif); // h/dif = ?/upperBoundary || h*upperBoundary=dif*? || ?=(h*upperBoundary)/dif;
		
		var plotOffset:Number = topPadding - upperBoundaryEquivalentPlotY;
		//trace("plotOffset: " + plotOffset + " - lower: " + lowerBoundaryEquivalentPlotY + " - upper: " + upperBoundaryEquivalentPlotY + " - h: " + h);
		
		// Declare function to get plotY
		var getPlotY:Function = function(plotNumber:Number):Number
		{
			return plotOffset + (-((h * plotNumber) / dif));
		}
		
		// ----------------------------
		// Finally ready to plot values
		// ----------------------------
		
		var lineThickness:Number = 3;
		var dropShadowColor:Number = 0x666666;
		var dropShadowAlpha:Number = 50;
		var dropShadowOffset:Number = 2;
		
		var lastPlotX:Number;
		var lastPlotY:Number;
		
		var w:Number = width;
		var numMarkers:Number = __hPoints.length;
		var sectionW:Number = w / (numMarkers - 1);
		
		for (var i:Number=0; i<__lines.length; i++)
		{
			var tempLine:Object = __lines[i];
			var linePoints:Array = tempLine.points;
			var lineLabel:String = tempLine.label;
			var tempLineColor:Number = tempLine.color;
			
			
			
				
			// Loop thru points to plot - DROP SHADOW THIS TIME
			
			vAxis_mc.lineStyle(lineThickness, dropShadowColor, dropShadowAlpha);
			for (var j:Number=0; j<linePoints.length; j++)
			{
				var tempPlotValue:Number = linePoints[j];
				/*Added by Roland Zhu 2006.9.20 
				 *Skip the drawing operations when this point has no value 
				 */
				if(isNaN(tempPlotValue)) continue;
				// Prepare layout values - reference hPoints position
				/*Modified by Roland Zhu 2006.9.19
				 *Get the index of the h point by the field "id"(in initialize time, use the index to indicate the "id"), rather
				 *than use the absolute index "j", so the point id which got from __lines can absent, but not all of point id
				 */
				 var tpIndex:Number = j;
				 for(var p=0;p<__hPoints.length;p++){
					
					 if(j == Number(__hPoints[p].id)){
						 tpIndex = p;
					 }
					
				 }
				 
				//var tempPlotX:Number = __hPoints[j].hAxisX;
				var tempPlotX:Number = (__startPointXLeftAlign) ? __hPoints[tpIndex].hAxisX : __hPoints[tpIndex].hAxisX + sectionW/2;
				
				var tempPlotY:Number = getPlotY(tempPlotValue);
				var breakPointFlag:Boolean = false;
				//loop through all the breakpoint to check if current point is a breakpoint.
				for(var m = 0;m <__breakPoints.length;m++){
					if(j == Number(__breakPoints[m])){
						breakPointFlag = true;	//The previous point is a breakpoint, so flag it to control the drawing operations
						break;
					}
				}
				
				if (j!=0 && !breakPointFlag)
				{
					// Actually draw drop shadow if not first item
					
					// vAxis_mc.moveTo(lastPlotX, lastPlotY + dropShadowOffset);
					
					//vAxis_mc.lineTo(tempPlotX, tempPlotY + dropShadowOffset);
					//Modified by Roland Zhu 7.31.2006
					//Movie the dot to the center of the section
					
					vAxis_mc.lineTo(tempPlotX , tempPlotY + dropShadowOffset);
				}
				if(breakPointFlag || j==0)
				{
					// Move to starting position for dropshadow
					
					vAxis_mc.moveTo(tempPlotX , tempPlotY + dropShadowOffset);
					
				}
				
				lastPlotX = tempPlotX;
				lastPlotY = tempPlotY;
			}
			
			// Loop thru points to plot - ACTUAL LINE THIS TIME
			
			vAxis_mc.lineStyle(lineThickness, tempLineColor, 100);
			for (var j:Number=0; j<linePoints.length; j++)
			{
				var tempPlotValue:Number = linePoints[j];
				/*Added by Roland Zhu 2006.9.20 
				 *Skip the drawing operations when this point has no value 
				 */
				if(isNaN(tempPlotValue)) continue;
				// Prepare layout values - reference hPoints position
				/*Modified by Roland Zhu 2006.9.19
				 *Get the index of the h point by the field "id"(in initialize time, use the index to indicate the "id"), rather
				 *than use the absolute index "j", so the point id which got from __lines can absent, but not all of point id
				 */
				 var tpIndex:Number = j;
				 for(var p=0;p<__hPoints.length;p++){
					
					 if(j == Number(__hPoints[p].id)){
						 tpIndex = p;
					 }
					
				 }
				//var tempPlotX:Number = __hPoints[j].hAxisX;
				//var tempColumnName:String = __hPoints[j].label;
				var tempPlotX:Number = (__startPointXLeftAlign) ? __hPoints[tpIndex].hAxisX : __hPoints[tpIndex].hAxisX + sectionW/2;
				var tempColumnName:String = __hPoints[tpIndex].label;
				
				var tempPlotY:Number = getPlotY(tempPlotValue);
				var breakPointFlag:Boolean = false;
				//loop through all the breakpoint to check if current point is a breakpoint.
				for(var m = 0;m <__breakPoints.length;m++){
					if(j == Number(__breakPoints[m])){
						breakPointFlag = true;
						break;
					}
				}
				
				if (j!=0 && !breakPointFlag)
				{
					// Actually draw line if not first item
					// vAxis_mc.moveTo(lastPlotX, lastPlotY);

					vAxis_mc.lineTo(tempPlotX , tempPlotY);
				}
				if(breakPointFlag || j==0)
				{
					// Move to starting position for line
					vAxis_mc.moveTo(tempPlotX, tempPlotY);
				}
				
				// -----------------
				// Add mouseover box
				// -----------------
				
				var mouseOverBoxName:String = "mouseoverbox_" + i + "_" + j + "_mc";
				var mouseOverBox:MovieClip = vAxis_mc.createEmptyObject(mouseOverBoxName, vAxis_mc.getNextHighestDepth());
				
				mouseOverBox._x = tempPlotX - 10 ;
				mouseOverBox._y = tempPlotY - 9;
				
				mouseOverBox.createEmptyObject("hover_mc", 1);
				mouseOverBox.createEmptyObject("content_mc", 2);
				mouseOverBox.hover_mc.useHandCursor = false;
				mouseOverBox.content_mc._visible = false;
				
				// Invisible hoverbox
				drawRoundRect(mouseOverBox.hover_mc, 8, 8, 5, 5, 0, 0xFFD400, 100);	//modified by Roland Zhu to show the vertex upon the line.
				
				// Tooltip hover dot
				var mouseOverDotDiameter:Number = 10;
				mouseOverBox.content_mc.lineStyle(1, tempLineColor, 100);
				drawRoundRect(mouseOverBox.content_mc, 5, 5, 10, 10, 5, 0xFFFFFF, 100);
				mouseOverBox.content_mc.lineStyle(0, tempLineColor, 0);
				drawRoundRect(mouseOverBox.content_mc, 8, 8, 4, 4, 2, tempLineColor, 100);
				
				// Tooltip message
				trace("--"+lineLabel+"--");
				var mouseOverMessage:String = (lineLabel!=undefined && lineLabel.length >0 ) ? "<b>" + lineLabel + "</b><br>" : "";
				mouseOverMessage += __hTitle +": "+ tempColumnName + "<br>" + __vTitle +": "+ numberPrefix + tempPlotValue + numberPostfix;
				
				mouseOverBox.content_mc.createTextField("label_txt", 2, 22, -2, 0, 0);
				var tf:TextField = mouseOverBox.content_mc.label_txt;
				tf.selectable = false;
				tf.html = true;
				tf.multiline = true;
				tf.htmlText = "<font face='Verdana' size='10'>" + mouseOverMessage + "</font>";
				tf._width = tf.textWidth + 5;
				tf._height = tf.textHeight + 5;
				tf._y -= tf._height;
				
				var o:MovieClip = mouseOverBox.content_mc.createEmptyObject("labelbg_mc", 1);
				o._x = tf._x - 2;
				o._y = tf._y - 1;
				o.lineStyle(1, tempLineColor, 100);
				drawRoundRect(o, 0, 0, tf._width + 4, tf._height + 3, 0, 0xFFFFFF, 80); // bg
				o.lineStyle(0, tempLineColor, 0);
				drawRoundRect(o, 1, tf._height + 3.5, tf._width+4.5, 1, 0, 0x666666, 50); // inner shad horiz
				drawRoundRect(o, tf._width + 4.5, 1, 1, tf._height+2.5, 0, 0x666666, 50); // inner shad vert
				drawRoundRect(o, 2, tf._height + 4.5, tf._width+4.5, 1, 0, 0x666666, 20); // outer shad horiz
				drawRoundRect(o, tf._width + 5.5, 2, 1, tf._height+2.5, 0, 0x666666, 20); // outer shad vert
				
				/*Added by Roland Zhu 2006.9.19
				 *Control the coordinate of the float pane when it is near from the stage boundary
				 */
				 trace("current pane postion:"+(tempPlotX));
				 trace("chart width:"+this.width);
				 if(tempPlotX + mouseOverBox.content_mc._width > this.width && __hPoints.length >2){	//this is the last point, then move the position of the float pane to make it may show in the stage area.
					trace("The original postion"+mouseOverBox.content_mc._x);
					var offset = mouseOverBox.content_mc._width;
					mouseOverBox.content_mc.label_txt._x -=  offset;
					mouseOverBox.content_mc.labelbg_mc._x -=  offset;
					
					
					trace("after moved"+mouseOverBox.content_mc._x);
				 }
				
				// Mouse events
				mouseOverBox.hover_mc.onRollOver = function():Void
				{
					this._parent.content_mc._visible = true;
				}
				mouseOverBox.hover_mc.onRollOut = mouseOverBox.hover_mc.onDragOut = function():Void
				{
					this._parent.content_mc._visible = false;
				}
				
				// -- Done with mouseoverbox --
				
				// Update lastPlot values
				lastPlotX = tempPlotX;
				lastPlotY = tempPlotY;
			}
		}
		
	}

	function plotLine(line:Object, label:String, color:Number, startPointAlign:Boolean):Void
	{
		var plotValues:Array = convertLineObj(line);
		var labelValue:String = label; //label!=undefined ? label : "(None)";
		var colorValue:Number;
		if (color!=undefined)
		{
			colorValue = color;
		}
		else
		{
			var colorIndex:Number;
			if (__defaultColors.length > __lines.length)
			{
				colorIndex = __lines.length;
			}
			else
			{
				colorIndex = __lines.length - (Math.floor(__lines.length / __defaultColors.length) * __defaultColors.length);
			}
			colorValue = __defaultColors[colorIndex];
		}
		
		__lines.push({points:plotValues, label:labelValue, color:colorValue});
		
		//set the alignment of the first point relative to the first x scale
		__startPointXLeftAlign = startPointAlign;
		
		// Tell to draw in future
		invalidate();
	}
	
	function removeLines():Void
	{
		// Clear array
		__lines = [];
		
		// Tell to draw in future
		invalidate();
	}
	
	function drawLegend(o:MovieClip, pad:Number, hSpacing:Number):Void
	{
		var padding:Number = pad!=undefined ? pad : 5;
		__spacing = hSpacing;
		var layoutY:Number = 0;
		
		// Remove previous legend remains
		
		o.clear();
		
		for (var i:String in o)
		{
			if (i.substr(0, 13)=="legend_label_")
			{
				o[i].removeTextField();
			}
		}
		
		// Loop through lines and draw legend
		
		for (var i:Number=0; i<__lines.length; i++)
		{
			// Prepare vars
			var tempLine:Object = __lines[i];
			var tempLabel:String = tempLine.label;
			var tempColor:Number = tempLine.color;
			
			// Draw box
			drawRoundRect(o, padding, layoutY, 10, 15, 0, tempColor, 100);
			
			// Draw label
			var labelName:String = "legend_label_" + i;
			o.createTextField(labelName, o.getNextHighestDepth(), padding + 15, layoutY, 0, 10);
			var t:TextField = o[labelName];
			t.selectable = false;
			t.autoSize = "left";
			t.setNewTextFormat(labelFormatBold);
			t.text = tempLabel;
			
			// Increment layoutY
			//layoutY += spacing;
			//Modified by Roland Zhu Indrement padding, so the legend icon will be put horizontally
			padding += __spacing;
		}
	}
	
	function drawChart():Void
	{
		drawHAxis();
		drawVAxis();
	}
	
	function toDeg(rad:Number):Number
	{
		// 2PI RAD = 360deg
		var deg:Number = (180 / Math.PI) * rad;
		return deg;
	}
	
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -