JFreeChart中文乱码解决方案(方法汇总)

由于JFreeChart组件的版本、操作平台、JDK的设置等因素,在使用JFreeChart组件时可能会出现中文乱码的现象。遇到此问题时,可通过设置文字的字体来解决问题。在此提供以下两种解决此问题的方法。
一、设置主题的样式(强烈推荐)
  在制图前,创建主题样式并制定样式中的字体,通过ChartFactory的setChartTheme()方法设置主题样式。

Java代码 复制代码   收藏代码
  1. //创建主题样式   
  2.    StandardChartTheme standardChartTheme= new  StandardChartTheme( "CN" );   
  3.     //设置标题字体   
  4.    standardChartTheme.setExtraLargeFont( new  Font( "隶书" ,Font.BOLD, 20 ));   
  5.     //设置图例的字体   
  6.    standardChartTheme.setRegularFont( new  Font( "宋书" ,Font.PLAIN, 15 ));   
  7.     //设置轴向的字体   
  8.    standardChartTheme.setLargeFont( new  Font( "宋书" ,Font.PLAIN, 15 ));   
  9.     //应用主题样式   
  10.    ChartFactory.setChartTheme(standardChartTheme);  
    //创建主题样式
       StandardChartTheme standardChartTheme=new StandardChartTheme("CN");
       //设置标题字体
       standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,20));
       //设置图例的字体
       standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,15));
       //设置轴向的字体
       standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,15));
       //应用主题样式
       ChartFactory.setChartTheme(standardChartTheme);


  例如:

Java代码 复制代码   收藏代码
  1. package  com.zzs.jfreechart.demo;   
  2.   
  3. import  java.awt.Font;   
  4.   
  5. import  org.jfree.chart.ChartFactory;   
  6. import  org.jfree.chart.ChartFrame;   
  7. import  org.jfree.chart.JFreeChart;   
  8. import  org.jfree.chart.StandardChartTheme;   
  9. import  org.jfree.chart.plot.PlotOrientation;   
  10. import  org.jfree.chart.title.LegendTitle;   
  11. import  org.jfree.chart.title.TextTitle;   
  12. import  org.jfree.data.category.DefaultCategoryDataset;   
  13.   
  14. public   class  JfreeChartTest {   
  15.         
  16.      public   static   void  main(String[] args) {   
  17.     
  18. //     创建类别图(Category)数据对象   
  19.     
  20.        DefaultCategoryDataset dataset =  new  DefaultCategoryDataset();   
  21.     
  22.        dataset.addValue( 100 ,  "北京" ,  "苹果" );   
  23.     
  24.        dataset.addValue( 100 ,  "上海" ,  "苹果" );   
  25.     
  26.        dataset.addValue( 100 ,  "广州" ,  "苹果" );   
  27.     
  28.        dataset.addValue( 200 ,  "北京" ,  "梨子" );   
  29.     
  30.        dataset.addValue( 200 ,  "上海" ,  "梨子" );   
  31.     
  32.        dataset.addValue( 200 ,  "广州" ,  "梨子" );   
  33.     
  34.        dataset.addValue( 300 ,  "北京" ,  "葡萄" );   
  35.     
  36.        dataset.addValue( 300 ,  "上海" ,  "葡萄" );   
  37.     
  38.        dataset.addValue( 300 ,  "广州" ,  "葡萄" );   
  39.     
  40.        dataset.addValue( 400 ,  "北京" ,  "香蕉" );   
  41.     
  42.        dataset.addValue( 400 ,  "上海" ,  "香蕉" );   
  43.     
  44.        dataset.addValue( 400 ,  "广州" ,  "香蕉" );   
  45.     
  46.        dataset.addValue( 500 ,  "北京" ,  "荔枝" );   
  47.     
  48.        dataset.addValue( 500 ,  "上海" ,  "荔枝" );   
  49.     
  50.        dataset.addValue( 500 ,  "广州" ,  "荔枝" );   
  51.         //创建主题样式   
  52.        StandardChartTheme standardChartTheme= new  StandardChartTheme( "CN" );   
  53.         //设置标题字体   
  54.        standardChartTheme.setExtraLargeFont( new  Font( "隶书" ,Font.BOLD, 20 ));   
  55.         //设置图例的字体   
  56.        standardChartTheme.setRegularFont( new  Font( "宋书" ,Font.PLAIN, 15 ));   
  57.         //设置轴向的字体   
  58.        standardChartTheme.setLargeFont( new  Font( "宋书" ,Font.PLAIN, 15 ));   
  59.         //应用主题样式   
  60.        ChartFactory.setChartTheme(standardChartTheme);   
  61.     
  62.         JFreeChart chart=ChartFactory.createBarChart3D( "水果产量图" ,  "水果" ,  "水果" , dataset, PlotOrientation.VERTICAL,  true ,  true ,  true );   
  63. //        TextTitle textTitle = chart.getTitle();   
  64. //      textTitle.setFont(new Font("宋体", Font.BOLD, 20));   
  65. //      LegendTitle legend = chart.getLegend();   
  66. //      if (legend != null) {   
  67. //          legend.setItemFont(new Font("宋体", Font.BOLD, 20));   
  68. //      }   
  69.        ChartFrame  frame= new  ChartFrame ( "水果产量图 " ,chart, true );   
  70.     
  71.        frame.pack();   
  72.     
  73.        frame.setVisible( true );   
  74.     
  75.     }   
  76.     
  77.   
  78. }  
