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

📄 charts.as

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 AS
📖 第 1 页 / 共 3 页
字号:
package{	import com.adobe.serialization.json.JSON;	import com.yahoo.astra.fl.charts.*;	import com.yahoo.astra.fl.charts.events.ChartEvent;	import com.yahoo.astra.fl.charts.legend.Legend;	import com.yahoo.astra.fl.charts.series.*;	import com.yahoo.astra.fl.charts.skins.*;	import com.yahoo.astra.fl.utils.UIComponentUtil;	import com.yahoo.astra.utils.InstanceFactory;	import com.yahoo.astra.utils.JavaScriptUtil;	import com.yahoo.yui.LoggerCategory;	import com.yahoo.yui.YUIAdapter;	import com.yahoo.yui.charts.*;		import fl.core.UIComponent;		import flash.display.DisplayObject;	import flash.display.Shape;	import flash.display.Sprite;	import flash.events.ErrorEvent;	import flash.events.MouseEvent;	import flash.external.ExternalInterface;	import flash.text.TextFormat;	import flash.utils.getDefinitionByName;	import flash.utils.getQualifiedClassName;	[SWF(backgroundColor=0xffffff)]	/**	 * A wrapper for the Astra Charts components to allow them to be used by the YUI library.	 * 	 * @author Josh Tynjala	 */	public class Charts extends YUIAdapter	{			//--------------------------------------	//  Constructor	//--------------------------------------			/**		 * Constructor.		 */		public function Charts()		{			super();		}			//--------------------------------------	//  Properties	//--------------------------------------			/**		 * @private		 * A reference to the chart instance.		 */		protected var chart:Chart;				/**		 * @private		 * The type of the chart specified by setType().		 */		protected var type:String;				/**		 * @private		 * A reference to the legend instance.		 */		protected var legend:Legend;				/**		 * @private		 * Storage for the legendDisplay property.		 */		protected var _legendDisplay:String = "none";				/**		 * @private		 * Specifies the location of the legend, or "none" if the legend		 * is not to be displayed.		 */		public function get legendDisplay():String		{			return this._legendDisplay;		}				/**		 * @private		 */		public function set legendDisplay(value:String):void		{			this._legendDisplay = value;			this.refreshComponentSize();		}				/**		 * @private		 * Storage for the spacing property.		 */		protected var _spacing:Number = 6;				/**		 * @private		 * The spacing between the chart and other objects, such as the legend.		 */		public function get spacing():Number		{			return this._spacing;		}				/**		 * @private		 */		public function set spacing(value:Number):void		{			this._spacing = value;			this.refreshComponentSize();		}				/**		 * @private		 * Storage for the padding property.		 */		protected var _padding:Number = 10;				/**		 * @private		 * The padding around the chart, in pixels.		 */		public function get padding():Number		{			return this._padding;		}				/**		 * @private		 */		public function set padding(value:Number):void		{			this._padding = value;		}				/**		 * @private		 */		protected var backgroundAndBorder:BackgroundAndBorder;				/**		 * @private		 */		override protected function get component():DisplayObject		{			//why do I have to do this? it's not ambiguous!			return super.component;		}				/**		 * @private		 */		override protected function set component(value:DisplayObject):void		{			this.chart = Chart(value);			super.component = value;		}			//--------------------------------------	//  Public Methods	//--------------------------------------				/**		 * Creates a chart instance based on the specified type.		 */		public function setType(value:String):void		{			if(this.chart)			{				this.removeChild(this.chart);				this.chart.removeEventListener(ChartEvent.ITEM_CLICK, chartItemEventHandler);				this.chart.removeEventListener(ChartEvent.ITEM_DOUBLE_CLICK, chartItemEventHandler);				this.chart.removeEventListener(ChartEvent.ITEM_ROLL_OUT, chartItemEventHandler);				this.chart.removeEventListener(ChartEvent.ITEM_ROLL_OVER, chartItemEventHandler);				this.chart.removeEventListener(MouseEvent.MOUSE_DOWN, chartItemExtraEventHandler);			}						this.type = value;			var ChartType:Class = ChartSerializer.getType(this.type);			var chart:Chart = new ChartType();			chart.setStyle("contentPadding", 0);			chart.setStyle("backgroundSkin", Sprite);			var backgroundFactory:InstanceFactory = this.createBorderBackgroundFactory();			backgroundFactory.properties.fillColor = 0xffffff;			backgroundFactory.properties.fillAlpha = 0.9;			backgroundFactory.properties.borderWeight = 1;			backgroundFactory.properties.borderColor = 0x000000;			chart.setStyle("dataTipBackgroundSkin", backgroundFactory);			chart.setStyle("seriesMarkerSkins", []);			this.addChildAt(chart, 1);						this.component = chart;			this.chart.addEventListener(ChartEvent.ITEM_CLICK, chartItemEventHandler, false, 0, true);			this.chart.addEventListener(ChartEvent.ITEM_DOUBLE_CLICK, chartItemEventHandler, false, 0, true);			this.chart.addEventListener(ChartEvent.ITEM_ROLL_OUT, chartItemEventHandler, false, 0, true);			this.chart.addEventListener(ChartEvent.ITEM_ROLL_OVER, chartItemEventHandler, false, 0, true);			this.chart.addEventListener(MouseEvent.MOUSE_DOWN, chartItemExtraEventHandler, false, 0, true);						this.chart.legend = this.legend;						this.log("Type set to \"" + this.type + "\"");		}				public function setDataProvider(value:Array):void		{			var dataProvider:Array = [];			var seriesCount:int = value.length;			var seriesStyles:Array = [];			for(var i:int = 0; i < seriesCount; i++)			{				var dataFromJavaScript:Object = value[i];				var currentData:ISeries = this.chart.dataProvider[i] as ISeries;				var seriesType:Class = SeriesSerializer.shortNameToSeriesType(dataFromJavaScript.type ? dataFromJavaScript.type : this.type);								var series:ISeries;				if(currentData && getDefinitionByName(getQualifiedClassName(currentData)) == seriesType)				{					//reuse the series if possible because we want animation					series = SeriesSerializer.readSeries(dataFromJavaScript, currentData);				}				else				{					series = SeriesSerializer.readSeries(dataFromJavaScript);				}				dataProvider[i] = series;							//this is where we parse the individual series styles, and we convert them				//to the format the chart actually expects.				//we fill in with defaults for styles that have not been specified				if(dataFromJavaScript.style)				{					seriesStyles.push(dataFromJavaScript.style);				}				else seriesStyles.push(null);			}						this.log("Displaying " + seriesCount + " series.");						//set data provider and new styles			this.chart.dataProvider = dataProvider;						//make sures the series are created!			this.chart.drawNow();						//set the styles for the series			this.setSeriesStyles(seriesStyles);						this.refreshComponentSize();		}				/**		 * Returns the category names.		 */		public function getCategoryNames():Array		{			var categoryChart:ICategoryChart = this.chart as ICategoryChart;			if(categoryChart)			{				return categoryChart.categoryNames;			}			var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));			this.log("Cannot find categoryNames on a chart of type " + shortName, LoggerCategory.WARN);			return null;		}				/**		 * Sets the category names used if the data requires a category axis.		 * This field should be used if the data does not define the category		 * values directly.		 */		public function setCategoryNames(value:Array):void		{			var categoryChart:ICategoryChart = this.chart as ICategoryChart;			if(categoryChart)			{				categoryChart.categoryNames = value;			}			else			{				var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));				this.log("Unable to set categoryNames on a chart of type " + shortName, LoggerCategory.WARN);			}		}				/**		 * Returns the field used in complex objects to access data to be		 * displayed on the PieChart.		 */		public function getDataField():String		{			var pieChart:PieChart = this.chart as PieChart;			if(pieChart)			{				return pieChart.dataField;			}						var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));			this.log("Unable to find dataField on a chart of type " + shortName, LoggerCategory.WARN);			return null;		}				/**		 * Sets the field used in complex objects to access data to be displayed		 * on the PieChart.		 */		public function setDataField(value:String):void		{			var pieChart:PieChart = this.chart as PieChart;			if(pieChart)			{				pieChart.dataField = value;			}			else			{				var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));				this.log("Unable to set dataField on a chart of type " + shortName, LoggerCategory.WARN);			}		}				/**		 * Returns the field used in complex objects to access categories to be		 * displayed on the PieChart.		 */		public function getCategoryField():String		{			var pieChart:PieChart = this.chart as PieChart;			if(pieChart)			{				return pieChart.categoryField;			}						var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));			this.log("Unable to find categoryField on a chart of type " + shortName, LoggerCategory.WARN);			return null;		}				/**		 * Sets the field used in complex objects to access categories to be displayed		 * on the PieChart.		 */		public function setCategoryField(value:String):void		{			var pieChart:PieChart = this.chart as PieChart;			if(pieChart)			{				pieChart.categoryField = value;			}			else			{				var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));				this.log("Unable to set categoryField on a chart of type " + shortName, LoggerCategory.WARN);			}		}				/**		 * Returns the field used in complex objects to access data to be		 * displayed on the horizontal axis.		 */		public function getHorizontalField():String		{			var cartesianChart:CartesianChart = this.chart as CartesianChart;			if(cartesianChart)			{				return cartesianChart.horizontalField;			}						var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));			this.log("Unable to find horizontalField on a chart of type " + shortName, LoggerCategory.WARN);			return null;		}				/**		 * Sets the field used in complex objects to access data to be displayed		 * on the horizontal axis. If the input data is XML, and the field is an		 * attribute, be sure to include the "@" symbol at the beginning of the		 * field name.		 */		public function setHorizontalField(value:String):void		{			var cartesianChart:CartesianChart = this.chart as CartesianChart;			if(cartesianChart)			{				cartesianChart.horizontalField = value;			}			else			{				var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));				this.log("Unable to set horizontalField on a chart of type " + shortName, LoggerCategory.WARN);			}		}				/**		 * Returns the field used in complex objects to access data to be		 * displayed on the vertical axis.		 */		public function getVerticalField():String		{			var cartesianChart:CartesianChart = this.chart as CartesianChart;			if(cartesianChart)			{				return cartesianChart.verticalField;			}						var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));			this.log("Unable to find verticalField on a chart of type " + shortName, LoggerCategory.WARN);			return null;		}				/**		 * Sets the field used in complex objects to access data to be displayed		 * on the vertical axis. If the input data is XML, and the field is an		 * attribute, be sure to include the "@" symbol at the beginning of the		 * field name.		 */		public function setVerticalField(value:String):void		{			var cartesianChart:CartesianChart = this.chart as CartesianChart;			if(cartesianChart)			{				cartesianChart.verticalField = value;			}			else			{				var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));				this.log("Unable to set verticalField on a chart of type " + shortName, LoggerCategory.WARN);			}		}				/**		 * Returns the title displayed next to the vertical axis.		 */		public function getHorizontalAxisTitle():String		{			var cartesianChart:CartesianChart = this.chart as CartesianChart;			if(cartesianChart)			{				return cartesianChart.horizontalAxisTitle;			}						var shortName:String = ChartSerializer.getShortName(getQualifiedClassName(this.chart));			this.log("Unable to find horizontalAxisTitle on a chart of type " + shortName, LoggerCategory.WARN);			return null;		}				/**

⌨️ 快捷键说明

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