在弹性图表中使用多个轴和动画

时间:2009-02-16 13:34:38

标签: flex animation charts

我必须显示一个包含两个系列的折线图,每个系列都带有“日期值”,因为每个系列中的日期相距很远,它们有自己的水平轴。
问题是当我向系列添加动画时,动画开始循环并且永不停止 我的问题是:我做错了什么?这是灵活图表中的错误吗? 有谁知道如何解决这个问题?
这是一个示例代码: `

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.collections.ArrayCollection;

        [Bindable]
        private var arr1:ArrayCollection = new ArrayCollection([
            {date_1:"01/2008", value_1:2, date_2:"01/2007", value_2:4},
            {date_1:"02/2008", value_1:5, date_2:"02/2007", value_2:7},
            {date_1:"03/2008", value_1:4, date_2:"03/2007", value_2:3},
            {date_1:"04/2008", value_1:7, date_2:"04/2007", value_2:5}]);

        [Bindable]
        private var arr2:ArrayCollection = new ArrayCollection([
            {date_1:"01/2008", value_1:4, date_2:"01/2007", value_2:7},
            {date_1:"02/2008", value_1:3, date_2:"02/2007", value_2:5},
            {date_1:"03/2008", value_1:5, date_2:"03/2007", value_2:2},
            {date_1:"04/2008", value_1:4, date_2:"04/2007", value_2:5}]);

        private var temp:Boolean = false;

        private function switchGraf():void{
            if( temp){
                series_1.dataProvider = arr1;
                series_2.dataProvider = arr1;

            } else {
                series_1.dataProvider = arr2;
                series_2.dataProvider = arr2;
            }
            temp = !temp;
        }
    ]]>
</mx:Script>

<mx:SeriesSlide direction="right" duration="1000" id="aniShow"/>
<mx:SeriesSlide direction="left" duration="1000" id="aniHide"/>

<mx:ComboBox change="switchGraf()">
    <mx:String>one</mx:String>
    <mx:String>two</mx:String>
</mx:ComboBox>

<mx:LineChart>
    <mx:series>
        <mx:LineSeries id="series_1" yField="value_1" dataProvider="{arr1}" showDataEffect="aniShow" hideDataEffect="aniHide">
            <mx:horizontalAxis>
                <mx:CategoryAxis id="axis_1" categoryField="date_1"/>
            </mx:horizontalAxis>
        </mx:LineSeries>
        <mx:LineSeries id="series_2" yField="value_2" dataProvider="{arr1}">
            <mx:horizontalAxis>
                <mx:CategoryAxis id="axis_2" categoryField="date_2"/>
            </mx:horizontalAxis>
        </mx:LineSeries>
    </mx:series>
    <mx:verticalAxis>
        <mx:LinearAxis minimum="0" maximum="10"/>
    </mx:verticalAxis>
    <mx:horizontalAxisRenderers>
        <mx:AxisRenderer placement="bottom" axis="{axis_1}"/>
        <mx:AxisRenderer placement="top" axis="{axis_2}"/>
    </mx:horizontalAxisRenderers>
</mx:LineChart>

`

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

好吧,我没有答案,我不知道为什么会这样。 但我找到了解决问题的方法:
您必须在系列结束时删除系列中的效果,然后在更改系列的数据提供者时需要将其添加回来,如下所示:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" 
backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #FFFFFF]">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.collections.ArrayCollection;

        [Bindable]
        private var arr1:ArrayCollection = new ArrayCollection([
            {date_1:"01/2008", value_1:2, date_2:"01/2008", value_2:4},
            {date_1:"02/2008", value_1:5, date_2:"02/2008", value_2:3},
            {date_1:"03/2008", value_1:4, date_2:"03/2008", value_2:5},
            {date_1:"04/2008", value_1:7, date_2:"04/2008", value_2:4}]);

        [Bindable]
        private var arr2:ArrayCollection = new ArrayCollection([
            {date_1:"01/2007", value_1:4, date_2:"01/2007", value_2:7},
            {date_1:"02/2007", value_1:7, date_2:"02/2007", value_2:5},
            {date_1:"03/2007", value_1:3, date_2:"03/2007", value_2:2},
            {date_1:"04/2007", value_1:5, date_2:"04/2007", value_2:5}]);


        private var temp:Boolean = false;


        private function addAnimacion():void{
            serie_1.setStyle("showDataEffect", "aniShow");
            serie_2.setStyle("showDataEffect", "aniShow");
        }

        private function removeAnimacion():void{
            serie_1.setStyle("showDataEffect", "");
            serie_2.setStyle("showDataEffect", "");
        }

        private function switchGraf():void{

            addAnimacion();

            if( temp){
                serie_1.dataProvider = arr1;
                serie_2.dataProvider = arr1;

            } else {
                serie_1.dataProvider = arr2;
                serie_2.dataProvider = arr2;
            }

            temp = !temp;
        }
    ]]>
</mx:Script>

<mx:WipeRight duration="1000" id="aniShow" showTarget="true" effectEnd="removeAnimacion();"/>

<mx:ComboBox change="switchGraf()">
    <mx:String>one</mx:String>
    <mx:String>two</mx:String>
</mx:ComboBox>

<mx:LineChart>
    <mx:series>
        <mx:LineSeries id="serie_1" yField="value_1" dataProvider="{arr1}">
            <mx:horizontalAxis>
                <mx:CategoryAxis id="ejeAct" categoryField="date_1"/>
            </mx:horizontalAxis>
        </mx:LineSeries>
        <mx:LineSeries id="serie_2" yField="value_2" dataProvider="{arr1}">
            <mx:horizontalAxis>
                <mx:CategoryAxis id="ejeAnt" categoryField="date_2"/>
            </mx:horizontalAxis>
        </mx:LineSeries>
    </mx:series>
    <mx:verticalAxis>
        <mx:LinearAxis minimum="0" maximum="10"/>
    </mx:verticalAxis>
    <mx:horizontalAxisRenderers>
        <mx:AxisRenderer placement="bottom" axis="{ejeAct}"/>
        <mx:AxisRenderer placement="top" axis="{ejeAnt}"/>
    </mx:horizontalAxisRenderers>
</mx:LineChart>

希望这能有所帮助!