Page 1 of 1
changing text in Legend
Posted: Fri Mar 03, 2006 4:26 pm
by 9345071
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
Posted: Fri Mar 03, 2006 4:53 pm
by narcis
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;
re
Posted: Fri Mar 03, 2006 5:17 pm
by 9345071
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
Posted: Mon Mar 06, 2006 9:18 am
by narcis
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;
Posted: Mon Mar 06, 2006 9:56 am
by 9345071
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..
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...
Posted: Tue Mar 14, 2006 7:46 pm
by Pep
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.
Posted: Wed Mar 15, 2006 9:27 am
by 9345071
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.
Posted: Fri Mar 17, 2006 11:24 am
by Pep
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