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

📄 piechart.as

📁 FLASH实现的PIE chart组件
💻 AS
📖 第 1 页 / 共 2 页
字号:
import webex.Chart;
//import webex.pieBase;
class webex.pieChart extends Chart {
	/**
	* @private
	* SymbolName for object
	*/
	static var symbolName:String = "pieChart";
	/**
	* @private
	* Class used in createClassObject
	*/
	//static var symbolOwner:Object = LineChart;
	var className:String = "pieChart";
	var __lines:Array = [];
	var plotArea:MovieClip;
	var dummyArea:MovieClip;
	var boundingBox_mc:MovieClip;
	var arcAnchorPoint:Array = [];
	var arcRotationDegrees:Array = [];
	function pieChart() {
	}
	function init() {
		super.init();
		boundingBox_mc._visible = false;
	}
	function size():Void {
		super.size();
		invalidate();
	}
	function createChildren():Void {
		this.createEmptyMovieClip("plotArea", this.getNextHighestDepth());
		this.createEmptyMovieClip("dummyArea", this.getNextHighestDepth());
	}
	function draw():Void {
		drawChart();
	}
	function getLabelDims(label:String):Object {
		this.createTextField("temp_getwidth", this.getNextHighestDepth(), -1000, -1000, 0, 10);
		var o:TextField = this["temp_getwidth"];
		o.text = label;
		o.autoSize = "center";
		o.selectable = false;
		o.setTextFormat(labelFormat);
		var dims:Object = {width:o._width, height:o._height};
		o.removeTextField();
		return dims;
	}
	function getExtremeValues():Object {
		// Concatenate all arrays
		var comboArray:Array = [];
		for (var i:Number = 0; i<__lines.length; i++) {
			/*Added by Roland Zhu 2006.9.20 this feature only for the Detail Latency Time 
			 *Remove the null value point from __lines.point to make it can calculate the step and the max,min boundary of y axis
			 */
			var retrievedPoints:Array = [];
			for (var j = 0; j<__lines[i].points.length; j++) {
				if (__lines[i].points[j] != undefined && !isNaN(__lines[i].points[j])) {
					retrievedPoints.push(__lines[i].points[j]);
				}
			}
			//comboArray = comboArray.concat(__lines[i].points);
			comboArray = comboArray.concat(retrievedPoints);
		}
		// Sort and return extremes
		var sortArray:Array = comboArray.sort(Array.NUMERIC);
		var minNum:Number = sortArray[0];
		var maxNum:Number = sortArray[sortArray.length-1];
		var returnObj:Object = {min:minNum, max:maxNum};
		return returnObj;
	}
	function convertLineObj(obj:Object):Array {
		// Create reference object
		var referenceObj:Object = {};
		for (var i:Number = 0; i<__hPoints.length; i++) {
			var tempItem:Object = __hPoints[i];
			referenceObj[tempItem.id] = i;
		}
		// Create ordered array
		var returnArray:Array = [];
		for (var i in obj) {
			var tempOrder = referenceObj[i];
			var tempVal:Number = obj[i];
			returnArray[tempOrder] = tempVal;
		}
		return returnArray;
	}
	/*
	 *Plot the arcs by the certain format of data source
	 */
	function plotArc(bar:Object, label:String, color:Number):Void {
		var plotValues:Array = convertLineObj(bar);
		trace("The values of this cycle"+plotValues.toString());
		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});
		// Tell to draw in future
		invalidate();
	}
	function drawChart() {
		//trace("drew chart.");
		//trace("Width :"+width+"Height:"+height);
		drawPie();
		/*
		this.createEmptyMovieClip("testmc",this.getNextHighestDepth());
		 this["testmc"].lineStyle(0, 0x000000);
		  this["testmc"].lineTo(320,300)
		  this["testmc"].beginFill(0xff0000, 100);
		arcTo(this["testmc"],200, 300, 120, 0, 90);
		 this["testmc"].endFill();
		 */
	}
	
	
	function drawPie() {
		var plotCenter = {x:width/2, y:height/2};
		//var plotCenter = {x:200, y:200};
		var currentDegrees = 0;
		//record current degrees of the arc has been drewn.
		var radius = Math.min(width/2*0.8, height/2*0.8);
		//var radius = 200;
		//loop through the data source to get the value of every point
		//sum all values of the points
		var sum = 0;
		for (var i:Number = 0; i<__lines.length; i++) {
			var tempLine:Object = __lines[i];
			var linePoints:Array = tempLine.points;
			for (var j:Number = 0; j<linePoints.length; j++) {
				var tempPlotValue:Number = linePoints[j];
				if (isNaN(tempPlotValue)) {
					tempPlotValue = 0;
				}
				sum += tempPlotValue;
			}
		}
		trace("Sum value of all points:"+sum);
		for (var i:Number = 0; i<__lines.length; i++) {
			trace(__lines.length);
			var tempLine:Object = __lines[i];
			trace("dot in this "+tempLine.points.toString());
			var linePoints:Array = tempLine.points;
			var lineLabel:String = tempLine.label;
			var tempLineColor:Number = tempLine.color;
			for (var j:Number = 0; j<linePoints.length; j++) {
				var tempPlotValue:Number = linePoints[j];
				if (isNaN(tempPlotValue)) {
					tempPlotValue = 0;
				}
				var fraction = tempPlotValue/sum;
				var sliceDegrees = 360*fraction;
				//this is a single legend chart, so every point need render by a variable color
				//var tempLineColor:Number = tempLine.color;
				var barName:String = "arc"+i+"_"+j+"_mc";
				var mouseOverBoxName:String = "mouseoverbox_"+i+"_"+j+"_mc";
				var bar:MovieClip = plotArea.createEmptyObject(barName, plotArea.getNextHighestDepth());
				var mouseOverBox:MovieClip = dummyArea.createEmptyObject(mouseOverBoxName, dummyArea.getNextHighestDepth());
				bar._x = plotCenter.x;
				bar._y = plotCenter.y;
				bar.lineStyle(0, 0xffffff);
				bar.beginFill(tempLineColor, 100);
				bar.lineTo(radius, 0);
				arcTo(bar, radius, 0, radius, 0, sliceDegrees, "arcAnchorPoint");
				//drawCircle(plotArea, width / 2, height / 2, radius);
				currentDegrees += sliceDegrees;
				bar.lineTo(0, 0);
				bar.endFill();
				bar._rotation = currentDegrees;
				arcRotationDegrees.push(currentDegrees);
				//record the rotaion degree of every arc, in later time, we use it to control other mc's relative postion according to it.
				//define the nested mc of mouseOverBox, and specify the event for it in later time
				mouseOverBox._x = plotCenter.x;
				mouseOverBox._y = plotCenter.y;
				mouseOverBox.createEmptyObject("hover_mc", 1);
				mouseOverBox.createEmptyObject("content_mc", this.getNextHighestDepth());
				mouseOverBox.hover_mc.useHandCursor = false;
				mouseOverBox.content_mc._visible = false;
				//the content of the mouseOverBox
				mouseOverBox.hover_mc.lineStyle(0, 0xffffff);
				mouseOverBox.hover_mc.beginFill(tempLineColor, 0);
				mouseOverBox.hover_mc.lineTo(radius, 0);
				arcTo(mouseOverBox.hover_mc, radius, 0, radius, 0, sliceDegrees);
				//drawCircle(plotArea, width / 2, height / 2, radius);
				mouseOverBox.hover_mc.lineTo(0, 0);
				mouseOverBox.hover_mc.endFill();
				mouseOverBox.hover_mc._rotation = currentDegrees;
				mouseOverBox.hover_mc.delegator = this;
				//draw the content of the content mc(a float pane when mouse roll over)
				/*draw the highlight point
				//mouseOverBox.content_mc.createEmptyObject("anchor_mc1",mouseOverBox.content_mc.getNextHighestDepth());
				mouseOverBox.content_mc.createEmptyObject("anchor_mc2",mouseOverBox.content_mc.getNextHighestDepth());
				trace("test x:"+arcAnchorPoint[i].x+"y:"+arcAnchorPoint[i].y);
				trace("test x:"+arcAnchorPoint[i+1].x+"y:"+arcAnchorPoint[i+1].y);
				//drawThickBox(mouseOverBox.content_mc.anchor_mc,arcAnchorPoint.x*Math.cos(currentDegrees)-2,arcAnchorPoint.y*Math.sin(currentDegrees)-2,arcAnchorPoint.x*Math.cos(currentDegrees)+2,arcAnchorPoint.y*Math.sin(currentDegrees)+2,0x000000,0,1,0); 

⌨️ 快捷键说明

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