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 ~~~~