|
Delta symbol |
Posted by ADQA on Mar-28-2017 15:11 |
|
Hi!
I want to show a delta symbol in the Y axis of my graphic, but I don't know how. I tried with this codes
htmlentities("&Delta");
'&Delta';
& #x00394;
but doesn't work. Any help?
Thank you in advance! |
Re: Delta symbol |
Posted by Peter Kwan on Mar-28-2017 19:12 |
|
Hi ADQA,
The "& Delta;" and "& #x00394;" are for delta character in HTML escape sequence. However, your charting code is not written in HTML. It is written in PHP.
In PHP, if your PHP source code encoding is UTF8, you can just enter the delta symbol directly using your text editor, just like how you enter the delta character is a MS Word or Excel file. We found that in many case, people are not sure what their PHP encoding is, or what the server expects the PHP encoding to be. In this case, a more certain method is to just enter the UTF8 encoded Delta character directly using PHP escape sequence, which is "xcex94".
Note that you must use a font that contains the Delta character. On Windows or Mac OS X, most fonts contain the Delta character. On Linux, there is no standard font. ChartDirector 6 comes with the Liberation font as the Arial font substitute for the sample program. If you are using this font, it does have the Delta character.
Hope this can help.
Regards
Peter Kwan |
Re: Delta symbol |
Posted by ADQA on Mar-29-2017 19:31 |
|
Hello, and thank you for your response.
I tried to write the symbol like a Word or Excel, and I see it correctly in my code editor program, but in the webpage I see this symbol (look at the attached image)
I would try to write the Delta using PHP escape sequence, but I don't know how. Can you help me?
Thanks
|
Re: Delta symbol |
Posted by Peter Kwan on Mar-29-2017 23:42 |
|
Hi ADQA,
The PHP escape sequence is "\\xce\\x94". (Sorry for some reason, the backslash was not displayed in my previous message.)
Encoding is a little bit tricky. If the code editor can save the source code with the Delta character, and then when it closes the file and re-opens the file, it can still see the Delta character, it means the code editor can understand its own encoding, which must be non-ASCII (since ASCII does not have the Delta character). Do you know which encoding it is using? We also do not know whether your PHP understands the encoding. (Do you know which encoding your PHP is configured to expect for the source code?) The coding may or may not be UTF8. ChartDirector expects UTF8 encoding.
From my experience, using the escape sequence should be more reliable. If you prefer to directly enter the delta character (and there using non-ASCII encoding for the PHP source code), please configure your code editor to save in UTF8 without BOM. (Some PHP versions do not support BOM.)
By default, most PHP is configured to not to worry about encoding. So if the text string is in UTF8, PHP will just pass it byte by byte to ChartDirector and it will work. However, some PHP may be configured to use a specific encoding, such as ISO-8859-1 (the western European encoding). If the source code is not ISO-8859-1, PHP will understand the text string incorrectly, and it will result in corrupted characters. You can use
zend.script_encoding to configure the PHP not to worry about encoding or to use UTF8 encoding, or you can add a line declare('encoding=UTF-8'); as the first line of your PHP code. Note that using zend.script_encoding or declare(encoding=....) to set to UTF8 requires zend.multibyte to be enabled and the PHP mbstring extension installed. Please refer to PHP documentation for details.
If your code editor does not output UTF8 but using other encodings, you can configure the PHP to understand the encoding, and then use mb_convert_encoding to convert to UTF8.
As you can see, the directly entering the Delta character is very complicated. So no matter in PHP or HTML, it is best to use escape sequence. In PHP, the escape sequence for UTF8 is "\\xce\\x94". There are various online tools to find the escape sequence. For example:
https://mothereff.in/utf-8
I have attached an example deltabar.php for your reference. In it, I have used both the escape sequence and the direct method. You can try it to see the result.
Regards
Peter Kwan
deltabar.php |
---|
<?php
require_once("../lib/phpchartdir.php");
#The data for the bar chart
$data = array(85, 156, 179.5, "211", 123);
#The labels for the bar chart
$labels = array("Δ", "Tue", "Wed", "Thu", "Fri");
#Create a XYChart object of size 250 x 250 pixels
$c = new XYChart(250, 250);
$c->addTitle("\\xce\\x94");
#Set the plotarea at (30, 20) and of size 200 x 200 pixels
$plotArea = $c->setPlotArea(30, 20, 200, 200);
#Add a bar chart layer using the given data
$c->addBarLayer($data);
#Set the x axis labels using the given labels
$c->xAxis->setLabels($labels);
#output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>
|
| |
Re: Delta symbol |
Posted by ADQA on Mar-31-2017 17:41 |
|
Hi and thank you for your help.
Answering your question, I am using UTF8 encode. I tried encoding the php file with BOM too, but I still have not succeeded. I think that the encoding is correct, because I can see correctly other symbols like € and accents. But no way with greek symbols (the font I am using is arialbd.ttf).
I tried to write the delta in two ways that you tell me (Δ and xcex94) and write the value of the variable using utf8_encode($var) and utf8_decode($var) too , but I still have not lucky.
Any other ideas? Thank you |
Re: Delta symbol |
Posted by Peter Kwan on Mar-31-2017 18:41 |
|
Hi ADQA,
Have you tried the file "deltabar.php" in my last message without any modification? (Do not edit it. If the path "../lib/phpchartdir.php" is not correct for your environment, do not modify it. Just create the "../lib" directory in your environment and put the "phpchartdir.php" inside.
I mentioned not to modify the file in anyway, just to avoid the uncertainty that the editor may have changed some other things.
Does the "deltabar.php" works by showing the delta symbol? If it does not show the delta simply, please attached the image created. Somethings what looks like corrupted characters may still contain useful information. Also, please inform me of the result of the "phpinfo" page. (If you cannot post the result in a public forum, you can email it to me at pkwan@advsofteng.net).
If the "deltabar.php" does work, but it does not work in your own code, is it possible to create a simple hard coded example that can illustrate the problem, such as by modifying the "simplebar.php" sample code, and then zip it and attached the zipped file with your message, so I can try it? (The zipping is to ensure the file is the exactly original file without modification.)
Regards
Peter Kwan |
Re: Delta symbol |
Posted by Peter Kwan on Mar-31-2017 19:37 |
|
Hi ADQA,
After looking at your previous screenshot very carefully, I suspect the font actually used is not Arial Bold (arialbd.ttf).
I have not actually analyzed your bold font, but I analyze the labels on the axis (0.1, 0.2, 0.3), etc.. I find that they are not Arial font, and not Liberation font as well.
(The Liberation font is the substitute font shipped with ChartDirector 6.0 on Linux/FreeBSD/Solaris as these OS do not have standard built-in Arial or Times New Roman fonts, and we cannot ship with Arial or Times New Roman fonts as they are copyrighted.)
I suspect the font is another substitute font that we used in ChartDirector 5 or earlier. These fonts do not have Greek characters, but may have characters compatible with ISO8859-15 for western European characters. It may have the Euro symbol and the accents you mentioned. See:
https://en.wikipedia.org/wiki/ISO/IEC_8859-15
May be you can try another character that is in Arial but not in the ISO8859-15 (the Wiki page above mentions what is in the ISO8859-15) to see if it works.
To confirm, would you mind to clarify if you are using Linux, and which ChartDirector version you are using? Please kindly check the ChartDirector "fonts" subdirectory to see if there are Liberation or Arial fonts (the "arialbd.ttf" and "arial.ttf"). If there is no Arial fonts, you can legally download it free or charge and use it on your own server subject to Microsoft terms:
http://www.advsofteng.com/doc/cdphp.htm#fontspec.htm
https://www.microsoft.com/typography/faq/faq8.htm
https://sourceforge.net/projects/corefonts/files/
Regards
Peter Kwan |
Re: Delta symbol |
Posted by ADQA on Apr-04-2017 22:32 |
|
Hello Peter,
I attach you a screenshot of deltabar.php
Referring to your last post, I am using the ChartDirector version 5.1. Do you think that this could be the reason because delta symbol is not displaying? I tried to change the font to times.ttf, and I see changes on font, but Delta symbol doesn't appear.
Thank you for your help.
|
Re: Delta symbol |
Posted by Peter Kwan on Apr-05-2017 03:06 |
|
Hi ADQA,
Have you checked if you really have the "times.ttf" on the fonts subdirectory (assuming you are using Linux)? If you do not install it yourself, then it is likely your system does not have the font. The "times.ttf" is a copyrighted font and it should automatically appear unless you install it yourself.
(The Microsoft license allows a person to download and install it, but it does not allow redistribution. So no one can distribution the font to your system, but you can download it yourself.)
ChartDirector for Linux comes with several substitute fonts - one for sans serif styles (such as Arial), one for serif styles (such as Times New Roman), one for monospace style (such as Courier New), and one for cursory style. So if you change the font to "times.ttf", the text will change to serif style, even though there is no "times.ttf" in the system.
I have attached two images for the chart generated by ChartDirector 5.0 and 5.1 using real Arial font. You can see the text looks different from your chart. It means your chart is probably using a substitute font, not the Arial font.
Actually, the situation should be quite good now that nothing appear in the chart. It means the system can understand the encoding, and it is just the font does not contain the character so it cannot be displayed. If the system does not understand the encoding, it should display "garbage characters" instead of nothing. Once you download the real Arial font (or Arial Bold), it should work. Or you can upgrade to ChartDirector 6, which uses the "Liberation" font family for substitute fonts and they already contain the delta character.
Hope this can help.
Regards
Peter Kwan
|
Re: Delta symbol |
Posted by ADQA on Apr-05-2017 15:20 |
|
Hi,
I downloaded the font times.ttf and copied it in ChartDirector/lib/fonts directory (in a linux server). Then, I changed the font in the code:
$delta_symbol = 'Δ';
$c->yAxis->setTitle($delta_symbol, "times.ttf", 12);
Although I am not absolutely sure that the font is displaying is times.ttf.
Maybe I'll try with version 6 of Chartdirector.
Thanks for your help. |
Re: Delta symbol |
Posted by ADQA on Apr-05-2017 16:00 |
|
No way... Same thing with ChartDirector 6.0 and Liberation font |
Re: Delta symbol |
Posted by Peter Kwan on Apr-05-2017 19:14 |
|
Hi ADQA,
Note that for the fonts subdirectory, it should be under the directory that contains the ChartDirector shared object used by your PHP. In most recent PHP version, it is in the PHP extension directory. Usually people would extract the ChartDirector distribution in a certain directory and then copy everything in "ChartDirector/lib" to the PHP extension directory. When you add a new font, please make sure it is added to the ChartDirector in the PHP extension directory. which is the one actually used by PHP.
Also, in some systems, you would need to restart Apache if you changed any PHP extensions (such as updating ChartDirector).
If the above still cannot solve the problem, please try the code below, which will print out the ChartDirector version you are actually using, and also whether the arial.ttf font can be found. If the arial.ttf font or liberation font can be found, the delta character in the x-axis label of the "deltabar.php" sample code should be displayed. Please kindly let me know what is the result.
<?php
require_once("../lib/phpchartdir.php");
?>
<html><body>
ChartDirector Version : <?php echo (getVersion() & 0x7f000000) / 0x1000000 ?>
<br><br>
Font Loading Test : <br>
<?php echo str_replace("n", "<br><br>", libgTTFTest())?>
</body>
</html>
If you can provide a FTP guest account for me so that I can upload PHP scirpts to a directory in your web server for testing, I can try to create a chart with the delta character for you. You can email the guest account login information to me at pkwan@advsofteng.net
Regards
Peter Kwan |
Re: Delta symbol |
Posted by Peter Kwan on Apr-05-2017 19:16 |
|
Hi ADQA,
I forgot to mention that the code in my last message assumes the phpchartdir.php is at "../lib/phpchartdir.php". If it is in other directory, please modify the code to use the "phpchartdir.php" in that directory.
Regards
Peter Kwan |
Re: Delta symbol |
Posted by ADQA on Apr-05-2017 21:29 |
|
YES!! Finally!! I copied the font in extension directory as you tell me, and works now!
Thank you so much for your help, Peter. |
|