2013-05-08 62 views
0

对不起,对于奇怪的主题名称,但我不知道如何命名它。 enter image description here有没有其他方法可以计算其他坐标系坐标系中的X值?

问题是..我有一个zedgraph控件。里面有一些线条。

我有图区左边界和图区右边界的坐标。

我通过zedgraph控件将垂直线绘制为PictureBox,因此它们在不同的坐标系中移动。这条垂直线可以左右移动。

这样,我想在X轴的COORDS获得X值:

public double Get_X_InContextOfChart(int left_coord_of_border) //Left of vertical line 
{ 
    //zed_graph.GraphPane.XAxis.Scale.Min is minimal X value shown on XAxis 
    //zed_graph.GraphPane.Chart.Rect.Left is Left of YAxis 
    //Same for else if, aside of using Right and maximum X at right 
    if (zed_graph.GraphPane.XAxis.Scale.Min != 0) //to avoid division by zero 
     return (left_coord_of_border * zed_graph.GraphPane.XAxis.Scale.Min)/zed_graph.GraphPane.Chart.Rect.Left; 
    else if (zed_graph.GraphPane.XAxis.Scale.Max != 0) 
     return (left_coord_of_border * zed_graph.GraphPane.XAxis.Scale.Max)/zed_graph.GraphPane.Chart.Rect.Right; 

    return double.NaN; 
} 

此代码计算X罚款,只要否则如果使用,但在我的例子也计算了什么。

我希望有人能够理解这一点。

更新与新代码:

public double Get_X_InContextOfChart(int left_coord_of_border) 
{ 
    double scale_left = zed_graph.GraphPane.XAxis.Scale.Min; 
    double scale_right = zed_graph.GraphPane.XAxis.Scale.Max; 
    double graph_width = zed_graph.GraphPane.Chart.Rect.Width; 
    double x = left_coord_of_border; 

    return scale_left + (scale_right - scale_left)/graph_width * x; 
} 

结果: enter image description here

回答

1
scale_left = -0.1 
scale_right = 0.9 
graph_width = 540 // pixels 
x = 190   // pixels 

scale_x = scale_left + (scale_right - scale_left)/graph_width * x // 0.25 
+0

谢谢您的回答,但是,它仍然计算问题的话...请,我的问题 – Kosmos 2013-05-08 17:10:07

+0

不动神色更新它通过这样做double x = left_coord_of_border - zed_graph.GraphPane.Chart.Rect.Left;这是我所有问题的根源......谢谢你的基本想法 – Kosmos 2013-05-08 17:26:21

+0

@Kosmos - 'double x = left_coord_of_border - 56;' – 2013-05-08 17:26:24