0

在此处输入图像描述

如何在 teechart 中读取误差系列的 y 坐标?当光标在其上移动时,我想要 y 轴的上下坐标。

4

2 回答 2

2

您需要使用 TeeChart 鼠标事件(例如:OnMouseMove)和系列的 Clicked 方法来了解鼠标下方的点并检索相应的值,如下例所示:

  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(new Steema.TeeChart.Styles.Error()).FillSampleValues();
      tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
    }

    void tChart1_MouseMove(object sender, MouseEventArgs e)
    {
      Steema.TeeChart.Styles.Error error1 = (Steema.TeeChart.Styles.Error)tChart1[0];

      int index = error1.Clicked(e.X, e.Y);
      string tmp = "";

      if (index != -1)
      {
        double y = error1.YValues[index];
        double error = error1.ErrorValues[index];
        double top = y + error;
        double bottom = y - error;
        tmp = top.ToString("#.##") + " - " + bottom.ToString("#.##");
      }
      else
      {
        tmp = "";
      }

      this.Text = tmp;
    }
  }

如果您使用 CursorTool,则有 e.XValue 和 e.YValue 参数,它们为您提供 CursorTool 和 ex 和 ey 的轴值,它们等效于 MouseMove eX 和 eY 参数,因此您可以对该事件执行相同操作,a简单的例子:

public Form1()
{
  InitializeComponent();
  InitializeChart();
}

private void InitializeChart()
{
  tChart1.Aspect.View3D = false;
  tChart1.Series.Add(new Steema.TeeChart.Styles.Error()).FillSampleValues();
  //tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);

  Steema.TeeChart.Tools.CursorTool cursor1 = new Steema.TeeChart.Tools.CursorTool(tChart1.Chart);
  cursor1.Series = tChart1[0];
  cursor1.FollowMouse = true;
  cursor1.Change += new Steema.TeeChart.Tools.CursorChangeEventHandler(cursor1_Change);
}

void cursor1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
{      
  Steema.TeeChart.Styles.Error error1 = (Steema.TeeChart.Styles.Error)tChart1[0];

  int index = error1.Clicked(e.x, e.y);
  string tmp = "";

  if (index != -1)
  {
    double y = error1.YValues[index];
    double error = error1.ErrorValues[index];
    double top = y + error;
    double bottom = y - error;
    tmp = "Error top: " + top.ToString("#.##") + 
          " Error bottom: " + bottom.ToString("#.##") +
          " Cursor pos.: " + e.XValue.ToString("#.##") + "/" + e.YValue.ToString("#.##");
  }
  else
  {
    tmp = "";
  }

  this.Text = tmp;
}
于 2012-03-14T08:29:21.420 回答
-3

我对 teechart 不熟悉,但我很确定如果没有 cursor.move 事件,您可以创建一个。然后像这样修改该事件以捕获 cursor.position

CursorMove(object sender, args e)
{

   this.lowerTextBox.value = cursor.postion;

}
于 2012-03-13T16:18:52.987 回答