0

XML Data to plot:

<?xml version="1.0" encoding="utf-8" ?>
<spearkerslist>
    <speakers langid="afb" countryid="SA" countryalpha3id="SAU">200000</speakers>
    <speakers langid="acw" countryid="SA" countryalpha3id="SAU">6000000</speakers>
    <speakers langid="ars" countryid="SA" countryalpha3id="SAU">8000000</speakers>
    <speakers langid="arb" countryid="SA" countryalpha3id="SAU">206000000</speakers>
</spearkerslist>

The above data I need to plot to a Bar chart, which I tried with code below and not working I need to plot "Langid" on y-axis and bar length based on the value in speakers tag.

<mx:Script>
        <![CDATA[
            private var languagelist:XML = new XML(); //Variable where the XML is stored.
        ]]>
</mx:Script>

<mx:Panel>
    <mx:BarChart id="chrtLangugeVsPopulation" dataProvider="{languagelist.speakers}" showAllDataTips="true">
        <mx:verticalAxis>
            <mx:CategoryAxis 
                dataProvider="{languagelist.speakers.@langid}"
                categoryField="Language"
            />
        </mx:verticalAxis>
        <mx:series>
            <mx:BarSeries
                yField="Language"
                xField="Speakers"
                displayName="Speakers"
            />
        </mx:series>
    </mx:BarChart>
</mx:Panel>
Saneef
  • 8,620
  • 7
  • 29
  • 42

2 Answers2

0

You can try using E4X syntax:

dataProvider="{languagelist..speakers}"
Robusto
  • 31,447
  • 8
  • 56
  • 77
0

Changing mx:BarChart to below, worked for me:

<mx:BarChart id="chrtLangugeVsPopulation" dataProvider="{languagelist.speakers}" showDataTips="true">
    <mx:verticalAxis>
        <mx:CategoryAxis 
            dataProvider="{languagelist.speakers}"
            categoryField="@langid"
        />
    </mx:verticalAxis>
    <mx:series>
        <mx:BarSeries
            yField="@langid"
            xField=""
            displayName="Speakers"
            click="barseries1_clickHandler(event)"
        />
    </mx:series>
</mx:BarChart>
Saneef
  • 8,620
  • 7
  • 29
  • 42