package com.zzs.jfreechart.demo;

import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;

public class JfreeChartTest {
	 
    public static void main(String[] args) {
 
//     创建类别图(Category)数据对象
 
       DefaultCategoryDataset dataset = new DefaultCategoryDataset();
 
       dataset.addValue(100, "北京", "苹果");
 
       dataset.addValue(100, "上海", "苹果");
 
       dataset.addValue(100, "广州", "苹果");
 
       dataset.addValue(200, "北京", "梨子");
 
       dataset.addValue(200, "上海", "梨子");
 
       dataset.addValue(200, "广州", "梨子");
 
       dataset.addValue(300, "北京", "葡萄");
 
       dataset.addValue(300, "上海", "葡萄");
 
       dataset.addValue(300, "广州", "葡萄");
 
       dataset.addValue(400, "北京", "香蕉");
 
       dataset.addValue(400, "上海", "香蕉");
 
       dataset.addValue(400, "广州", "香蕉");
 
       dataset.addValue(500, "北京", "荔枝");
 
       dataset.addValue(500, "上海", "荔枝");
 
       dataset.addValue(500, "广州", "荔枝");
       //创建主题样式
       StandardChartTheme standardChartTheme=new StandardChartTheme("CN");
       //设置标题字体
       standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,20));
       //设置图例的字体
       standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,15));
       //设置轴向的字体
       standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,15));
       //应用主题样式
       ChartFactory.setChartTheme(standardChartTheme);
 
        JFreeChart chart=ChartFactory.createBarChart3D("水果产量图", "水果", "水果", dataset, PlotOrientation.VERTICAL, true, true, true);
//        TextTitle textTitle = chart.getTitle();
// 		textTitle.setFont(new Font("宋体", Font.BOLD, 20));
// 		LegendTitle legend = chart.getLegend();
// 		if (legend != null) {
// 			legend.setItemFont(new Font("宋体", Font.BOLD, 20));
// 		}
       ChartFrame  frame=new ChartFrame ("水果产量图 ",chart,true);
 
       frame.pack();
 
       frame.setVisible(true);
 
    }
 

}



二、制定乱码文字的字体  
 使用JFreeChart绘制图表的时候,如果使用默认的字体会导致图标中的汉字显示为乱码。解决方法如下:

JFreeChart是用户使用该库提供的各类图标的统一接口,JFreeChart主要由三个部分构成:title(标题),legend(图释),plot(图表主体)。三个部分设置字体的方法分别如下:

1.Title

TextTitle textTitle = freeChart.getTitle();  
textTitle.setFont(new Font("宋体",Font.BOLD,20)); 


2.Legent

LegendTitle legend = freeChart.getLegend();  
if (legend!=null) {  
   legend.setItemFont(new Font("宋体", Font.BOLD, 20));
} 


3.Plot



    对于不同类型的图表对应Plot的不同的实现类,设置字体的方法也不完全相同。

    对于使用CategoryPlot的图表(如柱状图):

