1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2009 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package mx.charts 13{ 14 15import mx.charts.chartClasses.CartesianChart; 16import mx.charts.chartClasses.DataTip; 17import mx.charts.chartClasses.DataTransform; 18import mx.charts.chartClasses.IAxis; 19import mx.charts.chartClasses.Series; 20import mx.charts.series.AreaSeries; 21import mx.charts.series.AreaSet; 22import mx.charts.styles.HaloDefaults; 23import mx.core.IFlexModuleFactory; 24import mx.core.mx_internal; 25import mx.graphics.IFill; 26import mx.graphics.SolidColor; 27import mx.graphics.SolidColorStroke; 28import mx.graphics.Stroke; 29import mx.styles.CSSStyleDeclaration; 30 31use namespace mx_internal; 32 33[DefaultBindingProperty(destination="dataProvider")] 34 35[DefaultTriggerEvent("itemClick")] 36 37[IconFile("AreaChart.png")] 38 39/** 40 * The AreaChart control represents data as an area 41 * bounded by a line connecting the values in the data. 42 * The AreaChart control can be used to represent different variations, 43 * including simple areas, stacked, 100% stacked, and high/low. 44 * 45 * <p>The AreaChart control expects its <code>series</code> property 46 * to contain an Array of AreaSeries objects.</p> 47 * 48 * <p>Stacked and 100% area charts override the <code>minField</code> 49 * property of their AreaSeries objects.</p> 50 * 51 * @mxml 52 * 53 * <p>The <code><mx:AreaChart></code> tag inherits all the properties 54 * of its parent classes, and adds the following properties:</p> 55 * 56 * <pre> 57 * <mx:AreaChart 58 * <strong>Properties</strong> 59 * type="<i>overlaid|stacked|100%</i>" 60 * /> 61 * </pre> 62 * 63 * @includeExample examples/Line_AreaChartExample.mxml 64 * 65 * @see mx.charts.series.AreaSeries 66 * 67 * @langversion 3.0 68 * @playerversion Flash 9 69 * @playerversion AIR 1.1 70 * @productversion Flex 3 71 */ 72public class AreaChart extends CartesianChart 73{ 74 include "../core/Version.as"; 75 76 //-------------------------------------------------------------------------- 77 // 78 // Class initialization 79 // 80 //-------------------------------------------------------------------------- 81 82 //-------------------------------------------------------------------------- 83 // 84 // Constructor 85 // 86 //-------------------------------------------------------------------------- 87 88 /** 89 * Constructor. 90 * 91 * @langversion 3.0 92 * @playerversion Flash 9 93 * @playerversion AIR 1.1 94 * @productversion Flex 3 95 */ 96 public function AreaChart() 97 { 98 super(); 99 100 LinearAxis(horizontalAxis).autoAdjust = false; 101 } 102 103 //-------------------------------------------------------------------------- 104 // 105 // Variables 106 // 107 //-------------------------------------------------------------------------- 108 109 /** 110 * @private 111 */ 112 private var _moduleFactoryInitialized:Boolean = false; 113 114 //-------------------------------------------------------------------------- 115 // 116 // Overridden properties 117 // 118 //-------------------------------------------------------------------------- 119 120 //---------------------------------- 121 // horizontalAxis 122 //---------------------------------- 123 124 [Inspectable(category="Data")] 125 126 /** 127 * @private 128 */ 129 override public function set horizontalAxis(value:IAxis):void 130 { 131 if (value is CategoryAxis) 132 CategoryAxis(value).padding = 0; 133 134 super.horizontalAxis = value; 135 } 136 137 //-------------------------------------------------------------------------- 138 // 139 // Properties 140 // 141 //-------------------------------------------------------------------------- 142 143 //---------------------------------- 144 // type 145 //---------------------------------- 146 147 /** 148 * @private 149 * Storage for the type property. 150 */ 151 private var _type:String = "overlaid"; 152 153 [Inspectable(category="General", enumeration="overlaid,stacked,100%", defaultValue="overlaid")] 154 155 /** 156 * Type of area chart to render. 157 * 158 * <p>Possible values are:</p> 159 * <ul> 160 * <li><code>"overlaid"</code>: 161 * Multiple areas are rendered on top of each other, 162 * with the last series specified on top. 163 * This is the default value.</li> 164 * <li><code>"stacked"</code>: 165 * Areas are stacked on top of each other and grouped by category. 166 * Each area represents the cumulative value 167 * of the areas beneath it.</li> 168 * <li><code>"100%"</code>: 169 * Areas are stacked on top of each other, adding up to 100%. 170 * Each area represents the percent that series contributes 171 * to the sum of the whole.</li> 172 * </ul> 173 * 174 * @langversion 3.0 175 * @playerversion Flash 9 176 * @playerversion AIR 1.1 177 * @productversion Flex 3 178 */ 179 public function get type():String 180 { 181 return _type; 182 } 183 184 /** 185 * @private 186 */ 187 public function set type(value:String):void 188 { 189 _type = value; 190 invalidateSeries(); 191 invalidateData(); 192 } 193 194 //-------------------------------------------------------------------------- 195 // 196 // Overridden methods: UIComponent 197 // 198 //-------------------------------------------------------------------------- 199 200 /** 201 * @private 202 */ 203 private function initStyles():Boolean 204 { 205 HaloDefaults.init(styleManager); 206 207 var areaChartSeriesStyles:Array /* of Object */ = []; 208 209 var n:int = HaloDefaults.defaultFills.length; 210 for (var i:int = 0; i < n; i++) 211 { 212 var styleName:String = "haloAreaSeries" + i; 213 areaChartSeriesStyles[i] = styleName; 214 215 var o:CSSStyleDeclaration = 216 HaloDefaults.createSelector("." + styleName, styleManager); 217 218 var f:Function = function(o:CSSStyleDeclaration, stroke:Stroke, 219 fill:IFill):void 220 { 221 o.defaultFactory = function():void 222 { 223 this.areaFill = fill; 224 this.fill = fill; 225 } 226 } 227 228 f(o, null, HaloDefaults.defaultFills[i]); 229 } 230 231 var areaChartStyle:CSSStyleDeclaration = styleManager.getStyleDeclaration("mx.charts.AreaChart"); 232 areaChartStyle.setStyle("chartSeriesStyles", areaChartSeriesStyles); 233 areaChartStyle.setStyle("fill", new SolidColor(0xFFFFFF, 0)); 234 areaChartStyle.setStyle("calloutStroke", new SolidColorStroke(0x888888,2)); 235 areaChartStyle.setStyle("horizontalAxisStyleNames", ["hangingCategoryAxis"]); 236 areaChartStyle.setStyle("verticalAxisStyleNames", ["blockNumericAxis"]); 237 238 return true; 239 } 240 241 /** 242 * A module factory is used as context for using embedded fonts and for finding the style manager that controls the styles for this component. 243 * 244 * @langversion 3.0 245 * @playerversion Flash 9 246 * @playerversion AIR 1.1 247 * @productversion Flex 3 248 */ 249 override public function set moduleFactory(factory:IFlexModuleFactory):void 250 { 251 super.moduleFactory = factory; 252 253 if (_moduleFactoryInitialized) 254 return; 255 256 _moduleFactoryInitialized = true; 257 258 // our style settings 259 initStyles(); 260 } 261 262 //-------------------------------------------------------------------------- 263 // 264 // Overridden methods: ChartBase 265 // 266 //-------------------------------------------------------------------------- 267 268 /** 269 * @private 270 */ 271 override protected function customizeSeries(seriesGlyph:Series, 272 i:uint):void 273 { 274 var aSeries:AreaSeries = seriesGlyph as AreaSeries; 275 276 if (aSeries) 277 { 278 aSeries.stacker = null; 279 aSeries.stackTotals = null; 280 } 281 } 282 283 /** 284 * @private 285 */ 286 override protected function applySeriesSet(seriesSet:Array /* of Series */, 287 transform:DataTransform):Array /* of Series */ 288 { 289 switch (_type) 290 { 291 case "stacked": 292 case "100%": 293 { 294 var newSeriesGlyph:AreaSet = new AreaSet(); 295 newSeriesGlyph.series = seriesSet; 296 newSeriesGlyph.type = _type; 297 return [ newSeriesGlyph ]; 298 } 299 300 case "overlaid": 301 default: 302 { 303 return super.applySeriesSet(seriesSet, transform); 304 } 305 } 306 } 307} 308 309} 310