Class | Fusioncharts::Utf8ExampleController
In: | app/controllers/fusioncharts/utf8_example_controller.rb
Parent: | ApplicationController

     Contains actions to show the UTF-8 chart examples.

To use FusionCharts with UTF-8 characters, remember the following:

- dataURL method has to be used to get the xml.
- Rotated text cannot render UTF-8 characters. For example, UTF-8 characters in the rotated labels will not be rendered correctly.
- BOM has to present in the xml given as input to the chart.

Steps to ensure correct UTF-8 output:

- <meta http-equiv="content-type" content="text/html; charset=utf-8" /> has to be present in the <head> section of the page which contains UTF8 characters. Notice that we have included this in the "common.html.erb" layout, so that it is avialable to all pages.
- Put this, headers["Content-Type"] = "text/xml; charset=utf-8" in the action which is the XML provider. ( Here, pie_data_french or pie_data_japanese actions)
- If you are using a xml file for the data, then the file should be saved with UTF-8 encoding with UTF-8 BOM. It should have the xml declaration also: <?xml version="1.0" encoding="UTF-8" ?>
- If you are generating xml dynamically, then in the xml provider ( here, pie_data_japanese.html.erb and pie_data_french.html.erb ), use get_UTF8_BOM and assign the BOM to the xml as initial value. This function present in fusioncharts_helper library.
- After placing the BOM in the xml string, append the xml declaration: <?xml version=‘1.0’ encoding=‘UTF-8’?>. Finally, append the actual chart xml.
- For using data from database, the default character set of the database should be UTF-8. This can be done using the sql command:

ALTER DATABASE DEFAULT CHARACTER SET = utf8;

     The default charset of the table containing the UTF characters should be UTF-8. This can be done by adding "DEFAULT CHARSET=utf8;" at the end of the table definition.
     In the config/database.yml file the setting for encoding should be: encoding: UTF8
     For more details on UTF specific code, please see the view where the code resides.

### Methods

french_dbexample french_xmlfile_example japanese_dbexample japanese_xmlfile_example pie_data_french pie_data_japanese

### Public Instance methods

french_dbexample()

In this example, we show how to use UTF8 characters in FusionCharts by connecting to a database and using dataURL method. Here, the XML data for the chart is generated in pie_data_french function. The function itself does not contain any specific code to handle UTF8 characters. NOTE: It‘s necessary to encode the dataURL if you‘ve added parameters to it.

french_xmlfile_example()

This is an example showing French characters on the chart. Here, we‘ve used a pre-defined FrenchData.xml (contained in /Data/ folder) This action uses the dataURL method of FusionCharts. A view with the same name french_xmlfile_example.html.erb is present and it is this view, which gets rendered with the layout "common". render_chart function from the helper is invoked to render the chart. The function itself has no code, all the work is done in the view.

     For more details on UTF specific code, please see the view where the code resides.

japanese_dbexample()

In this example, we show how to use UTF8 characters in FusionCharts by connecting to a database and using dataURL method. Here, the XML data for the chart is generated in pie_data_japanese function. The function itself does not contain any specific code to handle UTF8 characters. NOTE: It‘s necessary to encode the dataURL if you‘ve added parameters to it.

japanese_xmlfile_example()

This is an example showing Japanese characters on the chart. Here, we‘ve used a pre-defined JapaneseData.xml (contained in /Data/ folder) This action uses the dataURL method of FusionCharts. A view with the same name japanese_xmlfile_example.html.erb is present and it is this view, which gets rendered with the layout "common". render_chart function from the helper is invoked to render the chart. The function itself has no code, all the work is done in the view.

pie_data_french()

Generates the xml with each factory‘s name and total output quantity. Factory name in french is obtained from FrenchFactoryMaster. Content-type for its view is set to text/xml and char-set to UTF-8.

pie_data_japanese()

Generates the xml with each factory‘s name and total output quantity. Factory name in japanese is obtained from JapaneseFactoryMaster. Content-type for its view is set to text/xml and char-set to UTF-8.

[Validate]