CategoryPlot plot = (CategoryPlot)freeChart.getPlot();  
CategoryAxis domainAxis = plot.getDomainAxis();//(柱状图的x轴)  
domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴坐标上的字体  
domainAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴上的标题的字体    
ValueAxis valueAxis = plot.getRangeAxis();//(柱状图的y轴)  
valueAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的字体  
valueAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的标题的字体 
CategoryPlot plot = (CategoryPlot)freeChart.getPlot();
CategoryAxis domainAxis = plot.getDomainAxis();//(柱状图的x轴)
domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴坐标上的字体
domainAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴上的标题的字体
ValueAxis valueAxis = plot.getRangeAxis();//(柱状图的y轴)
valueAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的字体
valueAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的标题的字体


对于使用PiePlot的图标(如饼状图):


PiePlot plot = (PiePlot)freeChart.getPlot();  
plot.setLabelFont(new Font("宋体",Font.BOLD,15)); 



对于使用PiePlot的图标(如饼状图):


view plaincopy to clipboardprint?
PiePlot plot = (PiePlot)freeChart.getPlot();  
plot.setLabelFont(new Font("宋体",Font.BOLD,15)); 

下面一个实例:

Java代码 复制代码   收藏代码
  1. package  com.zzs.jfreechart.demo;   
  2.   
  3. import  java.awt.Font;   
  4.   
  5. import  javax.swing.JPanel;   
  6.   
  7. import  org.jfree.chart.ChartFactory;   
  8. import  org.jfree.chart.ChartPanel;   
  9. import  org.jfree.chart.JFreeChart;   
  10. import  org.jfree.chart.plot.PiePlot;   
  11. import  org.jfree.chart.title.LegendTitle;   
  12. import  org.jfree.chart.title.TextTitle;   
  13. import  org.jfree.data.general.DefaultPieDataset;   
  14. import  org.jfree.data.general.PieDataset;   
  15. import  org.jfree.ui.ApplicationFrame;   
  16.   
  17. public   class  JfreeChartOne  extends  ApplicationFrame {   
  18.   
  19.      private   static   final   long  serialVersionUID = 1L;   
  20.   
  21.      public  JfreeChartOne(String s)   
  22.   
  23.     {   
  24.   
  25.          super (s);   
  26.   
  27.         setContentPane(createJPanel());   
  28.   
  29.     }   
  30.   
  31.      public   static   void  main(String[] args) {   
  32.   
  33.         JfreeChartOne one =  new  JfreeChartOne( "CityInfoPort公司组织架构图" );   
  34.   
  35.         one.pack();   
  36.   
  37.         one.setVisible( true );   
  38.   
  39.     }   
  40.   
  41.      // 利用静态方法设定数据源(饼状图)   
  42.   
  43.      public   static  PieDataset createPieDataset() {   
  44.   
  45.         DefaultPieDataset defaultpiedataset =  new  DefaultPieDataset();   
  46.   
  47.         defaultpiedataset.setValue( "管理人员" ,  10 .02D);   
  48.   
  49.         defaultpiedataset.setValue( "市场人员" ,  20 .23D);   
  50.   
  51.         defaultpiedataset.setValue( "开发人员" ,  60 .02D);   
  52.   
  53.         defaultpiedataset.setValue( "OEM人员" ,  10 .02D);   
  54.   
  55.         defaultpiedataset.setValue( "其他人员" ,  5 .11D);   
  56.   
  57.          return  defaultpiedataset;   
  58.   
  59.     }   
  60.   
  61.      // 通过ChartFactory创建JFreeChart的实例   
  62.   
  63.      public   static  JFreeChart createJFreeChart(PieDataset p)   
  64.   
  65.     {   
  66.   
  67.         JFreeChart a = ChartFactory.createPieChart( "CityInfoPort公司组织架构图" , p,   
  68.                  true ,  true ,  true );   
  69.          // JFreeChart主要由三个部分构成:title(标题),legend(图释),plot(图表主体)。   
  70.          //三个部分设置字体的方法分别如下:   
  71.         TextTitle textTitle = a.getTitle();   
  72.         textTitle.setFont( new  Font( "宋体" , Font.BOLD,  20 ));   
  73.         LegendTitle legend = a.getLegend();   
  74.          if  (legend !=  null ) {   
  75.             legend.setItemFont( new  Font( "宋体" , Font.BOLD,  20 ));   
  76.         }   
  77.   
  78.         PiePlot pie = (PiePlot) a.getPlot();   
  79.   
  80.         pie.setLabelFont( new  Font( "宋体" , Font.BOLD,  12 ));   
  81.   
  82.         pie.setNoDataMessage( "No data available" );   
  83.   
  84.         pie.setCircular( true );   
  85.   
  86.         pie.setLabelGap( 0 .01D); // 间距   
  87.   
  88.          return  a;   
  89.   
  90.     }   
  91.   
  92.      public   static  JPanel createJPanel() {   
  93.   
  94.         JFreeChart jfreechart = createJFreeChart(createPieDataset());   
  95.   
  96.          return   new  ChartPanel(jfreechart);   
  97.   
  98.     }   
  99.   
  100. }  
