例一
最普通那种图
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel title="柱状图实例" y="36" width="408" height="423" layout="absolute" fontSize="14" fontFamily="Georgia" color="#3D52EA" horizontalCenter="11">
<mx:ColumnChart y="24" id="myChart" dataProvider="{finance}" width="346" height="348" type="clustered" showDataTips="true" fontFamily="Georgia" fontSize="11" horizontalCenter="-1">
<mx:horizontalAxis>
<mx:CategoryAxis
dataProvider="{finance}"
categoryField="Month"
title="(月份)"
/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries displayName="收入" xField="Month" yField="In"/>
<mx:ColumnSeries displayName="支出" xField="Month" yField="Out"/>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{finance}" y="10" x="294"/>
</mx:Panel>
<mx:Script><![CDATA[
import mx.collections.ArrayCollection; //引用数组类
[Bindable]
//定义数据集,数据集的内容为每月的收支情况
public var finance:ArrayCollection = new ArrayCollection([
{Month:"一月", In:20000, Out:15000},
{Month:"二月", In:1000, Out:200},
{Month:"三月", In:1500, Out:200},
{Month:"四月", In:3500, Out:1000},
{Month:"五月", In:500, Out:800},
{Month:"六月", In:4500, Out:600},
{Month:"七月", In:2500, Out:500},
{Month:"八月", In:1570, Out:300},
{Month:"九月", In:1000, Out:450},
{Month:"十月", In:1500, Out:400},
{Month:"十一月", In:1700, Out:2500},
{Month:"十二月", In:1800, Out:1500},
]);
]]></mx:Script>
</mx:Application>
例二:
3d柱状图 http://human-zx.iteye.com/blog/282851
例三:
蜡烛图 http://topic.csdn.net/u/20090410/17/d6ac26b9-48ed-4bc0-a60c-2f2453d5f43a.html
资源:
http://blog.csdn.net/mylxiaoyi/archive/2007/05/20/1618470.aspx
http://www.fusioncharts.com/demos/extensions/chart-explorer/view/index.html
HeatMap
http://michaelvandaniker.com/blog/2008/07/06/how-to-make-heat-maps-in-flex/
Chart选择事件处理
http://livedocs.adobe.com/flex/3/html/help.html?content=charts_eventsandeffects_12.html
PieChart 双击 动画 例子
http://blog.csdn.net/jiandanfeng2/article/details/6461746
一、 PieChart.xml中的实现,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:effects="jac.*"
layout="vertical" verticalAlign="top"
horizontalAlign="center" backgroundGradientColors="[0x000000,0x323232]" paddingTop="0" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.charts.events.ChartItemEvent;
import mx.controls.Alert;
import com.adobe.serialization.json.JSON;
import mx.charts.series.items.ColumnSeriesItem;
[Bindable]
private var medalsAC:ArrayCollection = new ArrayCollection( [
{ Country: "USA", Gold: 35, Silver:39, Bronze: 29 },
{ Country: "China", Gold: 32, Silver:17, Bronze: 14 },
{ Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]);
private var downArray:ArrayCollection = new ArrayCollection([
{ Country: "California",Gold:23.3},
{ Country: "Japan",Gold:23.4},
{ Country: "South Korea",Gold:33.3},
{ Country: "England",Gold:20}]);
private function displayGold(data:Object, field:String, index:Number, percentValue:Number):String {
var temp:String= (" " + percentValue).substr(0,6);
return data.Country + ": " + '/n' + "Total Gold: " + data.Gold + '/n' + temp + "%";
}
private function pieItemClick(evt:ChartItemEvent):void{
// Alert.show(""+JSON.encode(evt.hitSet),"tips");
var arr:Array = [];
arr[evt.hitData.chartItem.index] = 0.2;
series.perWedgeExplodeRadius=arr;
// chart.perWedgeExplodeRadius=arr;
}
private function pieItemDBClick(evt:ChartItemEvent):void{//drilldown
// Alert.show("ds","tips");
chart.showDataTips = false;
series.setStyle("showDataEffect", drillDownEffect);
chart.dataProvider=downArray;
chart.removeEventListener(ChartItemEvent.ITEM_DOUBLE_CLICK,pieItemDBClick);
chart.addEventListener(MouseEvent.CLICK, drillUp);
}
private function drillUp(event:MouseEvent):void{
chart.showDataTips = false;
series.setStyle("showDataEffect",drillUpEffect);
chart.dataProvider=medalsAC;
chart.addEventListener(ChartItemEvent.ITEM_DOUBLE_CLICK,pieItemDBClick);
chart.removeEventListener(MouseEvent.CLICK,drillUp);
}
//piechart钻取(drilldown或者drillup,本质是数据的重新加载)
]]>
</mx:Script>
<!--动画效果-->
<effects:DrillDownEffect id="drillDownEffect" duration="1500" effectEnd="chart.showDataTips=true" />
<effects:DrillUpEffect id="drillUpEffect" duration="1500" effectEnd="chart.showDataTips=true"/>
<mx:Panel title="PieChart Control" layout="vertical" color="0xffffff" borderAlpha="0.15" height="350" width="600"
paddingTop="10" paddingRight="10" paddingBottom="10" paddingLeft="10" horizontalAlign="center">
<mx:PieChart id="chart" height="100%" width="100%" paddingRight="5" paddingLeft="5" color="0x323232"
showDataTips="true" dataProvider="{medalsAC}" doubleClickEnabled="true" itemDoubleClick="pieItemDBClick(event);">
<mx:series>
<mx:PieSeries id="series" labelPosition="callout" field="Gold" labelFunction="displayGold" nameField="Country">
<mx:calloutStroke>
<mx:Stroke weight="0" color="0x888888" alpha="1.0"/>
</mx:calloutStroke>
<mx:radialStroke>
<mx:Stroke weight="0" color="#FFFFFF" alpha="0.20"/>
</mx:radialStroke>
<mx:stroke>
<mx:Stroke color="0" alpha="0.20" weight="2"/>
</mx:stroke>
<mx:filters>
<mx:Array/>
</mx:filters>
</mx:PieSeries>
</mx:series>
</mx:PieChart>
<mx:Legend dataProvider="{chart}" color="0x323232" direction="horizontal" horizontalGap="60"/>
</mx:Panel>
</mx:Application>
二、向下钻取效果的实现- DrillDownEffect.as
package jac
{
import mx.charts.effects.SeriesEffect;
import mx.effects.IEffectInstance;
import mx.effects.TweenEffect;
public class DrillDownEffect extends TweenEffect
{
public function DrillDownEffect(target:Object = null)
{
super(target);
instanceClass = DrillDownEffectInstance;
}
public var drillFromIndex:Number = 0;
public var splitDirection:String = "vertical";
override protected function initInstance(inst:IEffectInstance):void
{
super.initInstance(inst);
DrillDownEffectInstance(inst).drillFromIndex = drillFromIndex;
DrillDownEffectInstance(inst).splitDirection = splitDirection;
}
}
}
import mx.charts.effects.effectClasses.SeriesEffectInstance;
import mx.charts.chartClasses.RenderData;
import flash.geom.Rectangle;
import mx.effects.effectClasses.TweenEffectInstance;
import mx.charts.chartClasses.Series;
class DrillDownEffectInstance extends TweenEffectInstance
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor.
*/
public function DrillDownEffectInstance(target:Object)
{
super(target);
}
public var drillFromIndex:Number;
public var splitDirection:String;
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
/**
* @private
*/
private var _startingBounds:Rectangle;
private var _state:String = "";
/**
* @private
*/
private var dstRenderData:RenderData;
private var srcRenderData:RenderData;
private var targetBounds:Array;
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override public function play():void
{
var targetSeries:Series = Series(target);
srcRenderData = RenderData(targetSeries.getRenderDataForTransition("hide"));
dstRenderData = RenderData(targetSeries.getRenderDataForTransition("show"));
targetSeries.getElementBounds(srcRenderData);
targetSeries.getElementBounds(dstRenderData);
if(drillFromIndex >= srcRenderData.elementBounds.length)
drillFromIndex = 0;
var dstCount:Number= dstRenderData.elementBounds.length;
var srcCount:Number = srcRenderData.elementBounds.length;
if(drillFromIndex < srcRenderData.elementBounds.length)
{
_startingBounds = srcRenderData.elementBounds[drillFromIndex].clone();
targetBounds = [];
for(var i:int = 0;i<dstCount;i++)
{
targetBounds[i] = dstRenderData.elementBounds[i].clone();
}
for(i= 0;i<srcCount;i++)
{
dstRenderData.elementBounds[i] = srcRenderData.elementBounds[i].clone();
}
}
else
{
_startingBounds = null;
}
targetSeries.transitionRenderData = srcRenderData;
targetSeries.invalidateDisplayList();
_state = "hiding";
// Create a tween to move the object
tween = createTween(this, [ 0 ],
[ 1 ], duration);
}
/**
* @private
*/
override public function onTweenUpdate(values:Object):void
{
var targetSeries:Series = Series(target);
super.onTweenUpdate(values);
var value:Number = values[0];
if(_startingBounds == null)
return;
var targetBounds:Array = targetBounds;
var n:int;
var i:int;
var interpolation:Number;
var v:Rectangle;
interpolation = Math.min(1,value/.1);
if(_state == "hiding")
{
n = srcRenderData.filteredCache.length;
for (i = 0; i < n; i++)
{
interpolation = value/.1;
if(i != drillFromIndex)
srcRenderData.filteredCache[i].itemRenderer.alpha = (1-interpolation);
}
if(value >= .1)
{
_state = "holding";
n = srcRenderData.filteredCache.length;
for (i = 0; i < n; i++)
{
srcRenderData.filteredCache[i].itemRenderer.alpha = 1;
}
targetSeries.transitionRenderData = dstRenderData;
targetSeries.validateNow();
layoutDestination(0);
}
}
if (_state == "holding")
{
if(value >= .5)
{
_state = "splitting";
}
}
if(_state == "splitting")
{
interpolation = Math.max(value-.5,0)/.5;
layoutDestination(interpolation);
}
targetSeries.invalidateDisplayList();
}
private function layoutDestination(interpolation:Number):void
{
var n:Number = dstRenderData.filteredCache.length;
var startWidth:Number;
var startHeight:Number;
var activeBounds:Array = dstRenderData.elementBounds;
var a:Rectangle;
var vInterpolation:Number;
var hInterpolation:Number;
var target:Rectangle;
var startLeft:Number;
var wDelta:Number;
var hDelta:Number;
var lDelta:Number;
var tDelta:Number;
var newWidth:Number;
var newHeight:Number;
var startTop:Number;
var i:int;
if(splitDirection == "vertical")
{
startWidth = _startingBounds.width / n;
startHeight = _startingBounds.height;
vInterpolation = Math.pow(interpolation,4);
hInterpolation = Math.pow(interpolation,2);
for (i = 0; i < n; i++)
{
startLeft = _startingBounds.left + startWidth * i;
target = targetBounds[i];
a = activeBounds[i];
wDelta = target.width - startWidth;
hDelta = target.height - startHeight;
lDelta = target.left - startLeft;
tDelta = target.top - _startingBounds.top;
newWidth = startWidth + wDelta * hInterpolation;
newHeight = startHeight + hDelta * vInterpolation;
a.left = startLeft + lDelta * hInterpolation;
a.right = a.left + newWidth;
a.top = _startingBounds.top + tDelta * vInterpolation;
a.bottom = a.top + newHeight;
}
}
else
{
startWidth = _startingBounds.width;
startHeight = _startingBounds.height / n;
startLeft = _startingBounds.left;
vInterpolation = Math.pow(interpolation,4);
hInterpolation = Math.pow(interpolation,2/3);
for (i= 0; i < n; i++)
{
startTop = _startingBounds.top + startHeight * i;
target = targetBounds[i];
a = activeBounds[i];
wDelta = target.width - startWidth;
hDelta = target.height - startHeight;
lDelta = target.left - startLeft;
tDelta = target.top - startTop;
newWidth = startWidth + wDelta * hInterpolation;
newHeight = startHeight + hDelta * vInterpolation;
a.left = startLeft + lDelta * hInterpolation;
a.right = a.left + newWidth;
a.top = startTop + tDelta * vInterpolation;
a.bottom = a.top + newHeight;
}
}
}
}
三、向上钻取的实现,类似于向下钻取- DrillUpEffect.as
package jac
{
import mx.charts.effects.SeriesEffect;
import mx.effects.IEffectInstance;
import mx.effects.TweenEffect;
public class DrillUpEffect extends TweenEffect
{
public function DrillUpEffect(target:Object = null)
{
super(target);
instanceClass = DrillUpEffectInstance;
}
public var drillToIndex:Number = 0;
override protected function initInstance(inst:IEffectInstance):void
{
super.initInstance(inst);
DrillUpEffectInstance(inst).drillToIndex = drillToIndex;
}
}
}
import mx.charts.effects.effectClasses.SeriesEffectInstance;
import mx.charts.chartClasses.RenderData;
import flash.geom.Rectangle;
import mx.effects.effectClasses.TweenEffectInstance;
import mx.charts.chartClasses.Series;
class DrillUpEffectInstance extends TweenEffectInstance
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor.
*/
public function DrillUpEffectInstance(target:Object)
{
super(target);
}
public var drillToIndex:Number;
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
/**
* @private
*/
private var _drillBounds:Rectangle;
private var _state:String = "";
/**
* @private
*/
private var dstRenderData:RenderData;
private var srcRenderData:RenderData;
private var targetBounds:Array;
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override public function play():void
{
var targetSeries:Series = Series(target);
srcRenderData = RenderData(targetSeries.getRenderDataForTransition("hide"));
dstRenderData = RenderData(targetSeries.getRenderDataForTransition("show"));
targetSeries.getElementBounds(srcRenderData);
targetSeries.getElementBounds(dstRenderData);
if(drillToIndex >= srcRenderData.elementBounds.length)
drillToIndex = 0;
var dstCount:Number= dstRenderData.elementBounds.length;
var srcCount:Number = srcRenderData.elementBounds.length;
if(drillToIndex < srcRenderData.elementBounds.length)
{
_drillBounds = dstRenderData.elementBounds[drillToIndex].clone();
targetBounds = [];
for(var i:int = 0;i<srcCount;i++)
{
targetBounds[i] = srcRenderData.elementBounds[i].clone();
}
}
else
{
_drillBounds = null;
}
targetSeries.transitionRenderData = srcRenderData;
targetSeries.invalidateDisplayList();
_state = "merging";
// Create a tween to move the object
tween = createTween(this, [ 0 ],
[ 1 ], duration);
}
/**
* @private
*/
override public function onTweenUpdate(values:Object):void
{
var targetSeries:Series = Series(target);
super.onTweenUpdate(values);
var value:Number = values[0];
if(_drillBounds == null)
return;
var targetBounds:Array = targetBounds;
var n:int;
var i:int;
var interpolation:Number;
var v:Rectangle;
if(_state == "merging")
{
n = srcRenderData.filteredCache.length;
interpolation = value/.5;
layoutDestination(interpolation);
if(value >= .5)
{
_state = "holding";
targetSeries.transitionRenderData = dstRenderData;
targetSeries.invalidateDisplayList();
targetSeries.validateNow();
n = dstRenderData.filteredCache.length;
for (i = 0; i < n; i++)
{
if(i != drillToIndex)
dstRenderData.filteredCache[i].itemRenderer.alpha = 0;
else
dstRenderData.filteredCache[i].itemRenderer.alpha = 1;
}
}
}
if (_state == "holding")
{
if(value >= .9)
{
_state = "showing";
}
}
if(_state == "showing")
{
interpolation = Math.max(value-.9,0)/.1;
n = dstRenderData.filteredCache.length;
for (i = 0; i < n; i++)
{
if(i == drillToIndex)
dstRenderData.filteredCache[i].itemRenderer.alpha = 1;
else
dstRenderData.filteredCache[i].itemRenderer.alpha = interpolation;
}
}
targetSeries.invalidateDisplayList();
}
private function layoutDestination(interpolation:Number):void
{
var n:Number = srcRenderData.filteredCache.length;
var endWidth:Number = _drillBounds.width / n;
var endHeight:Number = _drillBounds.height;
var activeBounds:Array = srcRenderData.elementBounds;
var a:Rectangle;
var verticalInterpolation:Number = Math.pow(interpolation,1/4);
for (var i:int = 0; i < n; i++)
{
var endLeft:Number = _drillBounds.left + endWidth * i;
var itemBounds:Rectangle = targetBounds[i];
a = activeBounds[i];
var wDelta:Number = endWidth - itemBounds.width;
var hDelta:Number = endHeight - itemBounds.height;
var lDelta:Number = endLeft - itemBounds.left;
var tDelta:Number = _drillBounds.top - itemBounds.top;
var newWidth:Number = itemBounds.width + wDelta * interpolation;
var newHeight:Number = itemBounds.height + hDelta * verticalInterpolation;
a.left = itemBounds.left + lDelta * interpolation;
a.right = a.left + newWidth;
a.top = itemBounds.top + tDelta * verticalInterpolation;
a.bottom = a.top + newHeight;
}
}
}
相关推荐
自己开发的Flex图片移动例子,如有想学习的,可以下来学习一下。
Flex例子Flex例子Flex例子Flex例子Flex例子Flex例子
简单的 flex HttpService例子,可供初学者参考
在提供的“flex 3D 例子及3D资源包”中,你可能找到了以下内容: 1. 示例项目:这些项目展示了如何使用Flex 3D创建各种3D效果,比如旋转、缩放、平移的对象,以及更复杂的效果如3D模型的动画、碰撞检测和用户交互。...
这个"flex鱼眼显示图片的例子"是一个Flex项目,它展示了如何使用Flex技术实现一个鱼眼效果的图片显示功能。鱼眼效果通常指的是将图像扭曲成类似鱼眼镜头所拍摄的弧形视野,这种效果在视觉上往往能带来独特的体验。 ...
这个"Flex4.6+java+servlet上传图片例子+图片上传预览"的项目,结合了前端的Flex技术和后端的Java Servlet,为我们提供了一个完整的解决方案。下面将详细解释这个项目的各个组成部分及其工作原理。 首先,让我们来...
Flickr是一个知名的图片分享网站,这个例子可能是关于如何使用Flex显示和操作Flickr上的图片数据。 5. 数据绑定:Flex支持强大的数据绑定机制,允许UI组件的状态自动反映模型数据的变化,反之亦然。在例子中,可能...
Flex4是一种基于ActionScript 3.0的开源框架,用于构建富互联网应用程序(RIA)。它提供了强大的组件库、数据绑定和高级图形功能,使得开发者能够创建具有高度交互性和视觉吸引力的Web应用。在Flex4中,`HTTPService...
【Flex + Java简单例子】是关于使用Flex与Java进行跨域数据交互的一个基础教程,主要涉及Flex客户端和Java服务器端的配置与开发。这个例子旨在展示如何通过BlazeDS库在Flex前端和Java后端之间建立通信。 首先,我们...
在这个“flex右键例子源码”中,我们可以深入学习如何在Flex应用程序中实现自定义的右键菜单功能。 1. **ActionScriptProperties**: 这个文件通常包含关于ActionScript编译器的设置,如编译器警告级别、优化选项...
flex 画图的例子,很不错 //画圆角矩形 private function circleRect(cRectX:Number, cRectY:Number, cRectWidth:Number, cRectHeight:Number, cRectDU:Number):void{ cRectBoxID.graphics.clear(); if...
是一个linux环境下运行的flex air例子,有源码.
FLex MenuBar的小例子,可以实现下拉菜单的效果,可直接拷贝使用
本资源“FLex例子大全,绝对源码”包含了多个Flex应用的实例,可以帮助开发者深入理解Flex的使用和功能。 1. **Flex加载图片实现**: 在Flex中,我们可以使用`Loader`类来加载图像。`Loader`类提供了加载各种类型...
《FLASH-FLEX3.0开发教程中文版(例子源码)》是一份全面介绍Adobe Flex 3.0技术的教程,特别适合初学者和有一定基础的开发者深入学习。Flex是基于ActionScript 3.0的开放源代码框架,主要用于构建富互联网应用程序...
这个例子“Flex中利用HTTPService标签动态导入XML文件”展示了如何在Flex应用中通过HTTPService组件来获取和处理XML数据。 在Flex中,HTTPService组件允许开发者发送HTTP请求到服务器,并接收返回的数据。这些数据...
flex bison使用c++方式实现的例子 flex bison使用c++方式实现的例子
Flex开发是一种基于Adobe Flash Player或Adobe AIR运行时的富互联网应用程序(RIA)开发技术。它提供了强大的用户界面设计工具和编程框架,使得开发者能够构建具有交互性和动态效果的应用程序。本示例着重介绍如何在...
这个"flex例子.flex源程序"很显然是一个Flex开发的学习资源,它包含了一个或多个示例项目,用于帮助开发者理解和掌握Flex编程的基本概念和实践。 Flex的主要组件包括MXML和ActionScript,它们是构建Flex应用的两大...
3. 缩略图与全屏切换:为了实现缩放效果,可以添加两个按钮,分别用于查看缩略图和全屏展示图片。通过处理按钮的click事件,我们可以更改图片的大小或打开新的视图来显示全屏图像。 4. 动画效果:为了提升用户体验,...