Use chart items in more than one series : Column Chart ColumnSeries « Chart « Flex






Use chart items in more than one series

Use chart items in more than one 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/ComplexFillFunction.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        
        import mx.graphics.IFill;
        import mx.graphics.SolidColor;
        import mx.collections.ArrayCollection;
        import mx.charts.ChartItem;
        import mx.charts.series.items.ColumnSeriesItem;
        [Bindable]
        public var sales:ArrayCollection = new ArrayCollection([
            { Name:"Reiner", SalesGoal:65000, CurrentAmount:69000 },
            { Name:"Klaus", SalesGoal:40000, CurrentAmount:38000 },
            { Name:"Alan", SalesGoal:40000, CurrentAmount:44000 },
            { Name:"Wolfgang", SalesGoal:48000, CurrentAmount:33000 },
            { Name:"Francis", SalesGoal:22000, CurrentAmount:20000 },
            { Name:"Klaus-Jurgen", SalesGoal:50000, CurrentAmount:55000 },
            { Name:"Martin", SalesGoal:44000, CurrentAmount:70000 },
            { Name:"Mac", SalesGoal:40000, CurrentAmount:35000 },
            { Name:"Friedemann", SalesGoal:38000, CurrentAmount:38000 },
            { Name:"Bruno", SalesGoal:42000, CurrentAmount:40000 }
            ]);
        private function myFillFunction(element:ChartItem, index:Number):IFill
        {
            var item:ColumnSeriesItem = ColumnSeriesItem(element);
            trace("--------------------------------------------------");
            trace("Item index: " + index);
            trace("Sales Person: " + item.xValue);
            trace("Current Amount: " + currSalesSeries.items[index].yValue);
            trace("Sales Goal: " + item.yValue);
            // Set default color and alpha.
            var c:SolidColor = new SolidColor(0x00CC00);
            // Use the yNumber properties rather than the yValue properties
            // because the conversion to a Number is already done for
            // you. As a result, you do not have to cast them to a Number,
            // which would be less efficient.
            var goal:Number = item.yNumber;
            var currentAmount:Number = currSalesSeries.items[index].yNumber;
            // Determine if the goal was met or not.
            var diff:Number = currentAmount - goal;
            if (diff >= 0) {
              // Sales person met their goal.
              return c;
            } else if (diff < 0) {
             // Sales person did not meet their goal.
             c.color = 0xFF0000;
             c.alpha = .2;
            }
            return c;
        }
      
    </mx:Script>
    <mx:Panel title="Using a custom fillFunction in a Column Chart">
        <mx:ColumnChart id="myChart" dataProvider="{sales}" type="overlaid"
            showDataTips="true">
            <mx:horizontalAxis>
                <mx:CategoryAxis title="Sales Person" categoryField="Name" />
            </mx:horizontalAxis>
            <mx:verticalAxis>
                <mx:LinearAxis title="Sales (in $USD)" />
            </mx:verticalAxis>
            <mx:series>
                <mx:ColumnSeries id="currSalesSeries" xField="Name"
                    yField="CurrentAmount" displayName="Current Sales">
                    <mx:fill>
                        <mx:SolidColor color="0x00FF00" />
                    </mx:fill>
                </mx:ColumnSeries>
                <mx:ColumnSeries id="salesGoalSeries" xField="Name"
                    yField="SalesGoal" fillFunction="myFillFunction"
                    displayName="Sales Goal">
                </mx:ColumnSeries>
            </mx:series>
        </mx:ColumnChart>
        <mx:Legend>
            <mx:LegendItem label="Goal" fontWeight="bold">
                <mx:fill>
                    <mx:SolidColor color="0x00CC00" />
                </mx:fill>
                <mx:stroke>
                    <mx:Stroke color="0x000000" weight="1" />
                </mx:stroke>
            </mx:LegendItem>
            <mx:LegendItem label="Exceeded Goal" fontWeight="bold">
                <mx:fill>
                    <mx:SolidColor color="0x00FF00" />
                </mx:fill>
                <mx:stroke>
                    <mx:Stroke color="0x000000" weight="1" />
                </mx:stroke>
            </mx:LegendItem>
            <mx:LegendItem label="Missed Goal" fontWeight="bold">
                <mx:fill>
                    <mx:SolidColor color="0xFF0000" alpha=".2" />
                </mx:fill>
                <mx:stroke>
                    <mx:Stroke color="0x000000" weight="1" />
                </mx:stroke>
            </mx:LegendItem>
        </mx:Legend>
    </mx:Panel>
</mx:Application>

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.ColumnChart with ColumnSeriesColumnChart with ColumnSeries
2.Use the fill property to set the color for each ColumnSeries object in a ColumnChart controlUse the fill property to set the color for each ColumnSeries object in a ColumnChart control
3.Define a custom SolidColor object and a custom SolidColorStroke object, and applies them to the ColumnSeries object in the ColumnChart control.Define a custom SolidColor object and a custom SolidColorStroke object, and applies them to the ColumnSeries object in the ColumnChart control.
4.The following example mixes a LineSeries and a ColumnSeriesThe following example mixes a LineSeries and a ColumnSeries
5.The following example defines the colors for two series in the ColumnChart control:The following example defines the colors for two series in the ColumnChart control:
6.Adding Series to ColumnChartAdding Series to ColumnChart
7.defines the colors for two series in the ColumnChart controldefines the colors for two series in the ColumnChart control
8.Create a ColumnChart control with two seriesCreate a ColumnChart control with two series
9.Data Update In Real Time SeriesData Update In Real Time Series
10.uses two series to allow a visual comparison of two stocks that trade in different rangesuses two series to allow a visual comparison of two stocks that trade in different ranges
11.Cast the HitData object to a Series classCast the HitData object to a Series class
12.Set elementOffset property of SeriesInterpolate to 0.Set elementOffset property of SeriesInterpolate to 0.
13.Increments and decrements the series's selectedIndex property to select each itemIncrements and decrements the series's selectedIndex property to select each item
14.Add or remove a data point from a series in ActionScript.Add or remove a data point from a series in ActionScript.
15.Use a similar technique to add data series to your charts rather than replacing the existing onesUse a similar technique to add data series to your charts rather than replacing the existing ones
16.yValue of the ColumnSeriesItem represents the percentage a series takes up in a 100% chartyValue of the ColumnSeriesItem represents the percentage a series takes up in a 100% chart
17.Zoom in data series from the upper-right corner of the chart.Zoom in data series from the upper-right corner of the chart.
18.Change fields of a series to change chart data at run timeChange fields of a series to change chart data at run time
19.The final result is a chart with multiple axes, but whose series share some of the same properties defined by common axis renderers.The final result is a chart with multiple axes, but whose series share some of the same properties defined by common axis renderers.