Anyone with CartesianTransform knowledge? I'm having a good bit of difficulty getting a dynamically assigned custom CartesianTransform to work. I'm not finding a whole lot of sample code to learn from and am currently slogging through the framework code trying to determine what's up.
The problem is that once I assign the new Transform, the columns no longer display. It seems that the new Tranform doesn't seem to have the needed ColumnSeries data. Why this data isn't assigned when the Transform is created and attached to the series is a bit of a mystery. Is there another step needed, or is this a bug? Hopefully someone with more knowledge or experience can point me in the right direction. I just spent way too much time with a related dataTransform issue before I realized that it was indeed an unreported bug (https://bugs.adobe.com/jira/browse/FLEXDMV-2103), and I'd prefer to know more quickly if this too is a bug, or just inexperience. I've made a simple demo to demonstrate the problem. The code is below. Thanks in advance. Eddie B. Steps: 1) Compile and run the 2 files below (main app and custom transform) 2) Click the Change Data button to see that the data changes correctly. 3) Click the Set Transforms button to assign the new transform. 4) Click the Change Data button again to see the columns fail to display. /***** File 1 : The Main App *****/ <?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.charts.chartClasses.*; [Bindable] private var medalsAC:ArrayCollection = new ArrayCollection( [ { Country: "USA", Gold: 35, Silver:39, Bronze: 29 }, { Country: "China", Gold: 32, Silver:17, Bronze: 14 }, { Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]); [Bindable] private var medalsAC2:ArrayCollection = new ArrayCollection( [ { Country: "USA", Gold: 25, Silver:32, Bronze: 29 }, { Country: "China", Gold: 12, Silver:17, Bronze: 44 }, { Country: "Russia", Gold: 17, Silver:17, Bronze: 38 } ]); private function setTransforms():void { for (var i:int = 0; i < chart.series.length; i++) { var cs:ColumnSeries = chart.series[i] as ColumnSeries; var elements:Array = cs.dataTransform.elements; cs.dataTransform = new MyCartesianTransform(); //cs.dataTransform.elements = elements; //cs.dataTransform.setAxis(CartesianTransform.HORIZONTAL_AXIS, ca); //cs.invalidateProperties(); } } private function showTransforms():void { var classInfo:XML; textArea.text = "\nStacked chart's transforms:\n"; for (var i:int = 0; i < chart.series.length; i++) { var cs:ColumnSeries = chart.series[i] as ColumnSeries; classInfo = describeType(cs.dataTransform); textArea.text += classin...@name.tostring() + "\n"; } } private function changeData():void { if (chart.dataProvider == medalsAC) chart.dataProvider = medalsAC2; else chart.dataProvider = medalsAC; } ]]> </mx:Script> <mx:Panel title="Stacked Chart / CartesianTransform Bug" height="100%" width="100%" layout="vertical"> <mx:ColumnChart id="chart" height="100%" width="45%" dataProvider="{medalsAC}" > <mx:horizontalAxis> <mx:CategoryAxis id="ca" categoryField="Country"/> </mx:horizontalAxis> <mx:series> <mx:ColumnSeries xField="Country" yField="Gold" displayName="Gold" /> <mx:ColumnSeries xField="Country" yField="Silver" displayName="Silver" /> <mx:ColumnSeries xField="Country" yField="Bronze" displayName="Bronze" /> </mx:series> </mx:ColumnChart> <mx:Legend dataProvider="{chart}"/> <mx:Button label="Change Data" click="changeData()"/> <mx:Button label="Set Transforms" click="setTransforms()"/> <mx:Button label="Show Transform info" click="showTransforms()"/> <mx:TextArea id="textArea" height="174" width="100%"/> </mx:Panel> </mx:Application> /**** File 2 : The Custom Cartesian Transform ****/ package { import mx.charts.ColumnChart; import mx.charts.chartClasses.CartesianTransform; public class MyCartesianTransform extends CartesianTransform { public function MyCartesianTransform(){ super(); } override public function transformCache(cache:Array /* of Object */, xField:String, xConvertedField:String, yField:String, yConvertedField:String):void { var series:MyColumnSeries = this.elements[0] as MyColumnSeries; if (series != null) { var str:String = series.owner.name; trace("MyCartesianTransform: " + str); } else { trace("series == null. Where are the elements?"); } super.transformCache(cache, xField, xConvertedField, yField, yConvertedField); } }