[flexcoders] How can I Force a Chart to Redraw Itself?
I have a column chart that uses a label function to format the vertical axis. I added a button and want the axis (or chart) to redraw when the button is clicked. Right now, the chart axis renders OK only when initially added to the view state. I use a function that sets various properties after the chart is initially created. In there, I have tried all these: myChart.verticalAxis.dataChanged(); myChart.validateNow(); myChart.validateDisplayList(); myChart.validateProperties(); myChart.invalidateDisplayList(); myChart.invalidateProperties(); But they do not change the axis formatting. The MXML code for the axis is: mx:LinearAxis id=verticalAxis labelFunction=vAxisFormat/ The label function is: private function vAxisFormat(labelValue:Number, previousValue:Object, axis:IAxis):String { axis.getLabelEstimate(); if (_scale == 1){ return currencyFormatter.format(labelValue/_scale); }else { return numberFormatter.format(labelValue/_scale); } } I found out that the Adobe help has the following method for the Formatter class: resourcesChanged(): This method is called when a Formatter is constructed, and again whenever the ResourceManager dispatches a change Event to indicate that the localized resources have changed in some way. This event will be dispatched when you set the ResourceManager's localeChain property, when a resource module has finished loading, and when you call the ResourceManager's update() method. Subclasses should override this method and, after calling super.resourcesChanged(), do whatever is appropriate in response to having new resource values. So I inserted this with great expectations: resourceManager.update(); That didn't work so I tried: resourceManager.dispatchEvent(new Event(Change)); What am I missing? How do I call the axis format label function or get the chart to redraw?
[flexcoders] When Do I Render a Legend in a Chart?
My Flex chart has code that creates a legend from each data series. Currently, I have the drawLegend function execute when a button is clicked. I am trying to get the legend to draw automatically but I am having trouble determining when to call the drawLegend function. Users click on an 'Update' button which retrieves data. I want the legend to get created after this, without the users having to click on another button. I have put my drawLegend function in several places (ResultHandler, afterEffectEnd(for chart animation, etc.) and nothing works. Sometime after the series has been added to the chart and after the series animation ends, the legend can be added. How can I trap this point in time and call my function? Any ideas? Below is the code I used to create the legend. Note that even though the code processes each series, I noticed that the Fill color is null if it is called too early. private function drawLegend(event:Event):void { clearLegend(); // Use a counter for the series. var z:int = 0; var numRows:int; if (chart.series.length % rowSize == 0) { // The number of series is exactly divisible by the rowSize. numRows = Math.floor(chart.series.length / rowSize); } else { // One extra row is needed if there is a remainder. numRows = Math.floor(chart.series.length / rowSize) + 1; } for (var j:int = 0; j numRows; j++) { var gr:GridRow = new GridRow(); myGrid.addChild(gr); for (var k:int = 0; k rowSize; k++) { // As long as the series counter is less than the number of series... //skip columnset group if (chart.series[z] is LineSeries || chart.series[z] is ColumnSeries){ if (z chart.series.length) { var gi:GridItem = new GridItem(); gr.addChild(gi); var li:LegendItem = new LegendItem(); // Apply the current series' displayName to the LegendItem's label. li.label = chart.series[z].displayName; // Get the current series' fill. var sc:SolidColor = new SolidColor(); sc.color = chart.series[z].items[0].fill.color; // Apply the current series' fill to the corresponding LegendItem. li.setStyle(fill, sc.color);//was just sc // Apply other styles to make the LegendItems look uniform. li.setStyle(textIndent, 5); li.setStyle(labelPlacement, left); li.setStyle(fontSize, 9); gi.setStyle(backgroundAlpha, 1); gi.setStyle(backgroundColor, sc.color); //gi.width = 80; // Add the LegendItem to the GridItem. gi.addChild(li); } } // Increment any time a LegendItem is added. z++; } }
[flexcoders] Passing associative array to custom component
I built a custom button component and it has a property that accepts an array of values. In the main.mxml file, how can I pass an array when defining the property? main.mxml has this button code: comp:updateButton id=update cubeName={_cubeName} viewName={_viewName} serverChartId={_serverChartId} titleDims=xxx enabled=false/ for title dims, I tried: titleDims=[{Month: comboBox1.text, Year:comboBox2.text, Sales Order:comboBox3.text}] but I get a 1084: Syntax error: expecting rightparen before colon The keys will have spaces in them like 'Sales Order' How can I declare the array in mxml?