Chinese character garbled characters in images produced by jfreechart

Source: Internet
Author: User

Some time ago, I made several statistical charts as needed by the project, but I encountered some garbled code problems because I had not done it before. It took a long time to solve the problem. I would like to share it with you.

The possible reason for garbled Chinese Characters in images produced by jfreechart is as follows:

1. For details about servlet garbled characters, see the previous post.

Http://www.cn-java.com/www1/index.php? Uid-565002-action-viewspace-itemid-10577

Or

Http://blog.csdn.net/zhaotao_king/archive/2008/12/24/3596060.aspx

2. Some text settings in the process of creating an image are as follows:

The following reasons may be caused by garbled Chinese characters such as column charts and graphs (returned by the database or written directly in the method:
/*
*
*
* Solve the problem of jfreechart Chinese display

Several variables in the following code: The Chart plot domainaxis raxis object is as follows:

Jfreechart chart;

Categoryplot plot = chart. getcategoryplot ();

Categoryaxis domainaxis = plot. getdomainaxis ();

Valueaxis raxis = plot. getrangeaxis ();
*
*
**/
 
/* ---------- Set to eliminate the font's sawtooth rendering (solve Chinese problems )--------------*/
Chart. getrenderinghints (). Put (renderinghints. key_text_antialiasing,
Renderinghints. value_text_antialias_off );
/* ---------- Set the title Font --------------------------*/
Texttitle = chart. gettitle ();
Texttitle. setfont (new font ("", Font. Plain, 20 ));
/* ------ Set the text -----------*/
Domainaxis. setticklabelfont (new font ("Sans-serif", Font. Plain, 11 ));
/* ------ Set the title Text of the X axis ------------*/
Domainaxis. setlabelfont (new font ("", Font. Plain, 12 ));
/* ------ Set the text -----------*/
Raxis. setticklabelfont (new font ("Sans-serif", Font. Plain, 12 ));
/* ------ Set the title Text of the Y axis ------------*/
Raxis. setlabelfont (new font ("", Font. Plain, 12 ));

Chart. getlegend (). setitemfont (new font ("", Font. Plain, 12);/* ------ this code solves the problem of Chinese Character garbled characters at the bottom -----------*/

 
/* --------- Set the font displayed on the column body ---------*/
Renderer. setitemlabelgenerator (New labelgenerator (0.0 ));
Renderer. setitemlabelfont (new font ("", Font. Plain, 12 ));
Renderer. setitemlabelsvisible (true );

It took me a long time to solve the garbled code problem because of 2nd reasons ~~

To prevent others from encountering the same problem, share it with me ~~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.