Flex LineSeries - 沿曲线查找 y 值

发布于 2024-08-23 00:10:26 字数 1487 浏览 8 评论 0原文

我创建了一个 Flex LineChart,显示随时间变化的高潮和低潮预测。我使用带有 form="curve" 的 LineSeries,它会生成一个漂亮的正弦波图,代表一段时间内的水位。 X轴代表时间,Y轴代表水位。我必须处理的唯一数据点是高潮和低潮值,但我想弄清楚如何确定沿线任意 x 值的 y 值。

例如,假设我有以下数据点:

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 } 
]);

这是我的折线图:

<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>

我想知道 2010 年 2 月 26 日 09:00 的 waterLevel

如果我能做到的话那就太酷了

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

,但是可惜的是,getYValue(xValue) 函数不存在。

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 figure 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我还不会笑 2024-08-30 00:10:26

LineSeries 的 interpolate 属性将填充第一个值和最后一个值之间的间隙。然而,从你的问题来看,你似乎正在寻求通过提前估计来延长曲线。在这种情况下插值将不起作用。

我建议找到一个合适的水位数据估计回归模型,并将其应用于曲线上的更多点。根据我有限的经验,我可以推荐一种依赖于加权数据点的模型,称为样条模型。然而,我不是统计学家,估计模型的建议可能是错误的。

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.

一身仙ぐ女味 2024-08-30 00:10:26

好吧,我明白了。只得回到十一年级的数学课。

对于任何好奇的人,这是我想出的函数:

如果高潮(或低潮)是 date1w1 个单位,并且接下来的低潮(或高潮)是w2 单位位于 date2,则以下函数给出 date 处的水位 w

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;  
}

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;  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文