开发者

Flex LineSeries - find y-value along curve

I've created a Flex LineChart that shows high and low tide predictions over time. I'm using the LineSeries with form="curve", which produces a nice sinusoidal wave graph, representing water level over time. The X-axis represents time, and the Y-axis represents water level. The only data points I have to work with are high and low tide values, but I would like to figur开发者_高级运维e out how to determine the y-values of arbitrary x-values along the line.

For example, let's say I have the following data points:

var highLowTidePredictions:ArrayCollection = new ArrayCollection( [
     { Date: new Date(2010, 1, 26,  7, 15), waterLevel: 20.3 },
     { Date: new Date(2010, 1, 26, 13, 15), waterLevel: -1.2 },
     { Date: new Date(2010, 1, 26, 19, 15), waterLevel: 19.0 },
     { Date: new Date(2010, 1, 27,  1, 15), waterLevel: -1.0 },
     { Date: new Date(2010, 1, 27,  7, 15), waterLevel: 18.7 },
     { Date: new Date(2010, 1, 27, 13, 15), waterLevel:  0.7 } 
]);

Here's my Line Chart:

<mx:LineChart id="highLowLinePredictionsLineChart"
    width="100%" height="100%"
    dataProvider="{highLowTidePredictions}" 
    showDataTips="true">

    <mx:horizontalAxis>
            <mx:DateTimeAxis id="dta" />
    </mx:horizontalAxis>
    <mx:series>
            <mx:LineSeries id="lineSeries1" 
                   xField="Date" yField="waterLevel" 
                   form="curve" interpolateValues="true" sortOnXField="true"/>
    </mx:series>
</mx:LineChart>

And I want to know the waterLevel on Feb 26, 2010 at 09:00.

It would be cool if I could do

var date:Date = new Date(2010, 1, 26, 9, 0);
var waterLevel:Number = lineSeries1.getYValue(date);

But alas, that getYValue(xValue) function doesn't exist.


The interpolate property of the LineSeries will fill in the gaps between the first and last values. However it seems by your question that you are seeking to extend the curve by estimating ahead. Interpolate will not work in this case.

I'd suggest finding a suitable regression model of estimation of Water Level data and apply it to derive more points on the curve. From my limited experience, I could recommend a model dependent on weighted data points called the Spline model. However I am not a statistician and might be wrong about the estimate model recommendation.


Ok, I figured it out. Just had to go back to 11th grade math class.

For anyone who's curious, here's the function I came up with:

If the high(or low) tide is w1 units at date1 and the following low(or high) tide is w2 units at date2, then the following function gives the water level w at date.

private function getWaterLevel(date:Date, date1:Date, date2:Date, w1:Number, w2:Number):Number
{
    var t:Number = date.getTime();
    var t1:Number = date1.getTime();
    var t2:Number = date2.getTime();

    var A:Number = (w2 - w1) / 2;
    var B:Number = 2 * (t2 - t1);
    var C:Number = t1 + ((t2 - t1) / 2);
    var D:Number = w1 + ((w2 - w1) / 2);
    return A * Math.sin( ((2 * Math.PI)/B) * (t - C)) + D;  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