Unicode support for chart tile and point annotations. Here is a small script to show the problem.

75 views
Skip to first unread message

Mike Duffy

unread,
Dec 21, 2009, 1:50:34 PM12/21/09
to Google Chart API
<html>
<head>
<title>Test</title>
</head>
<body>
<script type="text/javascript">

// I have not tested it, but I presume that chart legends will be
similarly affected.

var chart = ''; // Will hold entire chart definition to send to
Google.

var s = new Array(); var i=0; // Array with text samples to test.

// Populate the text array with different methods to define one
characater.
s[i++] = 'A'; // - Unicode A via simple quoting.

s[i++] = '&#x0042;'; // - Unicode B via html escape
s[i++] = '\u0043'; // - Unicode C via javascript unicode
escape

s[i++] = '&#x2646;'; // - Unicode Neptune (trident) via html
escape
s[i++] = '\u2646'; // - Unicode Neptune (trident) via
javascript unicode escape
// Neither method works okay, but at
least you still get a chart.
// (converted to rectangles (FF) or
"?" (IE7).

s[i++] = '&alpha;'; // - HTML entity that sort of works. It
gets converted to "a".

s[i++] = '&#x0100;'; // - A with horizontal bar accent. FF okay,
IE removes the accent.


// The following cause errors :
// s[i++] = 'Á'; // These work okay in FF, but with IE the
title and annotation series
// s[i++] = '&#x00c1;'; // are completely missing. Maybe the
"GET" is not properly escaped.
// Note: 00c1 is the unicode sequence for
"Á".
// s[i++] = '&euro;'; // Euro currency. Same error as above. In
fact, IE fails with all
// HTML entities I tried above 00A0.

if(i>9) {alert("Too many samples, set to 9!"); i=9;};

// Define chart
chart += '?cht=s';
chart += '&chs=300x300';

// Put test chars into title, separate them with "_" (underscore).
chart += '&chtt=' + s[0]; for (j=1; j<=i-1; j++) {chart += '_' + s
[j];};

// Data points.
chart += '&chd=t:10,20,30,40,50,60,70,80,90|50,50,50,50,50,50,50,50,50|
100,100,100,100,100,100,100,100,100';

// Axes legend.
chart += '&chxt=x,y&chxl=0:|0|20|30|40|50|60|70|80|90|10|1:|0|25|50|75|
100';

// Position digits 1 to 9 at 90% height.
chart += '&chm=@t1,000000,0,.1:.9,20,1';
chart += '|@t2,000000,0,.2:.9,20,1';
chart += '|@t3,000000,0,.3:.9,20,1';
chart += '|@t4,000000,0,.4:.9,20,1';
chart += '|@t5,000000,0,.5:.9,20,1';
chart += '|@t6,000000,0,.6:.9,20,1';
chart += '|@t7,000000,0,.7:.9,20,1';
chart += '|@t8,000000,0,.8:.9,20,1';
chart += '|@t9,000000,0,.9:.9,20,1';

// Add test symbols as markers on chart at 70% height.
chart += '|@t'+s[0]+',000000,0,.1:.7,20,1';
for (j=1; j<=i-1; j++) {k = j+1; chart += '|@t' + s[j] + ',000000,0,.'
+ k + ':.7,20,1';};

// Define image tag including the chart definition.
var image_tag = '<img src="http://chart.apis.google.com/chart' + chart
+ '" alt="">';

// Write it to document.
document.write (image_tag); //alert(chart);

// For debug purposes, display the coded url. Break it into readable
segments.
document.write ('<p>' + chart.replace(/\&c/g, "<br><br>&c").replace(/
\@/g, "<br>@") + '</p>');

</script>
</body></html>

KeithB

unread,
Dec 29, 2009, 10:49:58 AM12/29/09
to Google Chart API
The Chart API expects URL-encoded UTF-8 characters. See the examples
at http://groups.google.com/group/google-chart-api/web/chart-types-for-map-pins

Here's a site that I've used in the past to obtain utf-8 hex values:
http://www.utf8-chartable.de/unicode-utf8-table.pl?number=1024

Good luck,
Keith

Mike Duffy

unread,
Dec 30, 2009, 8:39:40 AM12/30/09
to Google Chart API
Thanks! I will post to the "Call For Charts" thread when my planet &
star chart app has been updated.

Mike Duffy

unread,
Dec 31, 2009, 12:07:35 PM12/31/09
to Google Chart API
I spoke too soon. The special chart type for the maps apparently
accepts URI -encoded unicode chars, but NOT the regular chart API. If
we try, for example, to use the value %e2%99%86 (Neptune) as the
symbol to be plotted, the entire annotation list is not displayed at
all. Only the "main" data set shows up. The chart API does accept
arbitrary HTML entities, such as &#1234; or &#x89AB; without
"breaking", but most of the characters are not displayed properly.
Only particular character sets within the Unicode domain are treated
properly. And there does seem to be some specific substitutions going
on, such as "a" for lower case alpha, stripping of accents etc. as
detailed in my example above.

On Dec 30, 8:39 am, Mike Duffy <mdu...@videotron.ca> wrote:
> Thanks!

Reply all
Reply to author
Forward
0 new messages