SoFunction
Updated on 2025-03-07

c# Set the prompt text of the TeeChart control

Use the TeeChart control of a third-party Steema, set the mouse to place it on a certain line to display the data label problem at a certain point (dashed cross cursor baseline, placed on the line to display the two-dimensional coordinate axis data data of the corresponding point), and call the InitTeeChartTipTools method:

/// <summary>
///TeeChart line indication tool/// </summary>
 cursorTool;
/// <summary>
/// The text displayed by the mouse indicates/// </summary>
private  annotation;
/// <summary>
/// Initialize the prompt tool information of the line/// </summary>
private void InitTeeChartTipTools( tChart)
{
  //Dimension of coordinate axes in line form  cursorTool = new ();
   = ;
   = .;
   = ;
   = true;
   += CursorTool_Change;
  //Set the message of prompt text  annotation = new ();
   = "Arial";
   = 12;
   = true;
   = false;
   = ;
   = ;
   = ;

  for (int i = 0; i < ; i++)
  {
    [i].MouseEnter += Line_MouseEnter;
    [i].MouseLeave += Line_MouseLeave;
  }

   += TChart_MouseLeave;
   += TChart_MouseEnter;
}

/// <summary>
/// Event of the mouse entering TeeChart/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TChart_MouseEnter(object sender, EventArgs e)
{
  =;
}

/// <summary>
/// Event of the mouse leaving TeeChart/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TChart_MouseLeave(object sender, EventArgs e)
{
   = null;
}


/// <summary>
/// When the mouse enters the line, set the line indicated by TeeChart's cursorTool tool to the corresponding line/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Line_MouseEnter(object sender, EventArgs e)
{
   = sender as ;
}

/// <summary>
/// When the mouse leaves the line, set the line indicated by TeeChart's cursorTool tool to null/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Line_MouseLeave(object sender, EventArgs e)
{
   = null;
}
/// <summary>
/// Mouse Indication Tool Change Event/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CursorTool_Change(object sender,  e)
{
  try
  {
     cursor = sender as ;
    if (cursor != null &&  != null)
    {
       = ("({0},{1})", ("f1"), ("f1"));
       = (InterpolateLineSeries(, ));
       = ();
       -= 20;//Put the text above the mouse      SizeF size = ().MeasureString(,
        new Font(, ));
      if ( +  + 12 >= )
      {
         -= (int) + 12;//Prevent text labels from being incomplete after exceeding the right boundary      }
    }
    else
    {
      //Set it outside the control       = "";
       =  + 5;
       =  + 5;
    }
  }
  catch (Exception ex)
  {
     = ;
     = 5;
     = 5;
  }
}
/// <summary>
/// Calculate the Y value coordinates at a certain point/// </summary>
/// <param name="series">Curve</param>/// <param name="xvalue">The corresponding X-axis value</param>/// <returns>The calculated corresponding Y-axis value</returns>private double InterpolateLineSeries( series, double xvalue)
{
  try
  {
    int index;
    for (index = ; index &lt;= ; index++)
    {
      if (index == -1 || [index] &gt; xvalue) break;
    }
    // safeguard
    if (index &lt; 1)
    {
      index = 1;
    }
    else if (index &gt;= )
    {
      index =  - 1;
    }
    // y=(y2-y1)/(x2-x1)*(x-x1)+y1
    double dx = [index] - [index - 1];
    double dy = [index] - [index - 1];
    if (dx != 0.0)
    {
      return dy * (xvalue - [index - 1]) / dx + [index - 1];
    }
    else
    {
      return 0.0;
    }
  }
  catch (Exception ex)
  {
    ();
    return 0.0;
  }
}

The above is the detailed content of the prompt text for setting the TeeChart control in c#. For more information about setting the prompt text for c#, please pay attention to my other related articles!