- 浏览: 303668 次
- 性别:
- 来自: 郴州
文章分类
- 全部博客 (70)
- hadoop (0)
- lucene (1)
- heritrix (1)
- webservice (0)
- css+div (0)
- java (29)
- javaweb (3)
- spring (2)
- hibernate (3)
- struts (5)
- struts2 (3)
- tomcat (1)
- map/reduce (0)
- ajax (0)
- android (3)
- oracle (3)
- 面试题 (1)
- 生活 (0)
- 开发工具 (1)
- 面试实习 (0)
- 设计模式 (3)
- 数据结构 (5)
- 论坛 (2)
- flex (3)
- PureMVC (1)
- java,jdk (1)
- sql server (1)
- 报表 (1)
- 算法 (4)
- 工作 (0)
最新评论
-
lp895876294:
第三种方式类似于工厂方法模式了
设计模式之单例模式(三种实现方式) -
xchsh12345:
如果用的是linux服务器呢
解决利用iText导出PDF报表中文乱码两种方式 -
memoryisking:
写的不错,关于Timer和TimeTask的内容网上资料挺多的 ...
Java定时调度 Timer类和TimerTask类 -
linfeng0169:
写的不错~!不过就是解释的不算好!
Calendar类add()与roll()方法的区别 -
u013606853:
好流弊的样子,LZ V5~
hibernate注解详解
使用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));
下面一个实例:
下面这个修改坐标轴:
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));
下面一个实例:
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); } }
下面这个修改坐标轴:
package com.zzs.jfreechart.demo; import java.awt.Color; import java.awt.Font; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.LegendTitle; import org.jfree.chart.title.TextTitle; import org.jfree.data.time.Month; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.ui.RectangleInsets; public class ShiJianXuLieTu01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //时间序列图 TimeSeries timeseries = new TimeSeries("L&G European Index Trust",Month.class); timeseries.add(new Month(2, 2001), 181.8D);//这里用的是Month.class,同样还有Day.class Year.class 等等 timeseries.add(new Month(3, 2001), 167.3D); timeseries.add(new Month(4, 2001), 153.8D); timeseries.add(new Month(5, 2001), 167.6D); timeseries.add(new Month(6, 2001), 158.8D); timeseries.add(new Month(7, 2001), 148.3D); timeseries.add(new Month(8, 2001), 153.9D); timeseries.add(new Month(9, 2001), 142.7D); timeseries.add(new Month(10, 2001), 123.2D); timeseries.add(new Month(11, 2001), 131.8D); timeseries.add(new Month(12, 2001), 139.6D); timeseries.add(new Month(1, 2002), 142.9D); timeseries.add(new Month(2, 2002), 138.7D); timeseries.add(new Month(3, 2002), 137.3D); timeseries.add(new Month(4, 2002), 143.9D); timeseries.add(new Month(5, 2002), 139.8D); timeseries.add(new Month(6, 2002), 137D); timeseries.add(new Month(7, 2002), 132.8D); TimeSeries timeseries1 = new TimeSeries("L&G UK Index Trust曾召帅",Month.class); timeseries1.add(new Month(2, 2001), 129.6D); timeseries1.add(new Month(3, 2001), 123.2D); timeseries1.add(new Month(4, 2001), 117.2D); timeseries1.add(new Month(5, 2001), 124.1D); timeseries1.add(new Month(6, 2001), 122.6D); timeseries1.add(new Month(7, 2001), 119.2D); timeseries1.add(new Month(8, 2001), 116.5D); timeseries1.add(new Month(9, 2001), 112.7D); timeseries1.add(new Month(10, 2001), 101.5D); timeseries1.add(new Month(11, 2001), 106.1D); timeseries1.add(new Month(12, 2001), 110.3D); timeseries1.add(new Month(1, 2002), 111.7D); timeseries1.add(new Month(2, 2002), 111D); timeseries1.add(new Month(3, 2002), 109.6D); timeseries1.add(new Month(4, 2002), 113.2D); timeseries1.add(new Month(5, 2002), 111.6D); timeseries1.add(new Month(6, 2002), 108.8D); timeseries1.add(new Month(7, 2002), 101.6D); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(timeseries); timeseriescollection.addSeries(timeseries1); timeseriescollection.setDomainIsPointsInTime(true); //domain轴上的刻度点代表的是时间点而不是时间段 JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("合法 & General Unit Trust Prices", "日期", "暗示的话发神经提防", timeseriescollection, true, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle textTitle = jfreechart.getTitle(); textTitle.setFont(new Font("宋体", Font.BOLD, 20)); LegendTitle legend = jfreechart.getLegend(); if (legend != null) { legend.setItemFont(new Font("宋体", Font.BOLD, 20)); } XYPlot xyplot = (XYPlot)jfreechart.getPlot(); //获得 plot : XYPlot!! ValueAxis domainAxis=xyplot.getDomainAxis(); domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴坐标上的字体 domainAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴坐标上的标题的字体 ValueAxis rangeAxis=xyplot.getRangeAxis(); rangeAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的字体 rangeAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的标题的字体 xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); ChartFrame frame=new ChartFrame ("折线图 ",jfreechart,true); frame.pack(); frame.setVisible(true); } }
- jfreechart-1.0.13.zip (7.4 MB)
- 下载次数: 46
评论
1 楼
hanmiao
2013-09-05
上述方法在我的 jfreechart 1.0.15 版本上无法正常运行,会提示 ClassCastException,原因是XYPlot 类型无法直接转化为 CategoryPlot 类型,估计是官方在新的版本中作了壹些修改引起的,目前我知道的最有效的解决方案是 51CTO 上提供的这个方法:http://developer.51cto.com/art/201112/308902.htm
发表评论
-
利用微软翻译API替代被停用谷歌翻译API
2012-02-13 13:37 10343众所周知,谷歌已经不支持翻译API1版本了,现在提供了A ... -
(转)Java回调实现
2011-12-08 14:38 1130Java回调实现 轮询:过10分钟就到女朋友宿舍前面去看她有 ... -
java实现排序算法之插入排序(直接插入排序、折半插入、shell排序)
2011-09-15 09:29 2483插入排序主要包括直接插入排序、shell排序和折半插入等几种排 ... -
java实现排序算法之交换排序(冒泡排序、快速排序)
2011-09-14 21:28 2591交换排序的主体操作是对数组中的数据不断进行交换操作。交换排序主 ... -
java实现排序算法之选择排序(直接选择排序、堆排序)
2011-09-14 20:44 2636常用的选择排序算法有两种:直接选择排序和堆排序。 一、直接选择 ... -
java 实现数据结构之队列
2011-09-14 15:27 12606队列是一种特殊的线性表,它只允许在表的前端(front)进行删 ... -
java 实现数据结构之线性表
2011-09-14 11:44 10669应用程序后在那个的数据大致有四种基本的逻辑结构: 集合:数 ... -
java 实现undo和redo操作链表的一种实现
2011-09-14 10:32 2138今天在iteye论坛逛,发现有这么一道笔试题目:实现一个可以增 ... -
jdbc连接mysql oracle sql server数据库的连接字符串
2011-09-13 10:41 2713jdbc连接mysql oracle sql serv ... -
java 利用label标记退出多重循环
2011-09-10 09:16 12033学过C语言的都知道,有个goto关键字,利用goto关键字可以 ... -
深入JDK源代码之定时操作Timer类和TimerTask类实现
2011-07-26 14:45 3468Timer类是一种线程设施,可以用来实现某一个时间或某 ... -
(转)Java中对象的深复制(深克隆)和浅复制(浅克隆)
2011-07-25 20:31 11971.浅复制与深复制概念 ⑴浅复制(浅克隆) 被复制对象 ... -
深入JDK源代码之LinkedList类
2011-07-26 09:09 1887public class LinkedList<E> ... -
Java中的transient关键字
2011-07-25 14:36 24886transient说明一个属性是临时的,不会被序列化。 下面是 ... -
深入JDK源代码之Observer接口和Observable类实现观察者模式
2011-07-25 11:46 3410一、何为观察者模式? 观察者模式(有时又被称为发布/ ... -
深入JDK源代码之ArrayList类
2011-07-22 11:19 2915public class ArrayList<E&g ... -
深入JDK源代码之Arrays类中的排序查找算法
2011-07-22 09:58 3948最近在暑假实习, ... -
java 实现数据结构之栈
2011-07-10 21:51 4641在学数据结构课程 ... -
Java定时调度 Timer类和TimerTask类
2011-07-10 15:38 23883Timer类是一种线程设施,可以用来实现某一个时间或某一段 ... -
Calendar类add()与roll()方法的区别
2011-07-06 22:45 10935JDK API中对这两个方法的说明如下: abstract ...
相关推荐
Jfreechart 中文乱码的解决方法,网上共享的资源
jfreechart中文乱码问题解决方案
Linux下JFreechart中文乱码的解决.docx
JFreeChart 中文乱码 解决方案J FreeChart 中文乱码 解决方案
JFreeChart乱码解决方法 - 企业应用 - Java
解决jfreechart中文乱码方案整 解决jfreechart中文乱码方案整
jfreechart linux乱码解决方案,比较完整。
绝对物超所值! JFreeChart-1.0.13原文件含jar包。 1、JFreeChart生成图片路径教程 2、JFreeChart使用教程(含下载安装,超详细...5、JFreeChart乱码解决方法 等等 包括csdn上得优秀案例 ------20+M的数据不要别后悔哦
JFreeChart中文乱码问题解决,乱码问题一直是中文在网络时代的关键细节
JFreeChart-1.0.13原文件含jar包。 1、JFreeChart生成图片路径教程 2、JFreeChart使用教程(含下载安装,超详细) 3、JFreeChart使用详细教程 ...5、JFreeChart乱码解决方法 等等 包括许多优秀案例
这篇博文只是对网上关于jfreechart中文乱码解决方法的一个汇总整理。
NULL 博文链接:https://love422619.iteye.com/blog/2383006
JFreeChart用于制表,将数据转化为表格,这个版本不会有中文乱码,推荐
JFreeChart 中文乱码
解决linux 下,jfreechart乱码
终极解决方案最简单,最直接的,已解决多台服务器java程序应用jfreechart生成图片,中文乱码问题
jfreechart 乱码 问题 jfreechart乱码问题
自己将jfreechart常用的、柱状图、折线图、饼状图(二维的和三维的)对官网的dome进行了封装和加强,解决了高版本中文乱码问题,数值显示问题、及怎么显示百分比
zysong.ttf jfreechart 解决中文乱码 问题.zysong.ttf LInux字体库 .用于解决jfreechart在linux环境中的中文乱码问题
jfreechart生成报表会有乱码问题,这是解决报表乱码的,很好用