Sign in to follow this  
johnshih

Cannot display Chinese Character properly

Recommended Posts

Hi,

I shall be happy if anyone can help me resolve below wired character problem. Below is my javascript, xml and screenshot.

javascript:

<script language="JavaScript">

 var myChart = new FusionCharts("../swf/Pyramid.swf", "myChartId", "220", "150", "0", "1");

 myChart.setDataURL("<%=request.getContextPath()%>/servlet/MapChartServlet?chart=1&deptid=");

 myChart.render("div_chart");

</script>

xml: (xml is generated and returned from my servlet) 

<chart bgColor='FFFFFF' bgAlpha='100' caption='???????:?????'  is2D='1' isSliced='1' showPlotBorder='1' plotBorderThickness='1' plotBorderAlpha='100' plotBorderColor='FFFFFF'  numberPrefix=''  enableSmartLabels='1'  ><set label='OFFLINE'  value='7' /><styles><definition><style type='font' name='captionFont' size='10' /><style type='shadow' name='myShadow' /><style type='font' name='TOOLTIP' size='8' /></definition><application><apply toObject='CAPTION' styles='captionFont' /><apply toObject='DATAPLOT' styles='myShadow' /><apply toObject='TOOLTIP' styles='tooltipFont' /></application></styles></chart>

screenshot

2d47ebe9-d9f9-4509-8239-0704.gif

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Could you please try using the following code?

 

 

 

.......

 

.......

 

..........

 

OutputStream outs = response.getOutputStream();

 

 

 

outs.write(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF});

 

 

 

outs.flush();

 

 

 

Writer writer = new OutputStreamWriter(outs);

 

 

 

writer.append(XML string); // Put here your variable name that stores the XML.

 

 

 

writer.flush();

Share this post


Link to post
Share on other sites

Hi,

It does not work after put your code to my servler. Below is error shown.

Info: Chart loaded and initialized.

Initial Width: 220

Initial Height: 150

Scale Mode: noScale

Debug Mode: Yes

Application Message Language: EN

Version: 3.0.2

Chart Type: Pyramid Chart

Chart Objects:

BACKGROUND

CANVAS

CAPTION

SUBCAPTION

DATALABELS

DATAPLOT

TOOLTIP

INFO: Chart registered with external script. DOM Id of chart is myChartId

INFO: XML Data provided using dataURL method.

dataURL provided: /dwfmgz/servlet/MapChartServlet?chart=1

dataURL provided: /dwfmgz/servlet/MapChartServlet?chart=1

INFO: XML Data provided using dataURL method.

ERROR: Invalid XML encountered. An XML element is malformed. Click the above "dataURL Invoked" link to see the XML in browser.

Share this post


Link to post
Share on other sites

Hi Rahul,

Here is my servlet code. Now it can display the chart, but show '??' for chinese character in both chart label and caption.

  chartString = createXmlChart(req, res);

res.setContentType("text/html; charset=UTF-8");

res.setHeader("Cache-Control", "no-store");

res.setHeader("Pragma", "no-cache");

 

OutputStream outs = res.getOutputStream();

outs.write(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF});

outs.flush();

Writer writer = new OutputStreamWriter(outs);

writer.append(chartString);

writer.flush();

writer.close();

where createXmlChart(req, res) will create xml chart string like

- <chart bgColor="FFFFFF" bgAlpha="100" caption="????????" is2D="1" isSliced="1" showPlotBorder="1" plotBorderThickness="1" plotBorderAlpha="100" plotBorderColor="FFFFFF" numberPrefix="" enableSmartLabels="1">
  <set label="??" value="14" />
  <set label="??" value="14" />
  <set label="??" value="9" />
- <styles>
- <definition>
  <style type="font" name="captionFont" size="10" />
  <style type="shadow" name="myShadow" />
  </definition>
- <application>
  <apply toObject="CAPTION" styles="captionFont" />
  <apply toObject="DATAPLOT" styles="myShadow" />
  </application>
  </styles>
  </chart>
Edited by Guest

Share this post


Link to post
Share on other sites

thanks Rahul! It works now after add 'UTF-8' to the outstreamwriter.

Writer writer = new OutputStreamWriter(outs, "UTF-8");

Edited by Guest

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this