tags:

views:

308

answers:

0

Hello,

I am new to flex development and I am stuck with this error

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.charts.series::LineSeries/findDataPoints()[E:\dev\4.0.0\frameworks\projects\datavisualization\src\mx\charts\series\LineSeries.as:1460]
at mx.charts.chartClasses::ChartBase/findDataPoints()[E:\dev\4.0.0\frameworks\projects\datavisualization\src\mx\charts\chartClasses\ChartBase.as:2202]
at mx.charts.chartClasses::ChartBase/mouseMoveHandler()[E:\dev\4.0.0\frameworks\projects\datavisualization\src\mx\charts\chartClasses\ChartBase.as:4882]

I try to create a chart where I can move the points with the mouse I notice that the error doesn't occur if I move the point very slowly I have try to use the debugger and pint some debug every where without success All the behaviours were ok until I had the modifyData

Please let me know if you have some experience with this kind of error I will appreciate any help. Is it also possible to remove the error throwing because after that the error occur if I click the dismiss all error button then the component work great

there is the simple code of the chart

<?xml version="1.0" encoding="utf-8"?>

<fx:Declarations>
    <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>

<fx:Script>
    <![CDATA[

        import mx.charts.HitData;
        import mx.charts.events.ChartEvent;
        import mx.charts.events.ChartItemEvent;
        import mx.collections.ArrayCollection;

        [Bindable]
        private var idx:Number;

        [Bindable]
        private var chartMouseY:int;

        [Bindable]
        private var lockMove:Boolean;


        [Bindable]
        private var profitPeriods:ArrayCollection = new ArrayCollection( [
            { period: "Qtr1 2006", profit: 32 },
            { period: "Qtr2 2006", profit: 47 },
            { period: "Qtr3 2006", profit: 62 },
            { period: "Qtr4 2006", profit: 35 },
            { period: "Qtr1 2007", profit: 25 },
            { period: "Qtr2 2007", profit: 55 } ]);

        private function init():void{
            lockMove = false;
            linechart.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
            linechart.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
        }

        public function onMouseDown(e:MouseEvent):void{

            trace("down");
            var hda:Array = linechart.findDataPoints(e.currentTarget.mouseX, 
                e.currentTarget.mouseY);
            if (hda[0]) {

                idx = profitPeriods.getItemIndex(hda[0].item);  
                linechart.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
            }           

        }
        private function onMouseMove(e:MouseEvent):void {

            if(!lockMove){
                lockMove = true;

                var p:Point = new Point(linechart.mouseX,linechart.mouseY);
                var d:Array = linechart.localToData(p);


                modifyData(d[1]);

                lockMove = false;
            }
        }

        public function onMouseUp(e:MouseEvent):void{


            linechart.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);

        }

        public function modifyData(val:Number):void {

            trace("start");

            //var idx:int = profitPeriods.getItemIndex(selectItem); 
            var item:Object = profitPeriods.getItemAt(idx);

            item.profit = val;                          
            profitPeriods.setItemAt(item,idx);

            linechart.invalidateDisplayList();

            trace("stop");
        }
    ]]>
</fx:Script>

<s:layout>

    <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle" />  

</s:layout>


<s:Panel title="LineChart Control" >

    <s:VGroup >

        <s:HGroup>

        <mx:LineChart id="linechart" color="0x323232" height="500" width="377"
                      showDataTips="true" 
                      dataProvider="{profitPeriods}" >

            <mx:horizontalAxis>
                <mx:CategoryAxis categoryField="period"/>
            </mx:horizontalAxis>

            <mx:series>
                <mx:LineSeries yField="profit" form="segment" displayName="Profit"/>
            </mx:series>

        </mx:LineChart>


        <mx:Legend dataProvider="{linechart}" color="0x323232"/>

        </s:HGroup>


    </s:VGroup>
</s:Panel>

UPDATE 30/2010 : the null object is _renderData.filteredCache from the chartline the code call before error is the default mouseMoveHandler of chartBase to chartline. Is it possible to remove it ? or provide a filteredCache

I simplify the code to look like the flex example