package com.zzs.jfreechart.demo;

import java.awt.Font;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;

public class JfreeChartOne extends ApplicationFrame {

	private static final long serialVersionUID = 1L;

	public JfreeChartOne(String s)

	{

		super(s);

		setContentPane(createJPanel());

	}

	public static void main(String[] args) {

		JfreeChartOne one = new JfreeChartOne("CityInfoPort公司组织架构图");

		one.pack();

		one.setVisible(true);

	}

	// 利用静态方法设定数据源(饼状图)

	public static PieDataset createPieDataset() {

		DefaultPieDataset defaultpiedataset = new DefaultPieDataset();

		defaultpiedataset.setValue("管理人员", 10.02D);

		defaultpiedataset.setValue("市场人员", 20.23D);

		defaultpiedataset.setValue("开发人员", 60.02D);

		defaultpiedataset.setValue("OEM人员", 10.02D);

		defaultpiedataset.setValue("其他人员", 5.11D);

		return defaultpiedataset;

	}

	// 通过ChartFactory创建JFreeChart的实例

	public static JFreeChart createJFreeChart(PieDataset p)

	{

		JFreeChart a = ChartFactory.createPieChart("CityInfoPort公司组织架构图", p,
				true, true, true);
		// JFreeChart主要由三个部分构成:title(标题),legend(图释),plot(图表主体)。
		//三个部分设置字体的方法分别如下:
		TextTitle textTitle = a.getTitle();
		textTitle.setFont(new Font("宋体", Font.BOLD, 20));
		LegendTitle legend = a.getLegend();
		if (legend != null) {
			legend.setItemFont(new Font("宋体", Font.BOLD, 20));
		}

		PiePlot pie = (PiePlot) a.getPlot();

		pie.setLabelFont(new Font("宋体", Font.BOLD, 12));

		pie.setNoDataMessage("No data available");

		pie.setCircular(true);

		pie.setLabelGap(0.01D);// 间距

		return a;

	}

	public static JPanel createJPanel() {

		JFreeChart jfreechart = createJFreeChart(createPieDataset());

		return new ChartPanel(jfreechart);

	}

}


下面这个修改坐标轴:

