Is there a simple way to find the nearest series on mouse move? I have got the nearest point tool, which unfortunately does not seem to work for all series, so I can neither use it to find a point on a multi series chart, or to even find the nearest series. Unless I'm missing something?
Thanks for your help.
Nearest Series
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Sam,
Which is the exact problem you are having with nearest point tool? An example we can run "as-is" to reproduce the problem here would be helpful.
You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Thanks in advance.
Which is the exact problem you are having with nearest point tool? An example we can run "as-is" to reproduce the problem here would be helpful.
You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
My first problem is that I have to assign a specific series to the nearest point tool, rather than having it work to find the nearest point of any series.
If the tool only works for a single series at a time, that makes it useless to my needs.
My primary requirement is, wherever the mouse is, I wish to know which series is closest. But I'd also like to be able to identify which point is closest as well, regardless of which series it is in.
I hope that makes it clearer.
Code: Select all
TLineSeries* MySeries = new TLineSeries(this);
MySeries->AddXY(4,101);
MySeries->AddXY(5,24);
Chart1->AddSeries(MySeries);
TLineSeries* MySeries2 = new TLineSeries(this);
MySeries2->AddXY(2,52);
MySeries2->AddXY(7,13);
Chart1->AddSeries(MySeries2);
//Tool wont work without limiting it to one specific series
NearestPointTool1->Series = MySeries;
My primary requirement is, wherever the mouse is, I wish to know which series is closest. But I'd also like to be able to identify which point is closest as well, regardless of which series it is in.
Code: Select all
void __fastcall TForm1::Chart1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
//How do I get these two values, in a multi-series environment?
int iNearestSeriesIndex = 0;
int iNearestPointIndex = 0;
//Highlight the nearest series
for(int i = 0; i < Chart1->SeriesCount(); i++)
{
if(i == iNearestSeriesIndex ) Chart1->Series[i]->Pen->Width = 3;
else Chart1->Series[i]->Pen->Width = 1;
}
//Display value of nearest point
Chart1->SubTitle->Text->Clear();
Chart1->SubTitle->Text->Add(Chart1->Series[iNearestSeriesIndex ]->YValues->Value[iNearestPointIndex]);
}
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Sam F,
Yes, in that case you can use NearestPoint tool like this:
Hope this helps!
Yes, in that case you can use NearestPoint tool like this:
Code: Select all
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var NearestPoints: array of integer;
i, j, k, SeriesIndex, ValueIndex: Integer;
Dist, tmp: double;
P1, P2: TPoint;
begin
SetLength(NearestPoints, Chart1.SeriesCount);
for i:=0 to High(NearestPoints) do
NearestPoints[i]:=ChartTool1.GetNearestPoint(Chart1[i], X, Y);
for j:=0 to High(NearestPoints) do
begin
P1.X:=Chart1[j].CalcXPos(NearestPoints[j]);
P1.Y:=Chart1[j].CalcYPos(NearestPoints[j]);
P2.X:=X;
P2.Y:=Y;
tmp:=Distance(P1,P2);
if ((j=0) or (tmp<Dist)) then
begin
Dist:=tmp;
SeriesIndex:=j;
ValueIndex:=NearestPoints[j];
end;
end;
for k:=0 to Chart1.SeriesCount-1 do
begin
if k=SeriesIndex then
(Chart1[k] as TPointSeries).Pointer.Pen.Width:=3
else
(Chart1[k] as TPointSeries).Pointer.Pen.Width:=1;
Chart1[k].RefreshSeries;
end;
Chart1.Title.Text[0]:='Series: ' + IntToStr(SeriesIndex) +
' - ValueIndex: ' + IntToStr(ValueIndex);
end;
function TForm1.Distance(Pt : TPoint; Pt2 : TPoint) : Double;
var dx, dy : LongInt;
begin
dx:= pt .x - pt2.x;
dy:= pt .y - pt2.y;
Result := Sqrt((Dx * Dx) + (Dy * Dy));
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Sam,
Yes, I've added it to the wish-list to be considered for inclusion in future releases.
Yes, I've added it to the wish-list to be considered for inclusion in future releases.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |