jfreechar-中文乱码-设置字体解决

林上夕下 13年前
/**   * @Title:JfreeChartOne.java   * @Package:cn.sh.jfreechar.test   * @Description:TODO   * @author:Administrator   * @date:2012-2-22下午04:31:09   * @version V1.0    *   */  package cn.sh.jfreechar.test;    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;   /**   * 饼图-乱码处理-通过设置字体 解决   * @ClassName:JfreeChartOne   * @Description:TODO   * @author: Administrator   * @date:2012-2-22下午04:35:30   */  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);    }          }