TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
Eic
- Newbie
- Posts: 5
- Joined: Fri Mar 24, 2017 12:00 am
Post
by Eic » Wed Jun 28, 2017 3:32 pm
Hi,
I want to center the title of my subgraph with AdjustFrame = false.
I use this code:
Code: Select all
TChart * Chart1 = new TChart(this);
Chart1->Parent = this;
Chart1->Align = alClient;
TSubChartTool *SubChart1 = new TSubChartTool(NULL);
Chart1->Tools->Add(SubChart1);
TChart * Chart2 = SubChart1->Charts->AddChart("MySubChart");
Chart2->AddSeries(new TPointSeries(Chart1))->FillSampleValues();
Chart2->Legend->Visible = true;
Chart2->Title->Caption = "SubChart Title";
Chart2->Title->Visible = true;
Chart2->Title->AdjustFrame = false;
SubChart1->Charts->Items[0]->Left = SubChart1->ParentChart->Width / 2;
SubChart1->Charts->Items[0]->Width = SubChart1->ParentChart->Width / 2;
In this situation, the title is not centered above my graph, as you can see in the attachment file.
While waiting for the bug fix, is there a solution ?
-
Attachments
-
- SubChart Title.png (10.35 KiB) Viewed 9025 times
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Fri Jun 30, 2017 10:09 am
Hello,
I'm not sure to understand why do you set AdjustFrame to false if you want the title to move with the Chart. Removing that line of code the title move to the desired position, isn't it?
-
Eic
- Newbie
- Posts: 5
- Joined: Fri Mar 24, 2017 12:00 am
Post
by Eic » Fri Jun 30, 2017 10:21 am
Hi,
I just want my title to be centered on the graph + legend.
When the line is deleted, the title is centered above the graph, without taking into account the place taken by the plenum.
There may be another property to do that?
I attached the file "Test 2" with the expected centering in red for the title
-
Attachments
-
- Test 2.png (20.62 KiB) Viewed 9009 times
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Fri Jun 30, 2017 11:32 am
Hello,
You can use the SubChart's (Chart2 in your example) OnBeforeDrawChart event to manually reposition its Title. Ie (delphi):
Code: Select all
procedure TForm1.SubChartBeforeDraw(Sender: TObject);
begin
with TChart(Sender) do
begin
Title.Top:=Top - Canvas.TextHeight(Title.Caption);
Title.Left:=Left+(Width div 2) - (Canvas.TextWidth(Title.Caption) div 2);
end;
end;
-
Eic
- Newbie
- Posts: 5
- Joined: Fri Mar 24, 2017 12:00 am
Post
by Eic » Fri Jun 30, 2017 11:44 am
Thank you for this temporary solution.
This bug will be corrected, or is it normal ?
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Fri Jun 30, 2017 1:43 pm
Hello,
The AdjustFrame property was designed to align the title with the ChartRect, not with the whole TChart.
If we changed this behaviour we'd break the compatibility. However, we could add some extra property to choose where to align the chart with more detail.