I need to create an instance of a PlotSeries icon.  It's easy enough to 
discover the PlotSeries item renderer:

var renderer:ClassFactory = plotSeries.getStyle("itemRenderer");

However, if I have not figured out how to create an instance of the renderer so 
I can add it to the display list.

Here is a short test program, consisting of two files.  The first file is a 
VBox whose icon property should be set to the item renderer instance.

// TestBox.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml";>
    <mx:Script>
        <![CDATA[
            import mx.controls.*;
            import mx.charts.series.PlotSeries;
                        
            public var plotSeries:PlotSeries;
            public var generator:Class;

            override protected function createChildren():void {
                super.createChildren();
                if (false) { // this works (icon is shown)
                    icon = generator;
                } else { // does not work (no icon)
                    var renderer:ClassFactory = 
plotSeries.getStyle("itemRenderer");
                    icon = renderer.generator;
                    /* var x:* = renderer.newInstance();
                    trace(x); */
                }
            }
        ]]>
    </mx:Script>
</mx:VBox>


// index.mxml
/* This is the application; it contains two embedded images that can be used to 
set the TestBox's icon property.  That works.

onPlotChartComplete() sets the icon. */
<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:local="*"
    xmlns:mx="http://www.adobe.com/2006/mxml";>
    
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.charts.series.PlotSeries;
    
            [Bindable]
            private var expensesAC:ArrayCollection = new ArrayCollection( [
                { Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450 },
                { Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 },
                { Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300 } 
            ]);

            [Embed(source="warning.png")]
            private static var WarningClass:Class;

            [Embed(source="error.png")]
            private static var ErrorClass:Class;


            private function onPlotChartComplete():void {
                var testBox1:TestBox = new TestBox();
                testBox1.plotSeries = plotSeries1;
                testBox1.generator = ErrorClass;
                testBox1.label = "Error";
                tab.addChild(testBox1);
                
                var testBox2:TestBox = new TestBox();
                testBox2.plotSeries = plotSeries2;
                testBox2.generator = WarningClass;
                testBox2.label = "Warning";
                tab.addChild(testBox2);
            }
        ]]>
    </mx:Script>

    <mx:PlotChart
        creationComplete="onPlotChartComplete()"
        dataProvider="{expensesAC}"
        height="50%" 
        width="100%">
        <mx:series>
            <mx:PlotSeries
                id="plotSeries1"
                xField="Expenses"
                yField="Profit"
                displayName="Plot 1" />
            <mx:PlotSeries
                id="plotSeries2"
                xField="Amount"
                yField="Expenses"
                displayName="Plot 2" />
        </mx:series>
    </mx:PlotChart>
    <mx:TabNavigator height="50%" id="tab" width="100%" />
</mx:Application>


Suggestions?

Mike


Reply via email to