Mega Code Archive

 
Categories / Flex / Chart
 

YValue of the ColumnSeriesItem represents the percentage a series takes up in a 100% chart

<!-- Code from Flex 4 Documentation "Using Adobe Flex 4". This user guide is licensed for use under the terms of the Creative Commons Attribution  Non-Commercial 3.0 License.  This License allows users to copy, distribute, and transmit the user guide for noncommercial  purposes only so long as    (1) proper attribution to Adobe is given as the owner of the user guide; and    (2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms.  The best way to provide notice is to include the following link.  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ --> <!-- charts/HitDataCastingWithPercent.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()">     <mx:Script>         import mx.collections.ArrayCollection;         import mx.charts.HitData;         import mx.charts.series.ColumnSeries;         import mx.charts.series.items.ColumnSeriesItem;         [Bindable]         public var dataSet:ArrayCollection = new ArrayCollection([             {Month:"Jan", Income:1500, Profit:90},             {Month:"Feb", Income:1200, Profit:100},             {Month:"Mar", Income:750, Profit:150}             ]);         public var b:Boolean = true;         public function myDataTipFunction(e:HitData):String {             var s:String;             s = "<B>" + ColumnSeries(e.element).displayName + "</B>\n";             s += "<I>Income:</I> <FONT COLOR='#339966'>$" + e.item.Income + "</FONT>\n";             s += "<I>Expenses:</I> <FONT COLOR='#FF0000'>$" + (e.item.Income - e.item.Profit) + "</FONT>\n";             s += "------------------------\n";             s += "<I>Profit:</I> $" + e.item.Profit + "\n";             // The value of the Income will always be 100%, so exclude adding that to the DataTip. Only             // add percent when the user gets the Profit DataTip.             var percentValue:Number = Number(ColumnSeriesItem(e.chartItem).yValue);             if (percentValue < 100) {                 s += "Profit was equal to about <B>" +                 Math.round(percentValue) + "</B>% of the income.\n";             }             return s;             //return e.item.Month + ":<B>$" + e.item.Profit + "</B>";         }       </mx:Script>     <mx:Panel title="Accessing ChartItems from HitData Objects">         <mx:ColumnChart id="myChart" dataProvider="{dataSet}" type="100%"             dataTipFunction="myDataTipFunction" showDataTips="true">             <mx:horizontalAxis>                 <mx:CategoryAxis categoryField="Month" />             </mx:horizontalAxis>             <mx:series>                 <mx:ColumnSeries yField="Profit" displayName="Profit '06" />                 <mx:ColumnSeries yField="Income" displayName="Income '06" />             </mx:series>         </mx:ColumnChart>         <mx:Legend dataProvider="{myChart}" />     </mx:Panel> </mx:Application>