|
Round Meter |
Posted by Sofia on Aug-28-2012 15:03 |
|
Hello,
I am trying to set text that shows value like in your example:
m->addText(100, 165, m->formatValue(value, "2"), "Arial", 8, 0xffffff,
Chart::Center)->setBackground(0x000000, 0x000000, -1);
But, my text is not centered, it is a little moved to right. Text starts at the half width ( in this example 100 px) , and move to right.
How can I text centered?
Thanks,
Sofia |
Re: Round Meter |
Posted by Peter Kwan on Aug-28-2012 20:11 |
|
Hi Sofia,
As I have not seen your chart image, it is hard for me to know if the text is already centered.
Note that the width of a character may include empty space to the right and/or left of the character. For example, in most fonts (eg. Arial, Times New Roman), all digits are designed to be of the same width. So if you have multiple lines of numbers, the digits will line up properly. It means the digit 1 and 0 are of the same width. Since the stroke of digit 1 is thinner than digit 0, it needs to have some empty space padded to the left and right side of the digit 1 to make it the same width as digit 0.
If the above is the cause of what you see, then it is normal (even a Word Processor or HTML web page would have layout the text in the same way as ChartDirector). If you wouuld like the manually manipulate the location of the text, you may use TextBox2.setMargin2 to set asymetrically margins to the text box (say 4 pixels right margin, but 1 pixel left margin). This would have the effect of shifting the text within the text box. The code is like:
TextBox* t = m->addText(100, 165, m->formatValue(value, "2"), "Arial", 8, 0xffffff,
Chart::Center);
t->setMargin(1, 4, 2, 2);
t->setBackground(0x000000, 0x000000, -1);
If you think the above is not the cause of the problem, please kindly attach an image, so I can see the extent of the non-centering to try to determine what may be the cause of the problem.
Regards
Peter Kwan |
Re: Round Meter |
Posted by Sofia on Aug-28-2012 20:38 |
|
Hi Peter,
attached picture is the result of the following code:
TextBox* t = m->addText(100, 165, m->formatValue(value, "2"), "Arial", 8, 0xffffff,
Chart::Center);
t->setMargin(1, 4, 2, 2);
t->setBackground(0x000000, 0x000000, -1);
Output is the same when code is like this :
m->addText(100, 165, m->formatValue(value, "2"), "Arial", 8, 0xffffff,
Chart::Center)->setBackground(0x000000, 0x000000, -1);
Thank you,
Sofia
|
Re: Round Meter |
Posted by Peter Kwan on Aug-28-2012 20:26 |
|
Hi Sofia,
As I have not seen your chart image, it is hard for me to know if the text is already centered.
Note that the width of a character may include empty space to the right and/or left of the character. For example, in most fonts (eg. Arial, Times New Roman), all digits are designed to be of the same width. So if you have multiple lines of numbers, the digits will line up properly. It means the digit 1 and 0 are of the same width. Since the stroke of digit 1 is thinner than digit 0, it needs to have some empty space padded to the left and right side of the digit 1 to make it the same width as digit 0.
If the above is the cause of what you see, then it is normal (even a Word Processor or HTML web page would have layout the text in the same way as ChartDirector). If you wouuld like the manually manipulate the location of the text, you may use TextBox2.setMargin2 to set asymetrically margins to the text box (say 4 pixels right margin, but 1 pixel left margin). This would have the effect of shifting the text within the text box. The code is like:
TextBox* t = m->addText(100, 165, m->formatValue(value, "2"), "Arial", 8, 0xffffff,
Chart::Center);
t->setMargin(1, 4, 2, 2);
t->setBackground(0x000000, 0x000000, -1);
If you think the above is not the cause of the problem, please kindly attach an image, so I can see the extent of the non-centering to try to determine what may be the cause of the problem.
Regards
Peter Kwan |
Re: Round Meter |
Posted by Sofia on Aug-28-2012 22:34 |
|
Hi Peter,
I found out what was my problem.
In my code aligment was 6st parametar from addText function, not 7t as it should be.
Thanks a lot of for your help,
Sofia |
|