Java代码 复制代码   收藏代码
  1. package  com.zzs.jfreechart.demo;   
  2.   
  3. import  java.awt.Color;   
  4. import  java.awt.Font;   
  5.   
  6. import  org.jfree.chart.ChartFactory;   
  7. import  org.jfree.chart.ChartFrame;   
  8. import  org.jfree.chart.JFreeChart;   
  9. import  org.jfree.chart.axis.CategoryAxis;   
  10. import  org.jfree.chart.axis.ValueAxis;   
  11. import  org.jfree.chart.plot.XYPlot;   
  12. import  org.jfree.chart.title.LegendTitle;   
  13. import  org.jfree.chart.title.TextTitle;   
  14. import  org.jfree.data.time.Month;   
  15. import  org.jfree.data.time.TimeSeries;   
  16. import  org.jfree.data.time.TimeSeriesCollection;   
  17. import  org.jfree.ui.RectangleInsets;   
  18.   
  19. public   class  ShiJianXuLieTu01 {   
  20.   
  21.      /**  
  22.      * @param args  
  23.      */   
  24.      public   static   void  main(String[] args) {   
  25.          // TODO Auto-generated method stub   
  26.          //时间序列图   
  27.             
  28.            TimeSeries timeseries =  new  TimeSeries( "L&G European Index Trust" ,Month. class );   
  29.         
  30.            timeseries.add( new  Month( 2 ,  2001 ),  181 .8D); //这里用的是Month.class,同样还有Day.class Year.class 等等   
  31.         
  32.            timeseries.add( new  Month( 3 ,  2001 ),  167 .3D);   
  33.         
  34.            timeseries.add( new  Month( 4 ,  2001 ),  153 .8D);   
  35.         
  36.            timeseries.add( new  Month( 5 ,  2001 ),  167 .6D);   
  37.         
  38.            timeseries.add( new  Month( 6 ,  2001 ),  158 .8D);   
  39.         
  40.            timeseries.add( new  Month( 7 ,  2001 ),  148 .3D);   
  41.         
  42.            timeseries.add( new  Month( 8 ,  2001 ),  153 .9D);   
  43.         
  44.            timeseries.add( new  Month( 9 ,  2001 ),  142 .7D);   
  45.         
  46.            timeseries.add( new  Month( 10 ,  2001 ),  123 .2D);   
  47.         
  48.            timeseries.add( new  Month( 11 ,  2001 ),  131 .8D);   
  49.         
  50.            timeseries.add( new  Month( 12 ,  2001 ),  139 .6D);   
  51.         
  52.            timeseries.add( new  Month( 1 ,  2002 ),  142 .9D);   
  53.         
  54.            timeseries.add( new  Month( 2 ,  2002 ),  138 .7D);   
  55.         
  56.            timeseries.add( new  Month( 3 ,  2002 ),  137 .3D);   
  57.         
  58.            timeseries.add( new  Month( 4 ,  2002 ),  143 .9D);   
  59.         
  60.            timeseries.add( new  Month( 5 ,  2002 ),  139 .8D);   
  61.         
  62.            timeseries.add( new  Month( 6 ,  2002 ), 137D);   
  63.         
  64.            timeseries.add( new  Month( 7 ,  2002 ),  132 .8D);   
  65.         
  66.         
  67.         
  68.            TimeSeries timeseries1 =  new  TimeSeries( "L&G UK Index Trust曾召帅" ,Month. class );   
  69.         
  70.            timeseries1.add( new  Month( 2 ,  2001 ),  129 .6D);   
  71.         
  72.            timeseries1.add( new  Month( 3 ,  2001 ),  123 .2D);   
  73.         
  74.            timeseries1.add( new  Month( 4 ,  2001 ),  117 .2D);   
  75.         
  76.            timeseries1.add( new  Month( 5 ,  2001 ),  124 .1D);   
  77.         
  78.            timeseries1.add( new  Month( 6 ,  2001 ),  122 .6D);   
  79.         
  80.            timeseries1.add( new  Month( 7 ,  2001 ),  119 .2D);   
  81.         
  82.            timeseries1.add( new  Month( 8 ,  2001 ),  116 .5D);   
  83.         
  84.            timeseries1.add( new  Month( 9 ,  2001 ),  112 .7D);   
  85.         
  86.            timeseries1.add( new  Month( 10 ,  2001 ),  101 .5D);   
  87.         
  88.            timeseries1.add( new  Month( 11 ,  2001 ),  106 .1D);   
  89.         
  90.            timeseries1.add( new  Month( 12 ,  2001 ),  110 .3D);   
  91.         
  92.            timeseries1.add( new  Month( 1 ,  2002 ),  111 .7D);   
  93.         
  94.            timeseries1.add( new  Month( 2 ,  2002 ), 111D);   
  95.         
  96.            timeseries1.add( new  Month( 3 ,  2002 ),  109 .6D);   
  97.         
  98.            timeseries1.add( new  Month( 4 ,  2002 ),  113 .2D);   
  99.         
  100.            timeseries1.add( new  Month( 5 ,  2002 ),  111 .6D);   
  101.         
  102.            timeseries1.add( new  Month( 6 ,  2002 ),  108 .8D);   
  103.         
  104.            timeseries1.add( new  Month( 7 ,  2002 ),  101 .6D);   
  105.         
  106.            TimeSeriesCollection timeseriescollection =  new  TimeSeriesCollection();   
  107.         
  108.            timeseriescollection.addSeries(timeseries);   
  109.         
  110.             timeseriescollection.addSeries(timeseries1);   
  111.         
  112.            timeseriescollection.setDomainIsPointsInTime( true );  //domain轴上的刻度点代表的是时间点而不是时间段   
  113.         
  114.            JFreeChart jfreechart = ChartFactory.createTimeSeriesChart( "合法 & General Unit Trust Prices" ,   
  115.         
  116.                    "日期" ,   
  117.         
  118.                    "暗示的话发神经提防" ,   
  119.         
  120.                   timeseriescollection,   
  121.         
  122.                    true ,   
  123.         
  124.                    true ,   
  125.         
  126.                    false );   
  127.         
  128.                   jfreechart.setBackgroundPaint(Color.white);   
  129.                   TextTitle textTitle = jfreechart.getTitle();   
  130.                 textTitle.setFont( new  Font( "宋体" , Font.BOLD,  20 ));   
  131.                 LegendTitle legend = jfreechart.getLegend();   
  132.                  if  (legend !=  null ) {   
  133.                     legend.setItemFont( new  Font( "宋体" , Font.BOLD,  20 ));   
  134.                 }   
  135.         
  136.                   XYPlot xyplot = (XYPlot)jfreechart.getPlot();  //获得 plot : XYPlot!!   
  137.                   ValueAxis domainAxis=xyplot.getDomainAxis();   
  138.                   domainAxis.setTickLabelFont( new  Font( "宋体" ,Font.BOLD, 20 )); //设置x轴坐标上的字体   
  139.                   domainAxis.setLabelFont( new  Font( "宋体" ,Font.BOLD, 20 )); //设置x轴坐标上的标题的字体   
  140.                      
  141.                   ValueAxis rangeAxis=xyplot.getRangeAxis();   
  142.                   rangeAxis.setTickLabelFont( new  Font( "宋体" ,Font.BOLD, 20 )); //设置y轴坐标上的字体   
  143.                   rangeAxis.setLabelFont( new  Font( "宋体" ,Font.BOLD, 20 )); //设置y轴坐标上的标题的字体   
  144.         
  145.                   xyplot.setBackgroundPaint(Color.lightGray);   
  146.         
  147.                   xyplot.setDomainGridlinePaint(Color.white);   
  148.         
  149.                   xyplot.setRangeGridlinePaint(Color.white);   
  150.         
  151.                   xyplot.setAxisOffset( new  RectangleInsets(5D, 5D, 5D, 5D));   
  152.         
  153.                   xyplot.setDomainCrosshairVisible( true );   
  154.         
  155.                   xyplot.setRangeCrosshairVisible( true );   
  156.         
  157.                   ChartFrame  frame= new  ChartFrame ( "折线图 " ,jfreechart, true );   
  158.         
  159.                   frame.pack();   
  160.         
  161.                   frame.setVisible( true );   
  162.   
  163.   
  164.   
  165.     }   
  166.   
  167. }  
