Flex 4, chart, Error 1009
Posted
by Stephane
on Stack Overflow
See other posts from Stack Overflow
or by Stephane
Published on 2010-03-29T15:13:50Z
Indexed on
2010/03/30
9:33 UTC
Read the original article
Hit count: 612
flex
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
<fx:Declarations>
</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 selectItem:Object;
[Bindable]
private var chartMouseY:int;
[Bindable]
private var hitData:Boolean=false;
[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 } ]);
public function chartMouseUp(e:MouseEvent):void{
if(hitData){
hitData = false;
}
}
private function chartMouseMove(e:MouseEvent):void {
if(hitData){
var p:Point = new Point(linechart.mouseX,linechart.mouseY);
var d:Array = linechart.localToData(p);
chartMouseY=d[1];
modifyData();
}
}
public function modifyData():void {
var idx:int = profitPeriods.getItemIndex(selectItem);
var item:Object = profitPeriods.getItemAt(idx);
item.profit = chartMouseY;
profitPeriods.setItemAt(item,idx);
}
public function chartMouseDown(e:MouseEvent):void{
if(!hitData){
var hda:Array = linechart.findDataPoints(e.currentTarget.mouseX,
e.currentTarget.mouseY);
if (hda[0]) {
selectItem = hda[0].item;
hitData = true;
}
}
}
]]>
</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"
mouseDown="chartMouseDown(event)"
mouseMove="chartMouseMove(event)"
mouseUp="chartMouseUp(event)"
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>
<mx:Form>
<mx:TextArea id="DEBUG" height="200" width="300"/>
</mx:Form>
</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
© Stack Overflow or respective owner