tags:

views:

508

answers:

2

Hi Everyone,

I'm new at Flex and I wanted to know how to read an xml file to pull its data into a chart, using Flex Builder 3.

Even though I've read and done some tutorials, I haven't seen any of them loading the data dynamically. For example, I'd like to have an xml like the following:

<data>
    <result month="April-09">
        <visitor>
            <value>8</value>
            <fullname>Brian Roisentul</fullname>
            <coid>C01111</coid>
        </visitor>
        <visitor>
      <value>15</value>
      <fullname>Visitor 2</fullname>
      <coid>C02222</coid>
        </visitor>
        <visitor>
      <value>20</value>
      <fullname>Visitor 3</fullname>
      <coid>C03333</coid>
     </visitor>
    </result>
    <result month="July-09">
        <visitor>
            <value>15</value>
            <fullname>Brian Roisentul</fullname>
            <coid>C01111</coid>
        </visitor>
        <visitor>
      <value>6</value>
      <fullname>Visitor 2</fullname>
      <coid>C02222</coid>
        </visitor>
        <visitor>
      <value>12</value>
      <fullname>Visitor 3</fullname>
      <coid>C03333</coid>
     </visitor>
    </result>
    <result month="October-09">
        <visitor>
            <value>10</value>
            <fullname>Brian Roisentul</fullname>
            <coid>C01111</coid>
        </visitor>
        <visitor>
      <value>14</value>
      <fullname>Visitor 2</fullname>
      <coid>C02222</coid>
        </visitor>
        <visitor>
      <value>6</value>
      <fullname>Visitor 3</fullname>
      <coid>C03333</coid>
     </visitor>
    </result>   
</data>

and then loop through every "visitor" xml item and draw their values, and display their "fullname" when the mouse is over their line.

If you need some extra info, please let me just know.

Thanks,

Brian

A: 

The line chart example in the livedocs would help you to get started. They are using an array collection - you can replace it with an XMLListCollection.

//assuming that 'xml' is the name of the variable holding the data
[Bindable]
public var visitors:XMLListCollection = new XMLListCollection(xml.result.visitor);

You can use visitors in the place of expenseAC in their example.

Amarghosh
A: 

Thanks for that article.

But, what if I wanted to include into the chart an xml like the following:

<topics>
  <period month="Oct-09">
      <topic topicid="T4280814323819" title="Green Business"><value>1</value></topic>
      <topic topicid="T11260215353282" title="Performance Metrics"><value>2</value></topic>
  </period>
  <period month="Apr-09">
      <topic topicid="T4280814323819" title="Green Business"><value>1</value></topic>
      <topic topicid="T11260215353282" title="Performance Metrics"><value>8</value></topic>
  </period>
  <period month="Oct-08">
      <topic topicid="T4280814323819" title="Green Business"><value>8</value></topic>
      <topic topicid="T11260215353282" title="Performance Metrics"><value>34</value></topic>
  </period>    
</topics>

This means that I won't have one line per each "profit", "expenses", or "amount", but I'll have all "topic" items instead.

Do you undestand what I want to accomplish?

Regards,

Brian

Brian Roisentul
I don't have much experience working with charts, but I guess you would have to rewrite the data provider.
Amarghosh
Try to put follow up questions in comments rather than new posts because users will be notified when there is a new comment to their posts, not when there is a new answer to a question that they've answered.
Amarghosh
Is it too complicated to rewrite the data provider?If not, do you know any other tool or programming language to accomplish cool charts from xml?
Brian Roisentul