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
changing text in Legend
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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.
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.
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.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.
You can use the ClickLegend event and the legend Clicked method as shown here:This leads me to another question :
how can i gets the corresponding serie when i click an item in the legend ?
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 |
Instructions - How to post in this forum |
re
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
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
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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:
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 |
Instructions - How to post in this forum |
all right.
not all the series are displayed in the legend (too much: can be loaded from several files)
when i just add the text "new text" in the legend for the 1st item, it goes
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..
nothing special...
not all the series are displayed in the legend (too much: can be loaded from several files)
when i just add the text "new text" in the legend for the 1st item, it goes
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
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 :
which draws the frame manually.
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;
Pep Jorge
http://support.steema.com
http://support.steema.com
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.
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.
Hi,
ok, maybe in this case, the better solution would be to draw a custom legend on the Canvas (using the Canvas techniques).
ok, maybe in this case, the better solution would be to draw a custom legend on the Canvas (using the Canvas techniques).
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 : TV52011324please let me know when this bug is fixed.
Pep Jorge
http://support.steema.com
http://support.steema.com