ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  problem with Japanese characters
Posted by Girish on Sep-29-2004 12:29
Hi
I'm generating bar charts and pie charts using Chart Director, based on the inputs taken from a struts jsp page. And those charts are saved into .png files.  It works fine with simple alphanumeric values. But I'm not able to generate charts when the inputs are of Japanese characters. I'm using the jsp page with charset="UTF-8" and pageEncoding="UTF-8"  as well as filters(Apache's SetCharacterEncodingFilter) to set character encoding to UTF-8. I'm able to print the Japanese characters that are entered from jsp into the console.
Please help me in this regard.

  Re: problem with Japanese characters
Posted by Peter Kwan on Sep-30-2004 05:28
Attachments:
Hi Girish,

There are two things you need to check.

1. Make sure the server understands your encodings.

If you can print the Japanese characters, it may only mean that your console can understand what the browser enters. (Is your console a browser, or a display device on the client side, or is it a monitor connected directly to the server?) The server may not understand what the browser enters at all.

From my understanding, no matter what encoding you choose (eg. using pageEncoding directive), the server always uses ISO-8859-1 encoding when interpretating user input. (I am not sure if your Apache SetCharacterEncodingFilter will modify this, but I think it is better just to remove it to avoid confusion.)

Since the browser actually uses UTF8 for input (I assume your pageEncoding works), the standard method is to ask the server to re-interpreted it using UTF8. The code is:

//get query parameter (user input)
String x = (String)request.getParameter("xxx");

//re-interpret as UTF8, assuming the pageEncoding is using UTF8
x = new String(x.getBytes("8859_1"), "utf-8");

One way to ensure the web server interprets the characters correctly is to display the Unicode equivalent of the character:

//prints out the unicode of the first character
c.addTitle("" + ((int)x.charAt(0)));

Then you can look up the "Windows/Accessories/System Tools/Character Map" to check if it is the character you expect. (If it is a Japanese character, the Unicode equivalent should be a number much bigger than 256.) If the Java server really understands the user's input, it should be able to return its unicode equivalent correctly.


2. If you are sure the web server understands the character correctly, then you need to ensure it uses the correct font. For example, if you use the Arial font, then the Japanese characters cannot be displayed, because Arial font does not have Japanese support. (In my computer, I find the "MingLiu" font that supports Japanese. You will need to use a Japanese font that your computer have.)


I have attached a sample code to demonstrate how to process user input in Java. The first line of the code contains "pageEncoding='UTF-8'", which tells the browser to send user input as UTF8. Then the Java code uses the method (1) above to re-interpret the user input as UTF8. Then I use the MingLiU font to display the user input in the chart title. No other server side configuration is necessary.

If you try to run the code, please change the "MingLiU" font to a font that you have.

Regards
Peter Kwan
simplebar.jsp
<%@page import="ChartDirector.*" pageEncoding="UTF-8" %>
<%
//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};

//The labels for the bar chart
String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};

//Create a XYChart object of size 250 x 250 pixels
XYChart c = new XYChart(250, 250);

//get the parameter and convert to UTF8
String x = (String)request.getParameter("xxx");
if (x == null)
	x = "";
else
	x = new String(x.getBytes("8859_1"), "utf-8");

c.addTitle(x, "MingLiU", 14);

//Set the plotarea at (30, 30) and of size 200 x 190 pixels
c.setPlotArea(30, 30, 200, 190);

//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
String chart1URL = c.makeSession(request, "chart1");

String fullpath= application.getRealPath("/jspdemo/tmpcharts");
String filename = c.makeTmpFile(fullpath);

//include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: US${value}K'");
%>
<html>
<body topmargin=0 leftmargin=5 rightmargin=0>
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
    Simple Bar Chart
</div>
<hr color="#000080">
<form action="simplebar.jsp">
<input name="xxx">
<input type="submit">
</form>
<br>
<!--img src="getchart.jsp?<%=chart1URL%>" usemap="#map1" border="0"-->
<img src="<%=request.getContextPath() + "/jspdemo/tmpcharts/" + filename%>" usemap="#map1" border="0">

<map name="map1"><%=imageMap1%></map>
</body>
</html>

  Thanks
Posted by Girish on Sep-30-2004 11:36
Thank you Mr. peter kwan for your kind response.
Your reply was help ful to me and I was successful in getting generated the charts with Japanese characters.
The problem was with fonts, I was trying with "Times New Roman", I just changed it to "kochi gothic" which was readily available in my system.
Thanks and regards
girish

  Re: problem with Japanese characters
