localToData with DateTimeAxis
April 15, 2008
I was responding to one of the queries by Matt Horn, who is part of the Flex Documentation team on how to get the exact DataPoint for a series based on the mouse position which has one of its axis as a DateTimeAxis, thought let me share it here.
The usual code is
var d:Array = series1.localToData(p); // p is the point for which you want the data
if you notice d[0] will be x-coord and d[1] will be y-coord and if DateTimeAxis is representing the x-Axis then d[0] will be some huge number, basically it is the number of milliseconds from midnight of Jan 1 1970, so just create a Date object with that to get the actual data point.
To get the same data point which actually gets displayed on the Chart, just use the following code.
var d:Array = series1.localToData(p);
var da:Date = new Date(d[0]);
var str:String = daxis.formatForScreen(da); // daxis is the DataTimeAxis of the Chart.
formatForScreen is a public method which translates the date object to the one which is currently being displayed on the Chart based on the dataUnits that has been specified. Its a simple method, but nevertheless handy.

July 9, 2008 at 7:11 pm
I am trying to understand this, but I don’t get how I can get the p point.
I am trying to do a linechart where the user can drag the datapoints and maybe this is useful.
July 2, 2010 at 8:46 am
Hi Gilbert,
This is two years too late, but anyhow:
// Put the following inside a mouseMove listener
var p:Point = new Point(chartID.mouseX,chartID.mouseY);
Brian