当图表y值超过线的y值

时间:2018-01-05 22:26:22

标签: c# .net charts

我有一个烛台图表,可以自动更新.NET表格中的加密货币交易所的实时价格。目标是当图表上的价格通过用户绘制的一条线时,使机器人预成型动作。到目前为止,由于this article,我已经开始为用户启用线条绘制。

有谁能请我指出一种检测图表蜡烛和绘制线条之间碰撞的方法?我觉得必须有比我现在想的更简单的方法,但似乎无法找到解决方法。

使用文章中的线条图的精确解决方案,也为下面的线条图发布了代码:

int index1 = 1;
int index2 = 4;

DataPoint left = chart.Series[0].Points[index1];
DataPoint right = chart.Series[0].Points[index2];

    //Init the annotation
    LineAnnotation line = new LineAnnotation();
    line.AxisX = chart.ChartAreas[0].AxisX;
    line.AxisY = chart.ChartAreas[0].AxisY;
    line.IsSizeAlwaysRelative = false;

    //Each point in a candlestick series has several y values, 0=high, 1=low, 2=open, 3=close
    line.Y = left.YValues[1]; //low
    line.X = left.XValue;
    //If your data is indexed (your x values are Strings or you've set Series.IsXValueIndexed to true), use the data point index(+1) as the line X coordinate.
    //line.X = index1 + 1;

    //Use the width and height properties to determine the end position of the annotation.
    line.Height = right.YValues[1] - left.YValues[1];
    line.Width = right.XValue - left.XValue;
    //Again, use the index if necessary
    //line.Width = index2 - index1;

    chart.Annotations.Add(line);

只是寻找更容易解决问题的方向,而不是解决方案本身:)提前感谢!

1 个答案:

答案 0 :(得分:1)

所以听起来你问的是Point (Geometry)是否高于或低于一条线。

以下是假设(您可以稍后更改以满足您的需求):

  1. 外部资源在特定时间点(X)为您提供特定值(Y),这将调用积分点XY
  2. 用户绘制了一条线,它给出了一个起点(x1,y1)和一个终点(x2,y2)。
  3. 图表X组件以分钟为单位,每个水平刻度为1分钟。
  4. 图表Y分量以美元为单位,每个勾号为25美元。
  5. 用户从(下午1点,50美元)到(下午1点05分,75美元)画了一条线。
  6. 我们在下午1点10分得到 Integral Point XY ,价格为125美元。
  7. 下午1:10线的值是多少,因此您可以将它与积分点XY 进行比较。

    根据我对Trigonometry的评论

    enter image description here

    • 我们知道相邻的长度是:1:05 - 1:00 = 5
    • 我们知道相反的长度是:75 - 25 = 50
    • 使用公式:atan(对角/相邻)=角度
      • 我们计算出角度为:atan(50/5)= 1.47112767rad(弧度)

    现在我们简单地改变我们的数学:

    • 我们知道相邻的长度是:1:10 - 1:00 = 10
    • 我们知道我们在Radians中的角度:1.47112767
    • 使用公式:相邻* tan(角度)=相反
      • 我们计算相反的是:10 * tan(1.47112767)=〜$ 99.999999或$ 100

    125美元高于100美元,做你想做的事。

相关问题