解决jfreechart中文乱码,以及字体模糊,设置主题问题

来源:互联网 发布:最新网络流行词2016 编辑:程序博客网 时间:2024/05/21 13:58
发现一篇博客解决了我的乱码问题,复制过来分享下。
package cn.com.gwypx.util;import java.awt.Color;import java.awt.Font;import java.awt.Paint;import org.jfree.chart.ChartFactory;import org.jfree.chart.JFreeChart;import org.jfree.chart.StandardChartTheme;import org.jfree.chart.plot.DefaultDrawingSupplier;import org.jfree.chart.plot.PieLabelLinkStyle;import org.jfree.chart.renderer.category.StandardBarPainter;import org.jfree.chart.renderer.xy.StandardXYBarPainter;import org.jfree.ui.RectangleInsets;public class ChartUtils{    private static Font FONT = new Font("宋体", Font.PLAIN, 12);    public static Color[] CHART_COLORS = {new Color(31, 129, 188),            new Color(241, 92, 128), new Color(124, 181, 236),            new Color(102, 172, 204), new Color(102, 102, 0),            new Color(204, 153, 102), new Color(0, 153, 255),            new Color(204, 255, 255), new Color(51, 153, 153),            new Color(255, 204, 102), new Color(102, 102, 0),            new Color(204, 204, 204), new Color(204, 255, 255),            new Color(255, 204, 204), new Color(255, 255, 204),            new Color(255, 153, 204), new Color(51, 0, 0),            new Color(0, 51, 102), new Color(0, 153, 102),            new Color(153, 102, 153), new Color(102, 153, 204),            new Color(153, 204, 153), new Color(204, 204, 153),            new Color(255, 255, 153), new Color(255, 204, 153),            new Color(255, 153, 204), new Color(204, 153, 153),            new Color(204, 204, 255), new Color(204, 255, 204),            new Color(153, 204, 153), new Color(255, 204, 102)};// 颜色    /**     * 中文主题样式 解决乱码     */    public static void setChartTheme()    {        // 设置中文主题样式 解决乱码        StandardChartTheme chartTheme = new StandardChartTheme("CN");        // 设置标题字体        chartTheme.setExtraLargeFont(FONT);        // 设置图例的字体        chartTheme.setRegularFont(FONT);        // 设置轴向的字体        chartTheme.setLargeFont(FONT);        chartTheme.setSmallFont(FONT);        chartTheme.setTitlePaint(new Color(51, 51, 51));        chartTheme.setSubtitlePaint(new Color(85, 85, 85));        chartTheme.setLegendBackgroundPaint(Color.WHITE);// 设置标注        chartTheme.setLegendItemPaint(Color.BLACK);//        chartTheme.setChartBackgroundPaint(Color.WHITE);        // 绘制颜色绘制颜色.轮廓供应商        // paintSequence,outlinePaintSequence,strokeSequence,outlineStrokeSequence,shapeSequence        Paint[] OUTLINE_PAINT_SEQUENCE = new Paint[]{Color.WHITE};        // 绘制器颜色源        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(                CHART_COLORS, CHART_COLORS, OUTLINE_PAINT_SEQUENCE,                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);        chartTheme.setDrawingSupplier(drawingSupplier);        chartTheme.setPlotBackgroundPaint(Color.WHITE);// 绘制区域        chartTheme.setPlotOutlinePaint(Color.WHITE);// 绘制区域外边框        chartTheme.setLabelLinkPaint(new Color(8, 55, 114));// 链接标签颜色        chartTheme.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);        chartTheme.setAxisOffset(new RectangleInsets(5, 12, 5, 12));        chartTheme.setDomainGridlinePaint(new Color(192, 208, 224));// X坐标轴垂直网格颜色        chartTheme.setRangeGridlinePaint(new Color(192, 192, 192));// Y坐标轴水平网格颜色        chartTheme.setBaselinePaint(Color.WHITE);        chartTheme.setCrosshairPaint(Color.BLUE);// 不确定含义        chartTheme.setAxisLabelPaint(new Color(51, 51, 51));// 坐标轴标题文字颜色        chartTheme.setTickLabelPaint(new Color(67, 67, 72));// 刻度数字        chartTheme.setBarPainter(new StandardBarPainter());// 设置柱状图渲染        chartTheme.setXYBarPainter(new StandardXYBarPainter());// XYBar 渲染        chartTheme.setItemLabelPaint(Color.black);        chartTheme.setThermometerPaint(Color.white);// 温度计        ChartFactory.setChartTheme(chartTheme);    }    /**     * 解决中文字体模糊     */    public static void setAntiAlias(JFreeChart chart)    {        chart.setTextAntiAlias(false);    }}
创建报表对象之前调用setChartTheme(),创建报表对象之后调用setAntiAlias(JFreeChart chart)

0 0
原创粉丝点击