jfreechart之中文處理處理類
<PRE style="BACKGROUND-COLOR: #c5c5c5; FONT-WEIGHT: bold" class=java name="code">import java.awt.Color; import java.awt.Font; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.title.TextTitle;
/**
- @author 劉毅
- @date 2010-2-25
- @ClassName JfreeChinese.java
- @Email liu_yi126@163.com
- @param 字體
@param */ public class JfreeChinese { //柱.標題 public static Font FONT_TILE_CHINESE= new Font("宋體",Font.BOLD,16); //X軸 public static Font FONT_X_CHINESE= new Font("宋體",Font.BOLD,12); //Y軸 public static Font FONT_Y_CHINESE= new Font("宋體",Font.BOLD,13); //底部 public static Font FONT_L_CHINESE= new Font("宋體",Font.BOLD,18);
//餅標題 public static Font FONT_PIE_TILE_CHINESE= new Font("宋體",Font.BOLD,16); //Y軸 public static Font FONT_PIE_IMG_CHINESE= new Font("宋體",Font.BOLD,13); //底部 public static Font FONT_PIE_D_CHINESE= new Font("宋體",Font.BOLD,18);
/**
- 柱形圖字體
- @param chart */ public static void setChineseForXY(JFreeChart chart){
CategoryPlot plot = chart.getCategoryPlot();// 圖形的繪制結構對象 //標題字體 TextTitle title; title = chart.getTitle(); title.setFont(FONT_TILE_CHINESE); // 底部
chart.getLegend().setItemFont(FONT_L_CHINESE);
// X 軸
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLabelFont(FONT_X_CHINESE);// 軸標題
domainAxis.setTickLabelFont(FONT_X_CHINESE);// 軸數值
domainAxis.setTickLabelPaint(Color.BLUE) ; // 字體顏色
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 橫軸上的label斜顯示
// Y 軸
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setLabelFont(FONT_Y_CHINESE);
rangeAxis.setLabelPaint(Color.BLUE) ; // 字體顏色
rangeAxis.setTickLabelFont(FONT_Y_CHINESE); }/**
- 餅圖字體
- @param chart */ public static void setChineseForPie(JFreeChart chart){ //標題 TextTitle title; title = chart.getTitle(); title.setFont(FONT_PIE_TILE_CHINESE); //圖 PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(FONT_PIE_IMG_CHINESE); //底部說明 chart.getLegend().setItemFont(FONT_PIE_D_CHINESE);
}
} </PRE>