Create two functions that access complex data for both the axis and the series : Column Chart Axis « Chart « Flex






Create two functions that access complex data for both the axis and the series

Create two functions that access complex data for both the axis and the series
            

<!--
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/DataFunctionExample.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark"
    height="600">
    <fx:Script> 
        import mx.charts.chartClasses.AxisBase; 
        import mx.charts.chartClasses.Series; 
        import mx.charts.CategoryAxis; 
        import mx.charts.chartClasses.IAxis; 
        import mx.charts.chartClasses.ChartBase; 
        import mx.charts.chartClasses.CartesianTransform; 
        // This data provider contains complex, nested objects. 
        [Bindable] 
        public var SMITH:Array = [ 
            {month: "Aug", close: {High:45.87,Low:12.2}, open:25.19}, 
            {month: "Sep", close: {High:45.74,Low:10.23}, open:35.29}, 
            {month: "Oct", close: {High:45.77,Low:12.13}, open:45.19}, 
            {month: "Nov", close: {High:46.06,Low:10.45}, open:15.59}, 
        ]; 
        private function dataFunc(series:Series, item:Object, fieldName:String):Object { 
            trace("fieldName: " + fieldName); 
            if(fieldName == "yValue" && series.id=="highClose") 
                return(item.close.High); 
            else if(fieldName == "yValue" && series.id=="lowClose") 
                return(item.close.Low); 
            else if(fieldName == "xValue") 
                return(item.month); 
            else 
                return null; 
            } 
        private function catFunc(axis:AxisBase, item:Object):Object { 
            for (var s:String in item) { 
                trace(s + ":" + item[s]); 
            } 
            return(item.month); 
        } 
      </fx:Script>
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <s:Panel title="ColumnChart">
        <s:layout>
            <s:VerticalLayout />
        </s:layout>
        <mx:ColumnChart id="chart" dataProvider="{SMITH}"
            showDataTips="true" width="100%" height="100%">
            <mx:horizontalAxis>
                <!-- The dataFunction replaces "categoryField='month'. -->
                <mx:CategoryAxis id="h1" dataFunction="catFunc" />
            </mx:horizontalAxis>
            <mx:series>
                <!--
                    The dataFunction replaces yField value, which cannot drill down
                    into an object (close.High is not valid).
                -->
                <mx:ColumnSeries id="highClose" displayName="Close (High)"
                    dataFunction="dataFunc" />
                <!--
                    The dataFunction replaces yField value, which cannot drill down
                    into an object (close.Low is not valid).
                -->
                <mx:ColumnSeries id="lowClose" displayName="Close (Low)"
                    dataFunction="dataFunc" />
            </mx:series>
        </mx:ColumnChart>
    </s:Panel>
</s:Application>

   
    
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.horizontal Axis Renderer for ColumnCharthorizontal Axis Renderer for ColumnChart
2.Axis Renderer for ColumnChartAxis Renderer for ColumnChart
3.vertical Axis Renderer for ColumnChartvertical Axis Renderer for ColumnChart
4.Create a ColumnChart control with the default axis locations (bottom and left).Create a ColumnChart control with the default axis locations (bottom and left).
5.Column Chart Axis LabelColumn Chart Axis Label
6.Set Axis label for Column chartSet Axis label for Column chart
7.Customize horizontalAxisRenderer and AxisRendererCustomize horizontalAxisRenderer and AxisRenderer
8.Customize axisStrokeCustomize axisStroke
9.use the secondHorizontalAxisRenderer and secondVerticalAxisRenderer properties to control the appearance of the secondary axisuse the secondHorizontalAxisRenderer and secondVerticalAxisRenderer properties to control the appearance of the secondary axis
10.The following example removes tick marks from the horizontal axis:The following example removes tick marks from the horizontal axis:
11.Date Time Axis RangeDate Time Axis Range
12.Adding axis titlesAdding axis titles
13.Set LinearAxis, and formats the values to include a dollar sign and a thousands separator.Set LinearAxis, and formats the values to include a dollar sign and a thousands separator.
14.Remove tick marks from the horizontal axisRemove tick marks from the horizontal axis