Posted by soma on Oct-12-2007 12:44
Attachments:
Now I'm developing application with PHP on Windows Xp Japanese environment.
I have problem of Japanese.
By saving a file by UTF-8, I can use Japanese Chart Title.
But As for yAxis Lables, I cannot use Japanese. (Cannot see the Japanese Labels)

If you have any solution let me know.
gantt2.php
<?php
require_once("../../lib/phpchartdir.php");

# data for the gantt chart, representing the start date, end date and names for
# various activities
$startDate = array(chartTime(2004, 8, 16.5), chartTime(2004, 8, 30.2), chartTime(2004, 9,
    13.5), chartTime(2004, 9, 20.23), chartTime(2004, 9, 27.343), chartTime(2004, 10, 4.3),
    chartTime(2004, 10, 25.5), chartTime(2004, 11, 1.5), chartTime(2004, 11, 8.5));
$endDate = array(chartTime(2004, 8, 30), chartTime(2004, 9, 13), chartTime(2004, 9,
    27), chartTime(2004, 10, 4), chartTime(2004, 10, 11), chartTime(2004, 11, 8),
    chartTime(2004, 11, 8), chartTime(2004, 11, 22), chartTime(2004, 11, 22));
$labels = array("(日本語は表示不可)", "ABCD", "EFGH",
    "Jan", "Feb", "ひらがな", "カタカナ",
    "漢字", "問題");

# Create a XYChart object of size 620 x 280 pixels. Set background color to light
# blue (ccccff), with 1 pixel 3D border effect.
# The size of Frame is fixed
$c = new XYChart(840, 480, 0xccccff, 0x000000, 2);
# $c = new XYChart(620, 280, 0xEEEEEE, 0x000000, 2);

# Add a title to the chart using 15 points Times Bold Itatic font, with white
# (ffffff) text on a deep blue (000080) background
#$textBoxObj = $c->addTitle("Simple Gantt Chart Demo(日本語変換)", "timesbi.ttf", 15, 0xffffff);
$textBoxObj = $c->addTitle("Sample Gantt Chart Demo(日本語変換)", "msmincho.ttc", 10, 0xffffff);
$textBoxObj->setBackground(0x000080);

# Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use alternative
# white/grey background. Enable both horizontal and vertical grids by setting their
# colors to grey (c0c0c0). Set vertical major grid (represents month boundaries) 2
# pixels in width
$plotAreaObj = $c->setPlotArea(130, 45, 640, 400, 0xffffff, 0xeeeeee, LineColor, 0xc0c0c0, 0xc0c0c0);
$plotAreaObj->setGridWidth(2, 1, 1, 1);

# swap the x and y axes to create a horziontal box-whisker chart
$c->swapXY();

# Set the y-axis scale to be date scale from Aug 16, 2004 to Nov 22, 2004, with ticks
# every 7 days (1 week)
# $c->yAxis->setDateScale(chartTime(2004, 8, 16), chartTime(2004, 11, 22), 86400 );
$c->yAxis->setDateScale(chartTime(2004, 8, 16), chartTime(2004, 9, 22), 86400 );

# Set multi-style axis label formatting. Month labels are in Arial Bold font in "mmm
# d" format. Weekly labels just show the day of month and use minor tick (by using
# '-' as first character of format string).
$c->yAxis->setMultiFormat(StartOfMonthFilter(), "<*font=arialbd.ttf*>{value|m/d}", StartOfDayFilter(), "-{value|d}");
# $c->yAxis->setMultiFormat(StartOfMonthFilter(), "<*font=msmincho.ttc*>{value|m/d}", StartOfDayFilter(), "-{value|m/d}");

# Set the y-axis to shown on the top (right + swapXY = top)
$c->setYAxisOnRight();

# Set the labels on the x axis
$c->xAxis->setLabels($labels);

# Reverse the x-axis scale so that it points downwards.
$c->xAxis->setReverse();

# Set the horizontal ticks and grid lines to be between the bars
$c->xAxis->setTickOffset(0.5);

# Add a green (33ff33) box-whisker layer showing the box only.
$c->addBoxWhiskerLayer($startDate, $endDate, null, null, null, 0x00cc00,
    SameAsMainColor, SameAsMainColor);
$c->addBoxWhiskerLayer($startDate, $endDate, null, null, null, 0x00cc00,
    SameAsMainColor, SameAsMainColor);

# output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

  Re: problem with Japanese characters
Posted by soma on Oct-12-2007 15:31
I could find the Japanese and ASP problem, and
by adding following line to the php file, I have soloved the problem.
$c->setDefaultFonts("MSGOTHIC.TTC", "MSGOTHIC.TTC");

Thank you .