Page 1 of 1
Chartlistbox and Hover Effect?
Posted: Wed Jan 13, 2010 7:56 am
by 10545590
Hi !
Is it possible to detect if the mouse is over an item/series in the chartlistbox (without clicking the mouse)?
Let´s think about the following situation:
You have 10 or more active curves in your chart. Now the users hovers over the chartlistbox and the series items.
If there is any chance to detect the series where the mouse is over this series could be painted with a line pen width +1 as long as the mouse is over the series.
Greetz
Dominik
Re: Chartlistbox and Hover Effect?
Posted: Wed Jan 13, 2010 11:22 am
by yeray
Hi Dominik,
Taking
this example as reference, it is easy to obtain the following solution:
Code: Select all
uses series;
var selectedSeries: Integer;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
chart1.View3D:=false;
for i := 0 to 5 do
begin
Chart1.AddSeries(TFastLineSeries.Create(self));
Chart1[i].FillSampleValues();
end;
Chart1.Legend.CheckBoxes:=true;
selectedSeries:=-1;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var i: Integer;
tmpPnt: TPoint;
tmpRect: TRect;
begin
tmpPnt.X:=X;
tmpPnt.Y:=Y;
for i:=0 to Chart1.SeriesCount-1 do
begin
tmpRect.Left:=Chart1.Legend.Left;
tmpRect.Right:=Chart1.Legend.Left + Chart1.Legend.Width - 1;
tmpRect.Bottom:=Chart1.Legend.Item[i].Top + Chart1.Legend.Item[i].SymbolRect.Bottom - Chart1.Legend.Item[i].SymbolRect.Top + 3;
if (i = 0) then tmpRect.Top:=Chart1.Legend.Item[i].Top-3
else tmpRect.Top:=Chart1.Legend.Item[i].Top-2;
if PtInRect(tmpRect,tmpPnt) then
begin
if selectedSeries>-1 then Chart1[selectedSeries].Pen.Width:=1;
selectedSeries:=i;
Chart1[selectedSeries].Pen.Width:=3;
break;
end;
end;
end;
Re: Chartlistbox and Hover Effect?
Posted: Thu Jan 14, 2010 8:38 am
by 10545590
Hi Yeray,
that´s not what I need.
I want to hover over the ChartListBox - not over the Chart.
In easy words I need this:
Hover over a series in the ChartListBox and repaint the corresponding series with a line width +1 (as long as the hover takes).
Re: Chartlistbox and Hover Effect?
Posted: Thu Jan 14, 2010 3:07 pm
by yeray
Hi Dominik,
Excuse me, I missed that. But the solution for a ChartListBox isn't very different:
Code: Select all
uses series;
var selectedSeries: Integer;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
ChartListBox1.Chart:=Chart1;
chart1.View3D:=false;
for i := 0 to 5 do
begin
Chart1.AddSeries(TFastLineSeries.Create(self));
Chart1[i].FillSampleValues();
end;
Chart1.Legend.Visible:=false;
selectedSeries:=-1;
end;
procedure TForm1.ChartListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var i: Integer;
tmpPnt: TPoint;
tmpRect: TRect;
begin
tmpPnt.X:=X;
tmpPnt.Y:=Y;
for i:=0 to Chart1.SeriesCount-1 do
begin
if PtInRect(ChartListBox1.ItemRect(i),tmpPnt) then
begin
if selectedSeries>-1 then Chart1[selectedSeries].Pen.Width:=1;
selectedSeries:=i;
Chart1[selectedSeries].Pen.Width:=2;
break;
end;
end;
end;