-
Setting DataProvider to One Element in ArrayCollection
So the following MXML works fine. The problem is I want to isolate the chart to show the data for one player at a time. How would I do that? I tried every combination I can think of. But nothing works. Here are some example of things I've tried.
1 - playersCollection = e.result.rss.channel.player[0];
2 - dataProvider="{playersCollection[0]}"
3 - dataProvider="{playersCollection.source[0]}"
I even tried using XMLList, and Arrays. Do you guys have any ideas?
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="getter.send();" width="100%" height="100%" layout="horizontal" pageTitle="Graph Example" usePreloader="true">
<mx:Script>
<![CDATA[
import mx.managers.CursorManager;
import adobe.utils.CustomActions;
import mx.rpc.events.InvokeEvent;
import flash.events.Event;
import mx.controls.Alert;
import mx.rpc.events.*;
import mx.collections.ArrayCollection;
[Bindable]
private var playersCollection:ArrayCollection;
private var playerXML:XML;
private var playerRosterXMLList:XMLList;
private function finishedLoading( e:ResultEvent ):void {
CursorManager.removeBusyCursor();
playersCollection = e.result.rss.channel.player;
}
private function startedLoading( e:InvokeEvent ):void {
CursorManager.setBusyCursor();
}
private function labelChanged( e:Event ):void {
if ( e.currentTarget.selectedItem.data == "1" ) {
columnChart.visible = false;
lineChart.visible = true;
bar.visible = false;
} else if ( e.currentTarget.selectedItem.data == "2" ) {
columnChart.visible = true;
lineChart.visible = false;
bar.visible = false;
} else if ( e.currentTarget.selectedItem.data == "3" ) {
columnChart.visible = false;
lineChart.visible = false;
bar.visible = true;
}
}
]]>
</mx:Script>
<mx:HTTPService id="getter" url="data/sports-data.xml" invoke="startedLoading(event)" result="finishedLoading(event);"/>
<mx:Panel width="50%" height="100%" id="mainpanel" title="Basketball Stats" >
<mx:Accordion id="ac" width="100%" height="100%" selectedIndex="0" historyManagementEnabled="false" >
<mx:VBox label="Question 1" height="100%">
<mx:DataGrid width="100%" height="300" dataProvider="{playersCollection}">
<mx:columns>
<mx:DataGridColumn headerText="Player Name" dataField="name"/>
<mx:DataGridColumn headerText="Position" dataField="pos"/>
<mx:DataGridColumn headerText="Points" dataField="points"/>
<mx:DataGridColumn headerText="Rebounds" dataField="rebounds"/>
<mx:DataGridColumn headerText="Assists" dataField="assists"/>
<mx:DataGridColumn headerText="Steals" dataField="steals"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
<mx:VBox label="Question 2" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 2"/>
</mx:VBox>
<mx:VBox label="Question 3" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 3"/>
</mx:VBox>
<mx:VBox label="Question 4" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 4"/>
</mx:VBox>
<mx:VBox label="Question 5" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 5"/>
</mx:VBox>
<mx:VBox label="Question 6" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 6"/>
</mx:VBox>
<mx:VBox label="Question 7" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 7"/>
</mx:VBox>
<mx:VBox label="Question 8" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 8"/>
</mx:VBox>
<mx:VBox label="Question 9" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 9"/>
</mx:VBox>
<mx:VBox label="Question 10" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 10"/>
</mx:VBox>
<mx:VBox label="Question 11" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 11"/>
</mx:VBox>
<mx:VBox label="Question 12" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 12"/>
</mx:VBox>
<mx:VBox label="Question 13" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 13"/>
</mx:VBox>
<mx:VBox label="Question 14" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 14"/>
</mx:VBox>
<mx:VBox label="Question 15" height="100%">
<mx:TextArea width="100%" height="100%" borderThickness="0" htmlText="Here is question 15"/>
</mx:VBox>
</mx:Accordion>
</mx:Panel>
<mx:Panel width="50%" height="100%" id="chartpanel" title="Charts" layout="absolute">
<mx:ComboBox id="selector" change="labelChanged(event);" x="0" y="0">
<mx:ArrayCollection>
<mx:Object label="Line Graph" data="1"/>
<mx:Object label="Column Chart" data="2"/>
<mx:Object label="Bar Chart" data="3"/>
</mx:ArrayCollection>
</mx:ComboBox>
<mx:Legend dataProvider="{lineChart}" direction="horizontal" x="150" y="0" />
<mx:ColumnChart id="columnChart" y="50" visible="false" dataProvider="{playersCollection}" showDataTips="true" width="100%" height="85%">
<mx:horizontalAxis>
<mx:CategoryAxis
dataProvider="{playersCollection}" categoryField="name"/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries xField="name" yField="points" displayName="Points"/>
<mx:ColumnSeries xField="name" yField="rebounds" displayName="Rebounds"/>
<mx:ColumnSeries xField="name" yField="assists" displayName="Assists"/>
<mx:ColumnSeries xField="name" yField="steals" displayName="Steals"/>
</mx:series>
</mx:ColumnChart>
<mx:BarChart id="bar" visible="false" y="50" width="100%" height="85%" showDataTips="true" dataProvider="{playersCollection}">
<mx:verticalAxis>
<mx:CategoryAxis categoryField="name"/>
</mx:verticalAxis>
<mx:series>
<mx:BarSeries yField="name" xField="points" displayName="Points"/>
<mx:BarSeries yField="name" xField="rebounds" displayName="Rebounds"/>
<mx:BarSeries yField="name" xField="assists" displayName="Assists"/>
<mx:BarSeries yField="name" xField="steals" displayName="Steals"/>
</mx:series>
</mx:BarChart>
<mx:LineChart id="lineChart" y="50" visible="true" width="100%" height="85%" dataProvider="{playersCollection}" showDataTips="true">
<mx:horizontalAxis>
<mx:CategoryAxis id="a1" dataProvider="{playersCollection}" categoryField="name"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis id="a2"/>
</mx:verticalAxis>
<mx:series>
<mx:LineSeries yField="points" displayName="Points"/>
<mx:LineSeries yField="rebounds" displayName="Rebounds"/>
<mx:LineSeries yField="assists" displayName="Assists"/>
<mx:LineSeries yField="steals" displayName="Steals"/>
</mx:series>
</mx:LineChart>
</mx:Panel>
</mx:Application>
-
Here is the XML source
Just the first two player nodes, because it's pretty long.
Code:
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Fantasy News / NBA Weekly Top Performances</title>
<link>http://www.fantasysp.com</link>
<description>NBA Weekly Top Performances</description>
<copyright>Copyright 2009</copyright>
<player>
<name>LeBron James</name>
<nameb>LeBron_James</nameb>
<desc><span class="blueme">Points 52.3</span> <br /> FGs: 10.3 / 18.7 <br />Assists: 6.7 <br /> Steals: 3.0 <br /> Rebounds: 7.3 <br /> Turnovers: 3.0</desc>
<team>cle</team>
<pos>SF</pos>
<points>52.3</points>
<assists>6.7</assists>
<steals>3.0</steals>
<rebounds>7.3</rebounds>
<picture>http://www.fantasysp.com/images/nba/400553.jpg</picture>
<link>http://www.fantasysp.com/nba_player_news/LeBron_James/</link>
<teamlink>http://www.fantasysp.com/nba_team_news/cle</teamlink>
<poslink>http://www.fantasysp.com/nba_top_100/SF/7/</poslink>
</player>
<player>
<name>Dwyane Wade</name>
<nameb>Dwyane_Wade</nameb>
<desc><span class="blueme">Points 51.3</span> <br /> FGs: 10.8 / 21.5 <br />Assists: 7.0 <br /> Steals: 2.3 <br /> Rebounds: 4.0 <br /> Turnovers: 3.5</desc>
<team>mia</team>
<pos>SG</pos>
<points>51.3</points>
<assists>7.0</assists>
<steals>2.3</steals>
<rebounds>7.3</rebounds>
<picture>http://www.fantasysp.com/images/nba/400578.jpg</picture>
<link>http://www.fantasysp.com/nba_player_news/Dwyane_Wade/</link>
<teamlink>http://www.fantasysp.com/nba_team_news/mia</teamlink>
<poslink>http://www.fantasysp.com/nba_top_100/SG/7/</poslink>
</player>
<player>
<name>Vince Carter</name>
<nameb>Vince_Carter</nameb>
<desc><span class="blueme">Points 49.3</span> <br /> FGs: 7.3 / 14.0 <br />Assists: 10.0 <br /> Steals: 2.7 <br /> Rebounds: 6.3 <br /> Turnovers: 2.7</desc>
<team>nj</team>
<pos>SG</pos>
<points>49.3</points>
<assists>10.0</assists>
<steals>2.7</steals>
<rebounds>7.3</rebounds>
<picture>http://www.fantasysp.com/images/nba/20595.jpg</picture>
<link>http://www.fantasysp.com/nba_player_news/Vince_Carter/</link>
<teamlink>http://www.fantasysp.com/nba_team_news/nj</teamlink>
<poslink>http://www.fantasysp.com/nba_top_100/SG/7/</poslink>
</player>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|