FusionCharts for Flex > Special Cases > Multilingual Characters in Charts

Multilingual Character-Sets

FusionCharts allows you to display multi-lingual (UTF-8) characters on charts. The UTF-8 characters that are to be displayed must be encoded in the chart’s XML file. A FusionCharts object is essentially a Flash component and Flash offers no restriction on use of UTF-8 characters. However, it is essential that a byte-order mark be present in the UTF-8 encoding. So, to display UTF-8 characters in your chart, you need to stamp the UTF-8 encoded XML file with a byte-order mark.

 

As of now FusionCharts supports only left-to-right languages, as It doesn't have native support for right-to-left languages like Hebrew and Arabic. So, if you want to display Hebrew characters on charts, you'll have to programmatically change the text sequence before providing data to the chart.

WARNING

Please do not specify the encoding of your XML file in the XML header region as this does not add the Byte Order Mark.

<?xml version="1.0" encoding="UTF-8"?>

UTF-8 may be the default encoding for XML files, but the encoding needs to be specified when saving the file. Also, you have to make sure that the application, which saves the file applies the BOM mark.

 

If the XML file is not encoded in UTF-8 format while saving, the characters will be displayed as gibberish.

Standard Gibberish

Implementation

The Adobe Flex platform automatically handles data sources with Unicode characters. However, if an external XML file is used as datasource, it must be encoded with a byte-order mark (BOM). The UTF-8 representation of BOM is the byte sequence EF BB BF (Hex-Decimal Notation), which appears as the ISO-8850-1 characters  in most text-editors. Depending on the method of XML generation that you have used, you can follow any one of the various method of BOM stamping that has been discussed below.

Implementation with Static Flex Data Sources

This method is applicable when inline static Flex data sources such as String, Array, XML, or Model are used. The Unicode characters can be directly typed using a multi-lingual interface. They can also be specified with the help of \u escape sequence and the appropriate UTF Hex-Code.


// Chart declared using Array data type

private var chartParams:ArrayCollection=new ArrayCollection([
{caption: "藤原とふショプ \u00A9"},
.....
]);

// A Japanese caption, followed by copyright sign

Implementation with Static XML Generation

You can manually insert a BOM mark for those XML files, which remain static once they have been generated. This method may be implemented if data is retrieved from a file with the help of the FCDataURL attribute. All you have to do is ensure the file containing the XML data also contains a BOM mark. In case the BOM mark is not present, specify it manually by following these steps::

  1. Open the file in question, in a text-editor that supports UTF-8 encoding with BOM stamp (Example – Windows Notepad).
  2. Open the save dialog box and specify file name, file type, encoding, and BOM mark (if the option is available).
  3. Save the file.

Implementation with Dynamic XML Generation

For XML files that are generated by other applications and are outside the scope of manual manipulation, you need to control the process of XML generation – in order to incorporate the BOM mark. This method may be implemented if data is retrieved from a file using the FCDataURL attribute. Following solutions have been provided to help you incorporate BOM mark in XML files generated using various server-side scripts.

Implementation with Classic ASP generated XML

Insert the following code block at the beginning of page generation before outputting any data.

Response.AddHeader "Content-Type", "text/xml;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
Response.BinaryWrite(chrb(239))
Response.BinaryWrite(chrb(187))
Response.BinaryWrite(chrb(191))

Implementation with ASP.NET C# generated XML

Insert the following code block at the beginning of the page generation before you output the XML.

Response.ContentType = "text/xml; characterset=utf-8";
Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF });

Implementation with ASP.Net VB generated XML

Insert the following code block at the beginning of page generation. The output of the XML should follow this.

Response.ContentType = "text/xml"
Dim UTFHeader() As Byte = {&HEF, &HBB, &HBF}
Response.BinaryWrite(UTFHeader)

Implementation with PHP generated XML

Insert the following code block at the beginning of page generation before outputting XML data.

header('Content-type: text/xml');
echo pack("C3",0xef,0xbb,0xbf);

Implementation with Cold Fusion Markup generated XML

Insert the following code block at the beginning of page generation. Output the XML after this.

context = getPageContext();
response = context.getResponse().getResponse();
out = response.getOutputStream();
out.write(239);
out.write(187);
out.write(191);

For outputting data, you must convert the string to UTF-8 format. Using the getBytes("UTF-8") method for strings.

Implementation with JSP generated XML

Place the following code block at the beginning of page generation. Output any data after this block.

response.setContentType("text/xml; charset=UTF-8");
OutputStream outs = response.getOutputStream();
outs.write(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF});
outs.flush();


Implementation with Dynamic Flex Data Sources

While using data sources that are dynamically generated by other applications, you do not need to specify a BOM mark. This is because; the data passed, will be converted to a Flex data source before being transferred to the FusionCharts object. In this process the data is automatically formatted and no explicit declaration is necessary.