views:

29

answers:

2

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>
A: 

You can try using E4X syntax:

dataProvider="{languagelist..speakers}"
Robusto
Its not working :(
Saneef
Try putting empty brackets <>...</> around your XML.
Robusto
Also, I don't see where you're actually setting your dataprovider. The source, I mean.
Robusto
@Robusto - I haven't shown the setting the data provider since, in the output I'm getting the langid over the Y-axis.
Saneef
A: 

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