changing text in Legend

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Copeau
Newbie
Newbie
Posts: 9
Joined: Tue Jan 24, 2006 12:00 am

changing text in Legend

Post by Copeau » Fri Mar 03, 2006 4:26 pm

Hi there.

i am changing the text of an item in a legend when this item is clicked.
my legend is on the right.

the result is that the text is changed as excpected, the size of the rectangle is adjusted to the text,
BUT the symbol is not moved at all.
so, the rectangle is bigger (on the left), the symbol is now far from the left border of the legend box, and the text goes out of the box on the right.

i have no idea of what i do wrong.

This leads me to another question :
how can i gets the corresponding serie when i click an item in the legend ?

thanks in advance

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Mar 03, 2006 4:53 pm

Hi Copeau,

First of all, please notice that I moved your topic from TeeTree VCL forum to TeeChart VCL forum as I assumed this is a TeeChart question instead of a TeeTree question.
the result is that the text is changed as excpected, the size of the rectangle is adjusted to the text,
BUT the symbol is not moved at all.
so, the rectangle is bigger (on the left), the symbol is now far from the left border of the legend box, and the text goes out of the box on the right.

i have no idea of what i do wrong.
Could you please send us an example we can run "as-is" to reproduce the problem here? You can post your files at news://www.steema.net/steema.public.attachments newsgroup.
This leads me to another question :
how can i gets the corresponding serie when i click an item in the legend ?
You can use the ClickLegend event and the legend Clicked method as shown here:

Code: Select all

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var Index: Integer;
begin
  Index:=Chart1.Legend.Clicked(X,Y);

  if Index <> -1 then
    Chart1.Title.Text[0]:='Legend item clicked is ' + IntToStr(Index);
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
Image Image Image Image Image Image
Instructions - How to post in this forum

Copeau
Newbie
Newbie
Posts: 9
Joined: Tue Jan 24, 2006 12:00 am

re

Post by Copeau » Fri Mar 03, 2006 5:17 pm

thanks
well, i ll try to send an example as soon as i can..

for the next question, i know already the legend.click(XY).. what i want is not the legend item, but the corresponding serie..

actually, since i experienced problems while changing the text of an item in the legend (got with the famous click(XY) :-p) , i wanted to try to change the title of the serie.. but i was not able to get the serie..

thx again

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Mar 06, 2006 9:18 am

Hi Copeau,

If all series are displayed in the legend you may also get their index by using a similar code to the one before and then using the index for the series too:

Code: Select all

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var Index: Integer;
begin
  Index:=Chart1.Legend.Clicked(X,Y);

  if Index <> -1 then
    Chart1[Index].Title:='My Custom Title '+IntToStr(Index);
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
Image Image Image Image Image Image
Instructions - How to post in this forum

Copeau
Newbie
Newbie
Posts: 9
Joined: Tue Jan 24, 2006 12:00 am

Post by Copeau » Mon Mar 06, 2006 9:56 am

all right.

not all the series are displayed in the legend (too much: can be loaded from several files)
Image

when i just add the text "new text" in the legend for the 1st item, it goes
Image

do you see what i mean ?


The same happens when the legend is set to Right position, or anywhere.
the white rect gets bigger as expected, but the items don't move..

Code: Select all

  if(ssLeft in Shift) and (ssDouble in Shift) then
  begin
    ClickedLegend := Chart1.Legend.Clicked( x,y );
    if ClickedLegend <> -1 then
       Chart1.Legend.Item[ClickedLegend].Text := EditLegendText.Text
   end
nothing special...

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Mar 14, 2006 7:46 pm

Hi,

yes, it's a bug, seems the problem is related with the calculation of the ShapeBounds depending on the text. We'll try to fix it for the next maintenance releases, in meantime a workaround is to use similar code like the following :

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var ClickedLegend,xx,xwidth:integer;
  begin
  ClickedLegend := Chart1.Legend.Clicked( x,y );
  if ClickedLegend <> -1 then
       Chart1.Legend.Item[ClickedLegend].Text := 'hello';
end;

procedure TForm1.Chart1BeforeDrawChart(Sender: TObject);
begin
  Chart1.Canvas.Brush.Style:=bsSolid;
  Chart1.Canvas.Rectangle(r);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Legend.Transparent:=true;
  Chart1.Draw;
  r:=chart1.Legend.ShapeBounds;
end;
which draws the frame manually.

Copeau
Newbie
Newbie
Posts: 9
Joined: Tue Jan 24, 2006 12:00 am

Post by Copeau » Wed Mar 15, 2006 9:27 am

ok thank you.
actually i often have to switch to polar/cartesian, and even use smith chart on the same chart, i use different alignments for the legend..
well, i'll try to make something using legend.shapebounds but i'm not sure this is going to work here.
please let me know when this bug is fixed.

thanks Pep.

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Mar 17, 2006 11:24 am

Hi,

ok, maybe in this case, the better solution would be to draw a custom legend on the Canvas (using the Canvas techniques).
please let me know when this bug is fixed.
Ok, I'll try to remember, however you can take a look at the bug fixes list when a new release is ready, the ID of this issue is : TV52011324

Post Reply