Flex 条形图不起作用

发布于 2024-09-14 01:49:18 字数 1387 浏览 6 评论 0原文

要绘制的 XML 数据:

<?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>

我需要将上面的数据绘制到条形图上,我尝试使用下面的代码但不起作用 我需要根据扬声器标签中的值在 y 轴和条形长度上绘制“Langid”。

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑梦风尘 2024-09-21 01:49:18

您可以尝试使用 E4X 语法:

dataProvider="{languagelist..speakers}"

You can try using E4X syntax:

dataProvider="{languagelist..speakers}"
吻安 2024-09-21 01:49:18

将 mx:BarChart 更改为下面的内容对我有用:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文