Chartlistbox and Hover Effect?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Chartlistbox and Hover Effect?

Post by moelski » Wed Jan 13, 2010 7:56 am

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Chartlistbox and Hover Effect?

Post by Yeray » Wed Jan 13, 2010 11:22 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Re: Chartlistbox and Hover Effect?

Post by moelski » Thu Jan 14, 2010 8:38 am

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).

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Chartlistbox and Hover Effect?

Post by Yeray » Thu Jan 14, 2010 3:07 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply