centering Title on chart
centering Title on chart
using TeeChart v 7 in Borland Builder C++ 6. have 5 charts lined up next to each other. each as a different dynamic title. would like to center the title either over the graph or in the middle of the chart. have tried setting alignment property to Center and disabling custom location.
basically ... <left position of text>=(<chart width> - <width of title>) / 2
how do i calculate the <width of title>?
basically ... <left position of text>=(<chart width> - <width of title>) / 2
how do i calculate the <width of title>?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi rperkins,
You can try doing something like this:
The Draw call is necessary to force the chart being internally repainted and therefore drawn elements having valid property values.
You can try doing something like this:
Code: Select all
Chart1->Draw();
Chart1->Title->Width();
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
tried the code in the previous post (Draw and Width), but the Width is not a function, but an int property.
the current code has a function that is called after the Title text is changed. this is what was there, but doesn't work correctly.
int TitleWidth = aChart->DelphiCanvas->TextWidth(aChart->Title->Caption);
aChart->Title->Left = (aChart->Width-TitleWidth)/2;
note: aChart is the chart to manipulate and it's passed in to the function.
what happens in the above is that the text does move, but is not centered.
the current code has a function that is called after the Title text is changed. this is what was there, but doesn't work correctly.
int TitleWidth = aChart->DelphiCanvas->TextWidth(aChart->Title->Caption);
aChart->Title->Left = (aChart->Width-TitleWidth)/2;
note: aChart is the chart to manipulate and it's passed in to the function.
what happens in the above is that the text does move, but is not centered.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi rperkins,
What about doing something like this?
What about doing something like this?
Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Chart1->Title->Text->Clear();
Chart1->Title->Text->Add("This is my custom title text");
Chart1->Draw();
int tmpW=Chart1->DelphiCanvas->TextWidth(Chart1->Title->Text->Strings[0]);
Chart1->Title->CustomPosition=true;
Chart1->Title->Left=(Chart1->Width - tmpW)/2;
}
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi rperkins,
Another approach using ChartRect instead of whole chart dimensions.
Another approach using ChartRect instead of whole chart dimensions.
Code: Select all
Chart1->Title->Text->Clear();
Chart1->Title->Text->Add("This is my custom title text");
Chart1->Draw();
int TitleWidth=Chart1->DelphiCanvas->TextWidth(Chart1->Title->Text->Strings[0]);
Chart1->Title->CustomPosition=true;
Chart1->Title->Left=Chart1->ChartRect.Left+(Chart1->ChartRect.Width() - TitleWidth)/2;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
it appears that the TextWidth function isn't returning the correct size. doing a bit of experimentation, i've found that multiplying the TitleWidth by 1.4 always results in the correct placement over the chart. without this "fudge factor", the text is still too far to the right.
updated code is below. aChart is a parameter passed in to a local function which is used by all charts to update the title position.
String tempString = aChart->Title->Caption;
aChart->Title->Text->Clear();
aChart->Title->Text->Add(tempString);
aChart->Draw();
int TitleWidth=aChart->DelphiCanvas->TextWidth(aChart->Title->Text->Strings[0]);
TitleWidth = (int)((float)TitleWidth * 1.4 );
aChart->Title->CustomPosition=true;
aChart->Title->Left=aChart->ChartRect.Left+(aChart->ChartRect.Width() - TitleWidth)/2;
any thoughts?
updated code is below. aChart is a parameter passed in to a local function which is used by all charts to update the title position.
String tempString = aChart->Title->Caption;
aChart->Title->Text->Clear();
aChart->Title->Text->Add(tempString);
aChart->Draw();
int TitleWidth=aChart->DelphiCanvas->TextWidth(aChart->Title->Text->Strings[0]);
TitleWidth = (int)((float)TitleWidth * 1.4 );
aChart->Title->CustomPosition=true;
aChart->Title->Left=aChart->ChartRect.Left+(aChart->ChartRect.Width() - TitleWidth)/2;
any thoughts?
a co-worker (more familiar with TeeChart) suggested it might have something to do with the font associated with the canvas. he suggested that before doing the TextWidth, set the font of the canvas to the font of the title. this helped, but it still wasn't centered like the "fudge factor" multiply of 1.4
font setting....
aChart->DelphiCanvas->Font = aChart->Title->Font;
font setting....
aChart->DelphiCanvas->Font = aChart->Title->Font;
Hi,
using the following code seems to work fine here :
Chart3.Title.Left :=Chart3.ChartRect.Left + ((Chart3.Chartrect.right - chart3.ChartRect.Left) div 2) - ( Chart3.Canvas.textWidth(Chart3.Title.Caption) div 2);
Could you please test it ?
using the following code seems to work fine here :
Chart3.Title.Left :=Chart3.ChartRect.Left + ((Chart3.Chartrect.right - chart3.ChartRect.Left) div 2) - ( Chart3.Canvas.textWidth(Chart3.Title.Caption) div 2);
Could you please test it ?
Pep Jorge
http://support.steema.com
http://support.steema.com
same thing.
here's my Borland C++ converted code - i think it matches up with the delphi code.
aChart->Title->Left=aChart->ChartRect.Left+((aChart->ChartRect.right - aChart->ChartRect.Left)/2) -
(aChart->Canvas->TextWidth(aChart->Title->Caption)/2);
i've uploaded a new document to the Steema Upload site - ChartTitle-111907.doc. this shows the titles over the bottom 5 charts. using the above code, the 2nd screen shot has the titles running off the right. using the "fudge factor" i described before, there is enough room to display the entire title centered over the chart.
not sure if it's because of the font/size/style of the title. The font is Arial, size 10, Bold, TTeeShadow, clBlue.
let me know if there's anything else you'd like me to try.
thanks,
pbt.
here's my Borland C++ converted code - i think it matches up with the delphi code.
aChart->Title->Left=aChart->ChartRect.Left+((aChart->ChartRect.right - aChart->ChartRect.Left)/2) -
(aChart->Canvas->TextWidth(aChart->Title->Caption)/2);
i've uploaded a new document to the Steema Upload site - ChartTitle-111907.doc. this shows the titles over the bottom 5 charts. using the above code, the 2nd screen shot has the titles running off the right. using the "fudge factor" i described before, there is enough room to display the entire title centered over the chart.
not sure if it's because of the font/size/style of the title. The font is Arial, size 10, Bold, TTeeShadow, clBlue.
let me know if there's anything else you'd like me to try.
thanks,
pbt.
Hi,
it's strange. Are you able to reproduce the same problem iwth a small new app. (doing the same, adding just some charts and assign titles for them) ?
If so, could you please send us the app. so we can reproduce it ?
it's strange. Are you able to reproduce the same problem iwth a small new app. (doing the same, adding just some charts and assign titles for them) ?
If so, could you please send us the app. so we can reproduce it ?
Pep Jorge
http://support.steema.com
http://support.steema.com
i believe i uploaded the Borland C++ builder module (cpp, h, and dfm) file that contain the charts (for another unrelated support issue). it would be called MultiViewForm.zip. it's not in a self contained "mini-app", so it won't compile/run by itself. haven't had time to create a small test app, just time to come up with the fudge factor.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi rperkins,
We have looked at the code you sent but we are unable to compile it here. It is very difficult for us finding the problem without being able to reproduce the problem here. Test we have done here worked fine using this code:
Would you be so kind to arrange a simple example project we can run "as-is" to reproduce the problem here? This could only contain the numbers of charts you want, their titles and any other setting you feel to be relevant to the issue.
Thanks in advance.
We have looked at the code you sent but we are unable to compile it here. It is very difficult for us finding the problem without being able to reproduce the problem here. Test we have done here worked fine using this code:
Code: Select all
Chart3.Title.Left :=Chart3.ChartRect.Left + ((Chart3.Chartrect.right - chart3.ChartRect.Left) div 2) - ( Chart3.Canvas.textWidth(Chart3.Title.Caption) div 2);
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |