Morning all of you.
    I need you help about adding the Legend Tag in your solution of showing 
points on lineChart mentioned in this 
link:http://www.mail-archive.com/[email protected]/msg36175.html

    In fact, i do the same thing like you (all work good). but the only 
different thing that i would want it's to display the Legend of each line 
series.
so when i add  the tag <mx:Legend dataProvider="{myChart}"/> which myChart 
represent the id of the lineChart,     
    i have this error: TypeError:Error #1034: Type Coercion failed: cannot 
convert mx.charts.chartClasses::legendd...@cc33701 to mx.charts.ChartItem.

    i tried to add the import like 
import mx.charts.Legend;
import mx.charts.LegendItem;
import mx.charts.chartClasses.LegendData;

thank you in advance( i attached the image of the error)

that is the code:
---------LabelRenderer2.as------------
package
{

import flash.display.Graphics;
import flash.geom.Rectangle;
import mx.charts.ChartItem;
import mx.charts.chartClasses.GraphicsUtilities;
import mx.core.IDataRenderer;
import mx.graphics.IFill;
import mx.graphics.IStroke;
import mx.skins.ProgrammaticSkin;
import mx.controls.Label;
import mx.core.UIComponent;
import mx.charts.LineChart;
import mx.charts.series.items.LineSeriesItem;
import mx.charts.Legend;
import mx.charts.LegendItem;
import mx.charts.chartClasses.LegendData;

public class LabeledRenderer2 extends UIComponent implements IDataRenderer
{
    private var _label:Label;
    
    public function
 LabeledRenderer2():void
    {
        super();
        _label = new Label();
        addChild(_label);
        _label.setStyle("color",0x000000);        
    }
    private var _chartItem:ChartItem;

    public function get data():Object
    {
        return _chartItem;
    }

    public function set data(value:Object):void
    {
        if (_chartItem == value)
            return;
        _chartItem = ChartItem(value);

        if(_chartItem != null)
            _label.text = LineSeriesItem(_chartItem).yValue.toString();
    }

    private static const fills:Array = [0xFF0000,0x00FF00,0x0000FF,
                                        0x00FFFF,0xFF00FF,0xFFFF00,
                                        0xAAFFAA,0xFFAAAA,0xAAAAFF];     
    override protected function updateDisplayList(unscaledWidth:Number,
                                                 
 unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
              
        
_label.setActualSize(_label.getExplicitOrMeasuredWidth(),_label.getExplicitOrMeasuredHeight());
        _label.move(unscaledWidth - _label.getExplicitOrMeasuredWidth(),
                    unscaledHeight/2 - _label.getExplicitOrMeasuredHeight()/2);
    }

}

}


------------LineChart.mxml-------------
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";; styleName="plain">
        <mx:Script>
        import mx.graphics.Stroke;

        [Bindable]
        public var expenses:Object = [{Month: "Jan", Profit: 2000, Expenses: 
1500, Amount: 450},
                  {Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600},
                  {Month: "Mar",
 Profit: 1500, Expenses: 500, Amount: 300}];

        public var s:Stroke = new Stroke(0x001100); 

        </mx:Script>
<mx:Panel title="Line Chart" borderStyle="solid" textAlign="center">
        <mx:Label text=" "/>
        <mx:LineChart id="myChart" dataProvider="{expenses}" >
                <mx:horizontalAxis>
                        <mx:CategoryAxis dataProvider="{expenses}" 
categoryField="Month" />
                </mx:horizontalAxis>
                <mx:series>
                <mx:LineSeries yField="Profit" itemRenderer="LabeledRenderer2"/>
                <mx:LineSeries yField="Expenses"/>
                <mx:LineSeries yField="Amount"/>
                </mx:series>
        </mx:LineChart>
<mx:Legend
 dataProvider="{myChart}"/>
</mx:Panel>
</mx:Application>



      

Reply via email to