Jfreechart Chinese garbled solution Summary

Source: Internet
Author: User

Various factors on the jfreechart component operating platform may cause Chinese garbled characters. Next I will summarize the solutions for jfreechart Chinese garbled characters.

Due to the JFreeChart component version, operating platform, JDK settings, and other factors, Chinese characters may be garbled when using the JFreeChart component.

When this problem occurs, you can set the font of the text to solve the problem.

The following provides a solution that I personally think is better:

The Code is as follows: Copy code

// Create a topic Style
StandardChartTheme standardChartTheme = new StandardChartTheme ("CN ");
// Set the title Font
StandardChartTheme. setExtraLargeFont (new Font ("", Font. BOLD, 20 ));
// Set the font of the legend
StandardChartTheme. setRegularFont (new Font ("", Font. PLAIN, 15 ));
// Set the axial font
StandardChartTheme. setLargeFont (new Font ("", Font. PLAIN, 15 ));
// Apply the topic Style
ChartFactory. setChartTheme (standardChartTheme );

In this way, Chinese garbled characters in most charts can be solved.

Add a Chinese garbled Function

The Code is as follows: Copy code

CategoryDataset dataset = getDataSet2 ();
JFreeChart chart = ChartFactory. createBarChart3D ("", // chart title
"", // Display label of the Directory axis
"", // Display label of the numeric axis
Dataset, // dataset
PlotOrientation. VERTICAL, // chart direction: horizontal and VERTICAL
True, // whether to display the legend (for a simple bar chart, it must be false)
False, // whether to generate a tool
False // whether to generate a URL link
);
// Set the font
ConfigFont (chart );

// Font configuration method (solving Chinese problems)
Private static void configFont (JFreeChart chart ){
// Configure the font
Font xfont = new Font ("", Font. PLAIN, 12); // X axis
Font yfont = new Font ("", Font. PLAIN, 12); // y axis
Font kfont = new Font ("", Font. PLAIN, 12); // bottom
Font titleFont = new Font ("", Font. BOLD, 25); // picture title
CategoryPlot plot = chart. getCategoryPlot (); // Drawing Structure object of the image

// Image title
Chart. setTitle (new TextTitle (chart. getTitle (). getText (), titleFont ));

// Bottom
Chart. getLegend (). setItemFont (kfont );

// X axis
CategoryAxis domainAxis = plot. getDomainAxis ();
DomainAxis. setLabelFont (xfont); // axis title
DomainAxis. setTickLabelFont (xfont); // axis Value
DomainAxis. setTickLabelPaint (Color. BLUE); // font Color
DomainAxis. setCategoryLabelPositions (CategoryLabelPositions. UP_45); // oblique label display on the horizontal axis

// Y axis
ValueAxis rangeAxis = plot. getRangeAxis ();
RangeAxis. setLabelFont (yfont );
RangeAxis. setLabelPaint (Color. BLUE); // font Color
RangeAxis. setTickLabelFont (yfont );

}

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.