图表:展开"clickable"线/快速线的宽度

本文关键字:quot clickable 展开 图表 | 更新日期: 2023-09-27 18:16:33

我有一个WinForms应用程序,其中在一个TeeChart组件中绘制了许多行。要求可以通过右键单击一行来删除它。

一切正常,clickseries事件被捕获等等,但是用户发现在右击时很难击中行。问题是,是否有可能增加点击Line/FastLine对象的区域?也就是说,让线条变宽,而不让线条在屏幕上变宽。

图表:展开"clickable"线/快速线的宽度

是的,这是可能的。实现这一目标的关键是pointinlinettolerance方法。为了实现您的请求,您可以将它与NearestPoint的工具GetNearestPoint方法结合使用,如下例所示:

public Form1()
{
  InitializeComponent();
  InitializeChart();
}
private void InitializeChart()
{
  tChart1.Aspect.View3D = false;
  tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();
  tChart1.MouseMove += TChart1_MouseMove;
}
private void TChart1_MouseMove(object sender, MouseEventArgs e)
{
  var nearestPoint = new Steema.TeeChart.Tools.NearestPoint(tChart1[0]);
  nearestPoint.Active = false;
  var p = new Point(e.X, e.Y);
  var index = nearestPoint.GetNearestPoint(p);
  if (index != -1)
  {
    const int tolerance = 10;
    var px = tChart1[0].CalcXPos(index);
    var py = tChart1[0].CalcYPos(index);
    var index2 = (index == tChart1[0].Count - 1) ? index - 1 : index + 1;
    var qx = tChart1[0].CalcXPos(index2);
    var qy = tChart1[0].CalcYPos(index2);
    if (Steema.TeeChart.Drawing.Graphics3D.PointInLineTolerance(p, px, py, qx, qy, tolerance))
    {
      tChart1.Header.Text = "point " + index.ToString() + " clicked";
    }
    else
    {
      tChart1.Header.Text = "No point";
    } 
  }

另一种方法是使用与原始序列具有相同数据的不可见假序列。