2278539936474029544.bmp  

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="980" height="488" applicationComplete="go()">
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.collections.ArrayCollection;
        import flash.events.MouseEvent;
        import mx.managers.CursorManager;
        import mx.collections.Sort;
        import mx.collections.SortField;
        import flash.external.*;
        import json.*;


        private var cursorId:Number=0;
        [Embed(source="hand.gif")]
        private var handCursorSymbol:Class;
        [Bindable]
        private var prices:ArrayCollection=new ArrayCollection();
        /*private var prices:ArrayCollection=new ArrayCollection([
        {area:"广州市",price:3000,date:2008-01-01},
        {area:"深圳市",price:1000,date:2008-01-01},
        {area:"华山市",price:1500,date:2008-01-01},
        {area:"清远市",price:2200,date:2008-01-01},
        {area:"东莞市",price:3680,date:2008-01-01},
        {area:"中山市",price:4221,date:2008-01-01},
        {area:"梅州市",price:3380,date:2008-01-01},
        {area:"珠海市",price:4101,date:2008-01-01}
        ]);
        */
        
        

        
        private function moveOver():void
        {
            CursorManager.setCursor(handCursorSymbol);
            
        }
        
        private function moveOut(event:MouseEvent):void
        {
            
            CursorManager.removeAllCursors();
        }
        
        private function sortAsc():void
        {
            
            var p_sort_asc:Sort = new Sort();
            
            p_sort_asc.fields=[new SortField("price")];
            prices.sort=p_sort_asc;
            prices.refresh();
        }
        
        private function sortDesc():void
        {
            var p_sort_desc:Sort = new Sort();
            p_sort_desc.fields=[new SortField("price",true,true)];
            prices.sort=p_sort_desc;
            prices.refresh();
            
        }
        
        private function getMaxPrice():int
        {
            var p_sort_desc:Sort = new Sort();
            p_sort_desc.fields=[new SortField("price",true,true)];
            prices.sort=p_sort_desc;
            return int(Number(prices[0].price));
        }
        
        private function getText():String
        {
            return "it is testing javascript access As3 ";            
        }
        
        private function initApp():void
        {
            var s:String=ExternalInterface.call("getJsonData");
            var rawData:String = String(s);
            var prices2:ArrayCollection = new ArrayCollection(JSON.decode(rawData));
    
               
        }
        
        private function Chart_creationComplete():void {
                var msg:Alert;
                linearAxis.interval = Math.floor(100/6);
            }
        
        private function go():void
        {
            var s:String=ExternalInterface.call("getJsonData");
            
            var titletxt:String=ExternalInterface.call("getTitle");
            var rawData:String = String(s);
            var tempprices:ArrayCollection = new ArrayCollection(JSON.decode(rawData));
            var obj:Object=null;
            var i:int=0;
            p1.title="各地区"+titletxt+"价格对比图";
            for(i=0;i<tempprices.length;i++)
            {
                obj=null;
                obj=new Object();
                obj.area=tempprices[i].addr;
                obj.price=tempprices[i].priceM;
                prices.addItem(obj);
            }
            
        }
    ]]>
</mx:Script>
<mx:Style>
    Application{
    
    fontSize:15;
    backgroundColor:#ccc;
    }
    
    ColumnChart{
    fontSize:12;
    color:black;    
    }
    ToolTip{
    fontSize:12;
    color:red;
    
    }
    
    <!--DataTip设置数据提示的样式,对应于 showDataTips=true-->
    DataTip{
    fontSize:12;
    color:red;    
    }
    Button{
    fontSize:12;
    }
</mx:Style>
    <mx:Panel id="p1" x="0" y="0" width="980" height="488" layout="absolute" title="各地区XXXX价格对比图" horizontalAlign="center" verticalAlign="middle">
    <!--showDataTips设置数据提示(柱状图数据提示)-->
        <mx:ColumnChart x="10" y="30" id="char1" width="922" dataProvider="{prices}" height="400" showDataTips="true" creationComplete="Chart_creationComplete()">
        <mx:horizontalAxis>
            <mx:CategoryAxis dataProvider="{prices}" categoryField="area" />
        </mx:horizontalAxis>
        <mx:verticalAxis>
            <mx:LinearAxis id="linearAxis"
                    baseAtZero="false"
                    minorInterval="100"
                    interval="1000" minimum="0"
                    />
        </mx:verticalAxis>
            <mx:series>
                <mx:ColumnSeries displayName="价格" xField="area" yField="price" color="#000000" maxColumnWidth="40">
                 <!--设置横向渐变
                        <mx:fill>
                            <mx:LinearGradient>
                                <mx:entries>
                                    <mx:Array>
                                        <mx:GradientEntry color="#C6D5DD" ratio="0" alpha="100"/>
                                        <mx:GradientEntry color="#336699" ratio="0.1" alpha="100"/>
                                        <mx:GradientEntry color="#ffee00" ratio="0.9" alpha="100"/>
                                        <mx:GradientEntry color="#ffffff" ratio="1" alpha="100"/>
                                    </mx:Array>
                                </mx:entries>
                            </mx:LinearGradient>
                        </mx:fill>-->

                <!--设置柱状图的颜色
                <mx:fill>
                    <mx:SolidColor color="#CCCCCC"/>
                </mx:fill>
                -->
                </mx:ColumnSeries>
            </mx:series>
         
        </mx:ColumnChart>
        <mx:Legend dataProvider="{char1}" y="4" x="18"/>
        <mx:Button x="636" y="10" label="按价格升序" width="104" height="20" click="sortAsc()"/>
        <mx:Button x="758" y="10" label="按价格降序" width="104" height="20" click="sortDesc()"/>
    </mx:Panel>

</mx:Application>

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()