Flex barChart和XML数据

时间:2010-04-17 15:22:34

标签: xml flex

    <Projectlist>
    <Project>
    <ProjectName>Alcoswitch - ToggleSwitches
    </ProjectName>
    <ProjectStatusname>Planning</ProjectStatusname>
    </Project>
    <Project>
    <ProjectName>
    Transverse Wedge</ProjectName>
    <ProjectStatusname>Canceled</ProjectStatusname>
    </Project>
    <Project>
    <ProjectName>High Speed Pluggable I/O</ProjectName>
    <ProjectStatusname>In-Progress</ProjectStatusname>
    </Project>
    <Project>
    <ProjectName>"High Speed Pluggable I/O - Product Breakouts:</ProjectName>
    <ProjectStatusname>In-Progress</ProjectStatusname>
    </Project>
    <Project>
    <ProjectName>Circular Plastic Connector (CPC)</ProjectName>
    <ProjectStatusname>In-Progress</ProjectStatusname>
    </Project>
    </Projectlist>

这是我收到的XML数据,如何在条形图中显示。

<mx:BarChart id="barChart"
             showDataTips="true" dataProvider="{ProjectStateInfo}"

             width="100%"
             height="100%">
             <mx:horizontalAxis>
                 <mx:CategoryAxis categoryField="ProjectStatusname"/>
             </mx:horizontalAxis>
        <mx:verticalAxis>
            <mx:CategoryAxis categoryField="ProjectName"/>
        </mx:verticalAxis>
        <mx:series>
            <mx:BarSeries id="barSeries" visible="true"
                    yField="ProjectName"
                    xField="ProjectStatusname"
                    displayName="ProjectStatusname"
                     />


        </mx:series>
    </mx:BarChart>

我的X轴显示正在进行的多个值,但我只需要一个。是否可以使用BarChart来表示这种关系。任何其他Flex图表都是可建议的。

1 个答案:

答案 0 :(得分:1)

您需要构建一个包含所有项目状态名称的数组(或其他数据结构),并将其用于水平轴。你需要它来消除重复。

var array:Array = ["Planning","Canceled","In-Progress"];

<mx:BarChart id="barChart"
         showDataTips="true" dataProvider="{xml.Project}"
         width="100%"
         height="100%">
         <mx:horizontalAxis>
             <mx:CategoryAxis dataProvider="{array}"/>
         </mx:horizontalAxis>
         <mx:verticalAxis>
            <mx:CategoryAxis dataProvider="{xml.Project}" categoryField="ProjectName"/>
         </mx:verticalAxis>
         <mx:series>
            <mx:BarSeries id="barSeries" visible="true"
                yField="ProjectName"
                xField="ProjectStatusname"
                displayName="ProjectStatusname"
                 />
         </mx:series>           
</mx:BarChart>