Page 1 of 1

Changing axes LabelFont properties by code does not work

Posted: Mon Sep 07, 2009 8:44 am
by 10046032
Hello,

I need to custom draw a TChart in to a metafile canvas. Everything works ok but before calling the DrawToMetaCanvas procedure I need to change the left axes fonts, so my code looks like:

Code: Select all

chart.Assign(qt_plot); // just to get titles etc from a template chart
chart.CustomChartRect:=true;
chart.ChartRect:=TeeRect(1,2,3,4); // do not pay attention to these values
chart.Axes.Left.LabelsFont.Color := clred;
chart.DrawToMetaCanvas(canvas, chart.ChartRect);
... but labels appear in black. Is it a bug or am I doing something wrong? I am using TChart Pro 8.0.6

Regards

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 07, 2009 9:57 am
by narcis
Hi johnnix,

The problem could be your ChartRect dimensions as not setting it to custom or using the rect in the code below works fine for me here. If the problem persists please attach a simple example project we can run "as-is" to reproduce the problem here.

Code: Select all

procedure TForm4.Button1Click(Sender: TObject);
begin
  Chart1.CustomChartRect:=true;
  Chart1.ChartRect:=TeeRect(0,0,200,200);
  Chart1.Axes.Left.LabelsFont.Color := clred;
  Chart1.DrawToMetaCanvas(Image1.Canvas, Chart1.ChartRect);
end;
Thanks in advance.

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 07, 2009 12:06 pm
by 10046032
Hello Narcis,

Yes, your code works ok because there is not assign statement! I just uploaded a sample app in the attachments newsgroup where you will see that if you comment the c.Assign(Chart1) line then labels do get red otherwise no change.... If you find a work around for me please let me know (I am a source code customer) so that I can test it here...

Thank you very much for your prompt reply.

Kindest regards

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 07, 2009 12:37 pm
by narcis
Hi johnnix,

I can't find the project at the upload area. Have you posted it? You may want to attach it to your reply. New forums engine supports attaching files with messages.

Thanks in advance.

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 07, 2009 12:51 pm
by 10046032
Hello Narcis,

Here it is then....

Kindest regards

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 07, 2009 1:59 pm
by narcis
Hello johnnix,

Sorry, now I found your project was at the attachments newsgroup, not at the upload page :oops:.

Regarding the issue reported, I think it is a bug which I have added to the list (TV52014389) to be fixed for future releases. There's no workaround I can think of for now.

Re: Changing axes LabelFont properties by code does not work

Posted: Tue Sep 08, 2009 7:27 am
by 10046032
Hello Narcis,

Ok, I did some research and found out that the last 2 lines of the procedure TAxisItems.CopyFrom somehow affect this issue. If I comment these lines then everything looks great:

Code: Select all

procedure TAxisItems.CopyFrom(Source: TAxisItems);
var t : Integer;
begin
  Format.Assign(Source.Format);

  Clear;

  //for t:=0 to Source.Count-1 do
  //    with Source[t] do Add(Value,Text);
end;
Can you please verify that the commented lines do not cause any other problem?

Kindest regards

Re: Changing axes LabelFont properties by code does not work

Posted: Tue Sep 08, 2009 3:00 pm
by narcis
Hi johnnix,

Thanks for the feedback. At this moment I'm not sure whether this change would brake other functionality. However, I don't think it's the solution as I can't reproduce this issue using our current v9 sources and they still have TAxisItems.CopyFrom implemented in the same way. I did a quick comparison between v8 and v9 sources but didn't find a significant difference on this area. I'll have another look and will get back to you when I have further news.

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 21, 2009 11:20 am
by narcis
Hi johnnix,

After some more testing I found the error also occurs in v9 sources. Your fix suggestion works fine and could be valid because CopyFrom method is not used anywhere else. Anyway I'm afraid implementing it may brake functionality in other circumstances. We will investigate the issue further.

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 21, 2009 11:45 am
by 10046032
Hello Narcis,

Thank you very much for looking into this issue. Indeed, before creating my post I double checked that CopyFrom is not used elsewhere so I also thought that my "fix" could be ok as it does not appear to have an affect outside that procedure. I was unable however to further investigate what makes the properties being fixed :(

I am sure that you will found a solution so please let me know of it :D

Kindest regards

Re: Changing axes LabelFont properties by code does not work

Posted: Mon Sep 21, 2009 1:33 pm
by narcis
Hi johnnix,

I found that using the fix you suggested doesn't work when original chart has custom axis labels. I finally found a solution which works fine for both default and custom labels which involves implementing CopyFrom and adding another Add method overload as shown here:

Code: Select all

Function TAxisItems.Add(const Value: Double; const Text:String; const Font:TTeeFont):TAxisItem;
begin
  result:=Add(Value,Text);
  result.Font:=Font;
end;

procedure TAxisItems.CopyFrom(Source: TAxisItems);
var t : Integer;
begin
  Format.Assign(Source.Format);

  if not Source.FAuto then
  begin
    Clear;

    for t:=0 to Source.Count-1 do
        with Source[t] do Add(Value,Text,Font);
  end;
end;
Hope this helps!

Re: Changing axes LabelFont properties by code does not work

Posted: Tue Sep 22, 2009 5:49 am
by 10046032
Hello Narcis,

Thank you very much for the code. The CopyFrom function with the new condition does the trick for me but the changes in Add function do not work. If I add the result.Font:=Font I get an undeclared identifier error and if I use the Add(Value, Text) then I get an exception while trying to run my app.

Kindest regards

Re: Changing axes LabelFont properties by code does not work

Posted: Tue Sep 22, 2009 7:27 am
by narcis
Hi johnnix,

Yes, sorry for not having been more specific but that probably is because you need to declare the overload below for the Add method at TAxisItems declaration.

Code: Select all

    Function Add(const Value: Double; const Text:String; const Font:TTeeFont):TAxisItem; overload;
Hope this helps!

Re: Changing axes LabelFont properties by code does not work

Posted: Tue Sep 22, 2009 7:39 am
by 10046032
Hello Narcis,

I am very sorry but did not realized that the Add method you introduced was a new one! Now, I can compile and run ok.

Thank you very much.

Kindest regards