Page 1 of 1
How to display Greek symbols on axis labels?
Posted: Wed Mar 11, 2020 5:00 pm
by 16487009
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?
Re: How to display Greek symbols on axis labels?
Posted: Thu Mar 12, 2020 8:01 am
by yeray
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;
Re: How to display Greek symbols on axis labels?
Posted: Thu Mar 12, 2020 9:34 pm
by 16487009
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?
Re: How to display Greek symbols on axis labels?
Posted: Fri Mar 13, 2020 8:08 am
by yeray
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 (3.54 KiB) Viewed 24915 times
Re: How to display Greek symbols on axis labels?
Posted: Fri Mar 13, 2020 10:49 am
by 16487009
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?
Re: How to display Greek symbols on axis labels?
Posted: Fri Mar 13, 2020 10:54 am
by 16487009
What I'm really looking for is this...
Re: How to display Greek symbols on axis labels?
Posted: Mon Mar 16, 2020 11:01 am
by yeray
Hello,
This is an issue already in the public tracker (
#1907) I'm currently revising.
Re: How to display Greek symbols on axis labels?
Posted: Mon Mar 16, 2020 12:43 pm
by 16487009
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
Re: How to display Greek symbols on axis labels?
Posted: Mon Mar 16, 2020 6:11 pm
by yeray
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.
Re: How to display Greek symbols on axis labels?
Posted: Fri Mar 20, 2020 9:50 am
by yeray
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.