3 Replies Latest reply on Jul 18, 2008 4:15 PM by ntsiii

    External XML file for a chart

    ice1000
      I'm new to Flex but using the samples & documentation, I have been able to create a simple chart that uses an external xml file for it's data source.

      I'm not sure how get to the next step, which is:
      Have the chart listen to any changes in the xml file and update itself at run time.

      Can anyone point me to samples or docs that can help me out?

      Thanks
        • 1. Re: External XML file for a chart
          SujitG Level 2
          Hi,

          How is the XML file going to be updated? Is the XML file going to be updated using the same application or some other application? When you said external XML file is it on the server or is it embed with SWF?

          You can also have a look at the Data Binding feature in Flex. Please find quick start guide on data binding at the URL below.

          http://www.adobe.com/devnet/flex/quickstart/using_data_binding/

          Hope this helps.
          • 2. Re: External XML file for a chart
            ice1000 Level 1
            Sujit,

            The XML file will be updated by another application. What I meant by external XML file was that I followed the steps in the documentation on using an xml file as a data provider:
            quote:

            You can define data provider data in a structured file. The following example shows the contents of the data.xml file:
            <data>
            <result month="Jan-04">
            <apple>81768</apple>
            <orange>60310</orange>
            <banana>43357</banana>
            </result>
            <result month="Feb-04">
            <apple>81156</apple>
            <orange>58883</orange>
            <banana>49280</banana>
            </result>
            </data>
            You can load the file directly as a source of a Model, as the following example shows:
            <?xml version="1.0"?>
            <!-- charts/XMLFileDataProvider.mxml -->
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
            <mx:Model id="results" source="../assets/data.xml"/>
            <mx:Panel title="Line Chart">
            <mx:LineChart id="myChart" dataProvider="{results.result}" showDataTips="true">
            <mx:horizontalAxis>
            <mx:CategoryAxis categoryField="month"/>
            </mx:horizontalAxis>
            <mx:series>
            <mx:LineSeries yField="banana" displayName="Banana"/>
            <mx:LineSeries yField="apple" displayName="Apple"/>
            <mx:LineSeries yField="orange" displayName="Orange"/>
            </mx:series>
            </mx:LineChart>
            <mx:Legend dataProvider="{myChart}"/>
            </mx:Panel>
            </mx:Application>


            The xml file is on the server but not embedded. When I change the xml file, the swf does not update unless I recompile.

            I will read over the link you provided.

            Thanks for your help!
            • 3. Re: External XML file for a chart
              ntsiii Level 3
              source="path" is a *compile time* operation, so the xml is in fact embedded in the swf.

              If you want run-time loading, then use HTTPService.

              Also, do not use mx:Model, and if you use HTTPService, be sure to set resultFormat="e4x".

              Search the archives if you want to know why, and read more detail and examples.

              Tracy