Page 1 of 1

TCursorTool calculation

Posted: Mon Mar 16, 2015 8:07 pm
by 9238362
Using TeeChart Pro 7.07 with BCB6

I'm trying to calculate the Y value of a TLineSeries on a cursor event. To complicate matters, I have multiple charts on the form and multiple series on each chart. What I want to do is report the y value for each series that a vertical cursor intersects. Each series has its own custom vertical axis. All series share the same x-axis but have varying numbers of points. I've tried several methods used in examples from the forum, but can't seem to get the right thing.

How can I calculate the correct Y value for each series?

Code: Select all

void __fastcall TfrmChartDisp::CursorChange(TCursorTool *Sender, Integer x, Integer y, Double XValue, Double YValue, TChartSeries *Series,
       Integer ValueIndex)
{
  String s;

  if( Sender )
  {
      // Which chart?
      chrt = (TChart *) Sender->ParentChart;

      for (int i = 0; i < chrt->SeriesCount(); i++)
      {
         int xpos = chrt->Axes->Bottom->CalcXPosValue(XValue);
         int ypos = chrt->Series[i]->CalcYPos(ValueIndex);

         double d = 100.0;
         int YValIndex = Sender->NearestPoint(cssVertical, d);

         s = String( XValue ) + String(", ") + String( YValue );

         // Add label next to cursor at ypos
         chrt->Canvas->TextOut( xpos, ypos, s);
      }
  }
}

Re: TCursorTool calculation

Posted: Tue Mar 17, 2015 3:11 pm
by yeray
Hello,

Have you seen the Interpolation example?
Take a look at the demo at All features\Welcome!\Chart Styles\Standard\Line (Strip)\Interpolating Line series

Re: TCursorTool calculation

Posted: Tue Mar 17, 2015 3:24 pm
by 9238362
Thank you for the suggestion, however that item is not included in the v7.07 demo. Is it available online somewhere?

Re: TCursorTool calculation

Posted: Tue Mar 17, 2015 3:27 pm
by yeray
Hello,

Yes, here.