Set fill color : Column Chart Style « Chart « Flex






Set fill color

Set fill color
               
<!--
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/ComparativeFillFunction.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", CurrentAmount:69000 },
            { Name:"Klaus", CurrentAmount:38000 },
            { Name:"Alan", CurrentAmount:44000 },
            { Name:"Wolfgang", CurrentAmount:33000 },
            { Name:"Francis", CurrentAmount:20000 },
            { Name:"Klaus-Jurgen", CurrentAmount:55000 },
            { Name:"Martin", CurrentAmount:70000 },
            { Name:"Mac", CurrentAmount:35000 },
            { Name:"Friedemann", CurrentAmount:38000 },
            { Name:"Bruno", CurrentAmount:40000 }
            ]);
        private function myFillFunction(element:ChartItem, index:Number):IFill
        {
            // Default to green.
            var c:SolidColor = new SolidColor(0x00FF00);
            var item:ColumnSeriesItem = ColumnSeriesItem(element);
            var sales:Number = Number(item.yValue);
            if (index == 0) {
                 // The first column should be green, no matter the value.
                 return c;
            } else {
                var prevVal:Number = Number(currSalesSeries.items[index - 1].yValue);
                var curVal:Number = Number(currSalesSeries.items[index].yValue);
                var diff:Number = curVal - prevVal;
                if (diff >= 0) {
                    // Current column's value is greater than the previous.
                    return c;
                } else {
                    // Previous column's value is greater than the current.
                    c.color = 0xFF0000;
                }
            }
            return c;
        }
      
    </mx:Script>
    <mx:Panel title="Using a custom fillFunction in a Column Chart">
        <mx:ColumnChart id="myChart" dataProvider="{sales}"
            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" fillFunction="myFillFunction"
                    displayName="Current Sales" />
            </mx:series>
        </mx:ColumnChart>
        <mx:Legend>
            <mx:LegendItem label="More than Previous" 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="Less than Previous" fontWeight="bold">
                <mx:fill>
                    <mx:SolidColor color="0xFF0000" />
                </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 Color GradientColumnChart with Color Gradient
2.Use SolidColorStoke to paint horizontalStrokeUse SolidColorStoke to paint horizontalStroke
3.Use SolidColorStoke to paint verticalStrokeUse SolidColorStoke to paint verticalStroke
4.background Elements for ColumnChartbackground Elements for ColumnChart
5.Remove Shadows for ColumnChartRemove Shadows for ColumnChart
6.Fill column with LinearGradientFill column with LinearGradient
7.Use GridLines as backgroundUse GridLines as background
8.LinearGradient fillLinearGradient fill
9.Formatting grid lines with ActionScriptFormatting grid lines with ActionScript
10.Formatting grid lines with MXMLFormatting grid lines with MXML
11.Chart With StyleChart With Style
12.Apply a custom drop shadow filter to a ColumnChart controlApply a custom drop shadow filter to a ColumnChart control
13.Creates a floating ColumnChart controlCreates a floating ColumnChart control
14.Alternatively, you can set the gutter properties inlineAlternatively, you can set the gutter properties inline
15.Define a custom component inline by using the tag.Define a custom component inline by using the <fx:Component> tag.
16.specify the x, y, height, and width properties of a rectangular range.specify the x, y, height, and width properties of a rectangular range.
17.Add background to chartAdd background to chart
18.Add new grid lines as annotation elements to the chart and an image as the background element.Add new grid lines as annotation elements to the chart and an image as the background element.
19.Add an image to the chart and manipulate its propertiessAdd an image to the chart and manipulate its propertiess
20.Style tickStrokeStyle tickStroke
21.Style minorTickStrokeStyle minorTickStroke
22.Disabling axis labelsDisabling axis labels
23.Change the label alignment for the vertical and horizontal axes.Change the label alignment for the vertical and horizontal axes.