How to display Greek symbols on axis labels?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Geocentrix
Newbie
Newbie
Posts: 7
Joined: Mon Sep 09, 2019 12:00 am

How to display Greek symbols on axis labels?

Post by Geocentrix » Wed Mar 11, 2020 5:00 pm

I am creating scatter plots in code and want to display the following label on the x-axis:
Rotation <THETA> (degrees)
where <THETA> is the Greek capital symbol theta, whose Unicode value is 0x4a.

Is there a way of doing this IN CODE?

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

Re: How to display Greek symbols on axis labels?

Post by Yeray » Thu Mar 12, 2020 8:01 am

Hello,

I'm not sure if you want to draw it in the axis title or in all the axis labels.
Anyway, the base of the code would be this:

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
{$IFNDEF CLX}
var UnicodeString : WideString;
{$ENDIF}
begin
  inherited;

{$IFNDEF CLX}

  SetLength(UnicodeString, 1);
  UnicodeString[1] := WideChar($0398);

  with Chart1.Canvas.Font do
  begin
    Size:=15;
    Name:='Arial Unicode MS';
  end;

  SetBkMode(Chart1.Canvas.Handle, TRANSPARENT);

  TextOutW(Chart1.Canvas.Handle, 10, 10, PWideChar(UnicodeString),
                                         Length(UnicodeString));

{$ENDIF}
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

Geocentrix
Newbie
Newbie
Posts: 7
Joined: Mon Sep 09, 2019 12:00 am

Re: How to display Greek symbols on axis labels?

Post by Geocentrix » Thu Mar 12, 2020 9:34 pm

Thanks, that work just fine.

It was even simpler - by setting the axis->Title->FontName to ""Arial Unicode MS" I get the required symbol.

Presumably, if I want to display symbols with subscripts, I would need to draw the title myself, including the subsripts?

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

Re: How to display Greek symbols on axis labels?

Post by Yeray » Fri Mar 13, 2020 8:08 am

Hello,

You could use ttfHtml font format as follows:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Title.Font.Size:=18;
  Chart1.Title.Font.Name:='Arial Unicode MS';
  Chart1.Title.TextFormat:=ttfHtml;
  Chart1.Title.Text.Text:='Theta: ' + WideChar($0398) + '<sub>subscript</sub>' + '<sup>superscript</sup>';
end;
Project1_2020-03-13_09-07-42.png
Project1_2020-03-13_09-07-42.png (3.54 KiB) Viewed 24950 times
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

Geocentrix
Newbie
Newbie
Posts: 7
Joined: Mon Sep 09, 2019 12:00 am

Re: How to display Greek symbols on axis labels?

Post by Geocentrix » Fri Mar 13, 2020 10:49 am

Yeray

Thanks for the further suggestions. That is (almost) what I want...

Both the subscript and the superscript appear to be too low relative to the regular text. Is there any way to control that?

Geocentrix
Newbie
Newbie
Posts: 7
Joined: Mon Sep 09, 2019 12:00 am

Re: How to display Greek symbols on axis labels?

Post by Geocentrix » Fri Mar 13, 2020 10:54 am

What I'm really looking for is this...

Image

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

Re: How to display Greek symbols on axis labels?

Post by Yeray » Mon Mar 16, 2020 11:01 am

Hello,

This is an issue already in the public tracker (#1907) I'm currently revising.
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

Geocentrix
Newbie
Newbie
Posts: 7
Joined: Mon Sep 09, 2019 12:00 am

Re: How to display Greek symbols on axis labels?

Post by Geocentrix » Mon Mar 16, 2020 12:43 pm

Yeray

Thanks for the additional info.

Looking at the proposed fix in the database, I would like to make the following commets:
  • The upwards and downwards offsets are MUCH better
  • However, there should be lest space between the end of the regular text and the beginning of the sub/superscript
Will the fix make it in the next release?

Andrew

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

Re: How to display Greek symbols on axis labels?

Post by Yeray » Mon Mar 16, 2020 6:11 pm

Hello,

I'm not sure because I've just seen this is breaking other html tags such as <big> and <small>
So we should revise it.
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

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

Re: How to display Greek symbols on axis labels?

Post by Yeray » Fri Mar 20, 2020 9:50 am

Andrew,
Geocentrix wrote:
Mon Mar 16, 2020 12:43 pm
  • However, there should be lest space between the end of the regular text and the beginning of the sub/superscript
In general we need to calculate the text size with a margin.
This is related to this old issue.
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