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);
}
}
}