6 Replies Latest reply on Apr 9, 2007 10:27 AM by compubrook

    Update Chart for Live Data

    compubrook
      I have a database collecting data live and a php script that generates an xml file of all the data when it is called. I have an Accordian with several charts of data on each page. Currently, the xml file is called when the chart is created, so if the chart is open for a period of time the data is no longer up-to-date. I would like the xml file to be called every time someone flips the page on the accordian, or even every 5 minutes or so. Has anyone out there had any experience with this? My assumption is that I need to call the data using an AS script and altering the an event function, but I don't know where to begin.

      Thanks for any help available!
        • 1. Re: Update Chart for Live Data
          peterent Level 2
          When you change children on the Accordion, the Accordion throws a change event. You can use that event to fetch data:

          <mx:Accordion change="getMoreData(event)" ... >

          Have the getMoreData() function look at the Accordion's selectedChild (or selectedIndex) to tell you which chart is being viewed.

          If you want to get more data every 5 minutes, use a Timer (see the Timer class for details and an example).
          • 2. Re: Update Chart for Live Data
            compubrook Level 1
            Why would I need to look at the selectedchild of the accordian? Would the following not work?

            <mx:Script>
            <![CDATA[

            import mx.events.*;
            import mx.rpc.events.*;

            [Bindable] public var chartdata:ArrayCollection;
            [Bindable] private var newchartdata:ArrayCollection;

            private function getMoreData(event):void
            {
            newchartdata = pSrv.lastResult.data.point;
            chartdata = new ArrayCollection(newchartdata.source);
            }

            ]]>
            </mx:Script>
            • 3. Re: Update Chart for Live Data
              peterent Level 2
              I thought you might want to know which child of the Accordion on was picked to determine what data to fetch.
              • 4. Re: Update Chart for Live Data
                compubrook Level 1
                Ok, thanks for the info.

                I can't seem to get it working though. I'll include the script below:

                <mx:Script>
                <![CDATA[

                import mx.events.*;
                import mx.rpc.events.*;

                [Bindable] public var chartdata:ArrayCollection;
                [Bindable] private var newchartdata:ArrayCollection;

                private function getMoreData():void
                {
                newchartdata = pSrv.lastResult.data.point;
                chartdata = new ArrayCollection(newchartdata.source);
                }

                ]]>
                </mx:Script>

                The Accordian call is the floowing:

                <mx:Accordion x="0" y="0" creationComplete="pSrv.send();" width="100%" height="100%" change="getMoreData()" headerHeight="50" themeColor="#80ffff" fontSize="17" color="#000000" cornerRadius="0">


                and the chart call is the following:

                <mx:Panel x="0" y="0" width="100%" height="100%" layout="absolute" borderStyle="none">
                <mx:LineChart id="T_OFFICE" width="100%" height="100%" dataProvider="{chartdata}" showDataTips="true" fontFamily="Verdana" fontSize="12" >


                Am I missing the specific event? The data loads using this, but does not update.
                • 5. Re: Update Chart for Live Data
                  peterent Level 2
                  Each time you want data you need to request it, so getMoreData should call pSrv.send(). When the data comes back it needs to follow the same process as it did when you got it the first time.
                  • 6. Re: Update Chart for Live Data
                    compubrook Level 1
                    Awesome! Peter, you'll make a Flex devy out of me yet!

                    Here is my script if anyone has the same problem:

                    <mx:Script>
                    <![CDATA[

                    import mx.events.*;
                    import mx.rpc.events.*;

                    [Bindable] public var chartdata:ArrayCollection;
                    [Bindable] private var newchartdata:ArrayCollection;

                    private function getMoreData():void
                    {
                    pSrv.send();
                    }

                    ]]>
                    </mx:Script>

                    All it does is call my HTTP service everytime the Accordian changes.... too easy!