JFreeChart在linux下中文乱码 很多文章都是修改服务器linux,但是实际情况中有的时候你没有权限,或不能对系统文件进行修改本文介绍怎么在项目内解决问题 private static File file = null; /** ************************************************************************* * JFreeChartHan... 阅读详情

相关推荐

linux下JFreeChart生成的图片乱码,可以用这个字体

linux下JFreeChart生成的图片乱码,可以用这个字体

LInux下Mplayer字幕乱码,日文字体部分乱码解决方案

ASS字幕如果不能加载的话,则需要把ASS字幕编码由utf16转换为utf8 用gedit也可以用这个也可以:iconv -f utf16 -t utf8 subtitle_utf16.ass > subtitle_utf8.ass 在Preferenecs->Subtitles&OSD中 Encoding选Simplified Chinese charset(CP93...

weixin_34233618的博客 5万+

Keil5实战:如何高效导出变量数据并实现可视化分析

本文详细介绍了在Keil5开发环境中,如何利用调试脚本高效导出程序运行时变量数据的方法。通过编写脚本自动捕获数据并保存为文件,再结合Excel或Python进行可视化分析,为嵌入式调试与算法优化提供了数据支撑,显著提升开发效率。

silver的专栏 1106

坑之二 乱码(3)

3)我百无聊赖地仰躺在床上,手里拿着一本书大声地念着。如果我身边还有其他人的话,我想辽会以为我在用希腊语念挪威文的北欧英雄史诗,伸会以为我在用阿拉伯语念意大利文的歌剧台词,征士会以为我在用蒙古语念不知哪个朝代传下来的梵语经文,秀会以为我在自学中国的湖南方言。但事实上我也不知道我在念什么。我甚至看不懂书名,更不要说知道内容了。我只知道这是一本用毛利语写就的书,而这恰好是一门我没有学过的语言。所以我只

愛ある限り 鎧のままに 23万+

【近源攻击】badusb制作

BadUSB是利用伪造HID设备执行攻击载荷的一种攻击方式。HID(Human InterfaceDevice)设备通常指的就是键盘鼠标等与人交互的设备,用户插入BadUSB,就会自动执行预置在固件中的恶意代码。BadUsb插入后,会模拟键盘鼠标对电脑进行操作,通过这些操作打开电脑的命令终端,并执行一条命令,这条命令将从指定网址下载其他代码并于后台静默运行。这些代码功能包括:窃取信息、反弹shell、发送邮件等,从而实现控制目标机或者窃取信息的目的。

qinjilll的博客 2550

不用加速器!Google Earth Pro登录失败自救手册:从服务器连接到地图加载的完整排错流程

本文详细解析了Google Earth Pro登录失败的常见问题及解决方案,包括服务器连接失败、地图加载异常等。通过基础排查、内置修复工具使用和高级配置调整,帮助用户无需加速器即可解决启动问题、黑屏和转圈圈等困扰,提升软件使用体验。

weixin_29227425的博客 485

一区即将要洗的DVD片子

101 Dalmatians [Animated] (2009, SE)《101斑点狗》预计2009年发行特别版12 Monkeys (05/10/2005, COM DOC)《12只猴子》预计2005年5月10日发行扩展版加评论和记录片等2001: A Space Odyssey (2006, SE)《2001:太空漫游》预计2006年发行特别版21 Grams (SE)《21克》特

现在的生活 521万+

DOORS需求管理实战:从汽车设计案例看模块化需求拆分技巧

本文通过一个汽车设计实战案例,深入解析了如何利用DOORS进行模块化需求拆分与管理。从捕获原始用户需求到精炼为可追踪的系统需求,再到按子系统(如自动驾驶)进行模块化拆分,文章详细展示了构建需求骨架、建立可追溯性以及实施变更控制的完整流程,帮助团队在复杂系统工程中实现从混沌到秩序的高效协同。

ww90123的博客 244

JFreeChart中文乱码

由于JFreeChart组件的版本、操作平台、JDK的设置等因素,在使用JFreeChart组件时可能会出现中文乱码的现象。遇到此问题时,可通过设置文字的字体来解决问题。在此提供以下三种种解决此问题的方法。

梦凝哲雪 989

ANSYS Workbench实战:用网格自适应搞定超弹性橡胶大变形仿真(附避坑命令流)

本文深入探讨了ANSYS Workbench中超弹性橡胶大变形仿真的网格自适应技术,重点解析了混合U-P单元的应用、非线性自适应网格的实战技巧及材料模型选择的注意事项。通过具体案例和命令流示例,帮助工程师有效解决橡胶仿真中的收敛问题和网格畸变挑战,提升仿真精度和效率。

weixin_42666036的博客 303

深入傅里叶级数与傅里叶变换:从基础到应用

傅里叶分析为我们提供了一种理解信号频率结构的强大工具。从傅里叶级数到傅里叶变换,再到快速傅里叶变换(FFT),其理论与应用紧密结合,对现代科学技术的发展意义非凡。如果你对信号处理、数据分析或工程计算感兴趣,傅里叶分析是必须掌握的基础工具。希望本文能帮助你对傅里叶分析有更深入的理解!如果有问题或想法,欢迎在评论区讨论!

qq_56683019的博客 3527

JFreeChart生成图表中文乱码问题解决方案

在使用JFreeChart生成图表时,可能会出现中文乱码,下面给出两种解决方法。 1、设置主题样式(推荐方法) 主题样式是在建立图表之前进行设置,JFreeChart图表一般包括3个部分:Title(图表标题)、Plot(图表主体)、Legend(图表图例),主题是统一对这三个部分进行字体设置 [java] view plaincopyprint? //创建主题样式  ...

phantomes的专栏 907

电商行业分析爬虫:抓取行业数据,进行行业分析

电商行业数据分析对于市场研究、竞争分析和商业决策至关重要。通过爬取电商平台的数据,我们可以深入了解市场动态、消费者行为和商品销售情况。本文将介绍如何构建一个电商行业分析爬虫,抓取商品信息、销售数据和用户评价等,并进行数据分析。

u014481728的博客 1628

JFreeChart中文乱码解决方案

------------------------http://developer.51cto.com/art/201112/308902.htm--------------------------     由于JFreeChart组件的版本、操作平台、JDK的设置等因素,在使用JFreeChart组件时可能会出现中文乱码的现象。遇到此问题时,可通过设置文字的字体来解决问题。在此提

3790

【以太网硬件九】1000base-X是什么?

简要描述1000base-X物理层规范

highman110的博客 1万+

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

JFreeChart 中文乱码解决

JFreeChart 中文乱码解决 这篇博文只是对网上关于jfreechart中文乱码解决方法的一个汇总整理。  我也是最近要使用到jfreechart这个图表工具,也是碰到了中文乱码这个问题,后来通过搜索(jfreechart图片乱码等关键词)解决了这个乱码,但发现一个问题就是有的文章只是解决了图表中乱码的某一个方面,比如图表标题,而有的文章不是解决图表标题乱码,却能够解决图表...

当你一无所有的时候,是上帝帮你倒空了垃圾,让你装进去对你最有用的东西 2149

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Linux下的JFreeChart出现中文乱码‘口口‘终极解决方案(亲测有效)

一、Linux下的JFreeChart出现的中文乱码 二、问题分析 在windows上运行时JFreeChart没有出现乱码,但是部署到Linux服务器时,JFreeChart出现了中文乱码的问题,究其原因,是因为Linux下缺少了一种字体,我们只需添加字体即可。 三、解决方案 1、找到你liunx上的jdk安装路径,在jre/lib/fonts文件夹下新建一个fallback文件夹 注意:文件夹的名称必须为fallback,请勿修改其他名称。 2、在fallback文件夹下添加simsun字体

年少不知曲中意,再听已是曲终人 3306

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

JFreeChart中文乱码和文字模糊问题的通用解决方案

在使用JFreeChart (http://www.jfree.org/jfreechart/ )做中文的图表时,中文乱码是一个最常要处理的问题,看网上许多文章都是在JFreeChart对象上下功夫,每次都得重新设置字体,比较麻烦。其实JFreeChart为我们提供了一个通用的解

dreambegin 的 优快云 2449

JfreeChart标题中文乱码的解决

如果使用JfreeChart默认的声明方式创建出来的图表图片上中文标题是方框或乱码,这个不用说肯定和字体有关.接下来来看一下解决办法.打开doc文件里的TextTitle类你会发现 /** The default font. */ public static final Font DEFAULT_FONT = new Font("SansSerif", Font.BOLD,12);JFre

yanick技术博客 2202

JFreeChart中文乱码的解决办法

由于JFreeChart组件的版本、操作平台、JDK的设置等因素,在使用JFreeChart组件时可能会出现中文乱码的现象。遇到此问题时,可通过设置文字的字体来解决问题。在此提供以下三种种解决此问题的方法。 一、设置主题的样式(强烈推荐) 在制图前,创建主题样式并制定样式中的字体,通过ChartFactory的setChartTheme()方法设置主题样式。 //创建主题样式 Stan...

lingtouyang的博客 750

jfreechart-绘图中文乱码问题

jfreechart-绘图中文乱码问题

kuLong_x的博客 464
上一篇: java 利用label标记退出多重循环
下一篇: maven2站点的定制和发布
Snoopy7713
博客等级 码龄21年 17粉丝 681原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值