Page 1 of 1

TSubChartTool and center title without AdjustFrame

Posted: Wed Jun 28, 2017 3:32 pm
by 16480579
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 ?

Re: TSubChartTool and center title without AdjustFrame

Posted: Fri Jun 30, 2017 10:09 am
by yeray
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?

Re: TSubChartTool and center title without AdjustFrame

Posted: Fri Jun 30, 2017 10:21 am
by 16480579
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

Re: TSubChartTool and center title without AdjustFrame

Posted: Fri Jun 30, 2017 11:32 am
by yeray
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;

Re: TSubChartTool and center title without AdjustFrame

Posted: Fri Jun 30, 2017 11:44 am
by 16480579
Thank you for this temporary solution.

This bug will be corrected, or is it normal ?

Re: TSubChartTool and center title without AdjustFrame

Posted: Fri Jun 30, 2017 1:43 pm
by yeray
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.