JFreeChart中文帮助文档
jfreechar 详细设置demo
jfreechar 详细设置demo(不断更新,研究中)关键字: jfreechar, 柱图, 饼图本demo正如上传的jfreechar的demo一样,(因为jfreechar版本并不相互支持)业余时间的爱好罢了,不过还是有质量的。
首先希望喜欢的、使用中的、使用过的、资深的jfreechar二次开发者能给与最大的支持支持!其次大家可以加入我的QQ群:72729572(普通群)一起在线研究讨论jfreechar。
最后感谢jfreechar、JavaEye和朋友们的大力支持支持!哈哈,今天心情好!多罗嗦两句!正题:jfreechart-1.0.11.zip里面有jfreechar的源码和jar包,我所发表的demo和他的demo是在一起的,请大家注意包的位置。
jfreechart-1.0.11-install.pdf是一个jreechar官方英文安装文档。
2006110821482378503.jpg是要放在d盘目录下的一个背景图片。
声明:1.在图片上生成中文时,一定要重新实例化字体,要不然中文是乱码!2.环境是:jdk1.5+jfreechart1.0.113.以下demo是为了明白图片生成和设置,并没有美化图片,嘿嘿!一、改造后的2d柱图demo1Java代码1./**2. * 详细设置2D柱图3. * */4.5.package org.jfree.chart.demo;6.7.import java.awt.Color;8.import java.awt.Dimension;9.import java.awt.Font;10.import java.awt.GradientPaint;11.12.import org.jfree.chart.ChartFactory;13.import org.jfree.chart.ChartPanel;14.import org.jfree.chart.JFreeChart;15.import org.jfree.chart.axis.AxisLocation;16.import org.jfree.chart.axis.CategoryAxis;17.import org.jfree.chart.axis.CategoryLabelPositions;18.import org.jfree.chart.axis.NumberAxis;19.import org.jfree.chart.axis.NumberTickUnit;20.import org.jfree.chart.axis.ValueAxis;21.import org.jfree.chart.block.BlockContainer;22.import org.jfree.chart.block.BorderArrangement;23.import belBlock;24.import bels.StandardCategoryItemLabelGenerator;25.import org.jfree.chart.plot.CategoryPlot;26.import org.jfree.chart.plot.IntervalMarker;27.import org.jfree.chart.plot.PlotOrientation;28.import org.jfree.chart.renderer.category.BarRenderer;29.import org.jfree.chart.renderer.category.LineAndShapeRenderer;30.import org.jfree.chart.title.LegendTitle;31.import org.jfree.chart.title.TextTitle;32.import org.jfree.chart.urls.StandardCategoryURLGenerator;33.import org.jfree.data.category.CategoryDataset;34.import org.jfree.data.category.DefaultCategoryDataset;35.import org.jfree.ui.ApplicationFrame;36.import org.jfree.ui.HorizontalAlignment;37.import yer;38.import org.jfree.ui.RectangleAnchor;39.import org.jfree.ui.RectangleEdge;40.import org.jfree.ui.RectangleInsets;41.import org.jfree.ui.RefineryUtilities;42.import org.jfree.ui.TextAnchor;43.import org.jfree.ui.VerticalAlignment;44.45./**46. * 生成一个带有多组数据的柱图(最基础图形)47. *48. */49.public class BarChartDemo1 extends ApplicationFrame {50.51. /**52. *53. */54. private static final long serialVersionUID = 1L;55.56. /**57. * 生成柱图58. *59. * @param title 大标题.60. */61. public BarChartDemo1(String title) {62. super(title);63. CategoryDataset dataset = createDataset();64. CategoryDataset dataset1 = createDataset1();65. JFreeChart chart = createChart(title,dataset,dataset1);66. ChartPanel chartPanel = new ChartPanel(chart, false);67. chartPanel.setPreferredSize(new Dimension(500, 270));68. setContentPane(chartPanel);69. }70.71. /**72. * 返回条形图所需要的数据(CategoryDataset基础数据类型).73. *74. * @return The dataset.75. */76. private static CategoryDataset createDataset() {77.78. // 行数据名称79. String series1 = "名称";80. String series2 = "Second";81. String series3 = "Third";82.83. // 栏数据名称84. String category1 = "栏数据";85. String category2 = "Category 2";86. String category3 = "Category 3";87. String category4 = "Category 4";88. String category5 = "Category 5";89.90. // 详细数据91. DefaultCategoryDataset dataset = new DefaultCategoryDataset();92.93. dataset.addValue(1.0, series1, category1);94. dataset.addValue(4.0, series1, category2);95. dataset.addValue(3.0, series1, category3);96. dataset.addValue(5.0, series1, category4);97. dataset.addValue(-5.0, series1, category5);98.99. dataset.addValue(5.0, series2, category1);100. dataset.addValue(7.0, series2, category2); 101. dataset.addValue(6.0, series2, category3); 102. dataset.addValue(8.0, series2, category4); 103. dataset.addValue(4.0, series2, category5); 104.105. dataset.addValue(4.0, series3, category1); 106. dataset.addValue(3.0, series3, category2); 107. dataset.addValue(2.0, series3, category3); 108. dataset.addValue(3.0, series3, category4); 109. dataset.addValue(6.0, series3, category5); 110.111. return dataset;112.113. }114. /**115. * 返回条形图所需要的数据(CategoryDataset基础数据类型).116. *117. * @return The dataset.118. */119. private static CategoryDataset createDataset1() { 120.121. // 行数据名称122. String series1 = "名称";123. String series2 = "Second";124. String series3 = "Third";125.126. // 栏数据名称127. String category1 = "栏数据";128. String category2 = "Category 2";129. String category3 = "Category 3";130. String category4 = "Category 4";131. String category5 = "Category 5";132.133. // 详细数据134. DefaultCategoryDataset dataset = new DefaultCatego ryDataset();135.136. dataset.addValue(11.0, series1, category1); 137. dataset.addValue(14.0, series1, category2); 138. dataset.addValue(13.0, series1, category3); 139. dataset.addValue(15.0, series1, category4); 140. dataset.addValue(-15.0, series1, category5); 141.142. dataset.addValue(15.0, series2, category1); 143. dataset.addValue(17.0, series2, category2); 144. dataset.addValue(16.0, series2, category3); 145. dataset.addValue(18.0, series2, category4); 146. dataset.addValue(14.0, series2, category5); 147.148. dataset.addValue(14.0, series3, category1); 149. dataset.addValue(13.0, series3, category2); 150. dataset.addValue(12.0, series3, category3); 151. dataset.addValue(13.0, series3, category4); 152. dataset.addValue(16.0, series3, category5); 153.154. return dataset;155.156. }157. /**158. * 生成一个柱图图片159. *160. * @param dataset the dataset.161. *162. * @return The chart.163. */164. private static JFreeChart createChart(String title,Cat egoryDataset dataset,CategoryDataset dataset1) {165.166. // create the chart...167. JFreeChart chart = ChartFactory.createBarChart( 168. title, // chart title169. "Category", // domain axis label170. "Value", // range axis label171. dataset, // data172. PlotOrientation.VERTICAL, // 生成图片方向173. true, // include legend 174. true, // tooltips? 175. false // URLs?176. );177. //总图片设置178. //设置背景颜色的图表179. chart.setBackgroundPaint(Color.WHITE);180. //设置图片的边框是否显示181. chart.setBorderVisible(true);182. //设置背景图片透明度(0.0~1.0)183. chart.setBackgroundImageAlpha(1.0f);184. //是否字体去锯齿185. chart.setAntiAlias(true);186. //主标题字体设置187. TextTitle text = chart.getTitle();188. Font font = new Font("黑体",Font.BOLD,20); 189. text.setFont(font);190. chart.setTitle(text);191.192.193.194. //主图片主样式实例化195. CategoryPlot plot=chart.getCategoryPlot(); 196. //设置图片的背景颜色197. plot.setBackgroundPaint(Color.lightGray); 198. //设置图片的透明度(0.0~1.0)199. plot.setBackgroundAlpha(1.0f);200. //设置x轴刻度线颜色201. plot.setDomainGridlinePaint(Color.white); 202. plot.setDomainGridlinesVisible(true);203. //设置y轴刻度线颜色204. plot.setRangeGridlinePaint(Color.white);205. plot.setRangeGridlinesVisible(true);206. //设置柱子的透明度207. plot.setForegroundAlpha(0.9f);208. //设置x轴显示位置209. plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEF T);210. //设置y轴显示位置211. plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_R IGHT);212. //设置横纵坐标与axises之间的间距213. plot.setAxisOffset(new RectangleInsets(10.0, 10.0,10.0, 10.0));214.215.216. //bar实例化217. BarRenderer renderer = (BarRenderer) plot.getRende rer();218. //设置条形图上bar是否显示背景阴影219. renderer.setDrawBarOutline(false);220. //设置bar最大宽度百分比221. renderer.setMaximumBarWidth(0.10D);222. //设置bar显示value223. //renderer.setBaseItemLabelGenerator(new StandardC ategoryItemLabelGenerator());224. //renderer.setBaseItemLabelsVisible(true); 225. renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);226. // 手动设置条形图上bar设置颜色227. GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue,228.0.0f, 0.0f, new Color(0, 0, 64)); 229. GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red,230.0.0f, 0.0f, new Color(64, 0, 0)); 231. GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.green,232.0.0f, 0.0f, new Color(0, 64, 0)); 233. renderer.setSeriesPaint(0, gp0);234. renderer.setSeriesPaint(1, gp1);235. renderer.setSeriesPaint(2, gp2);236. //bar间的宽度237. renderer.setItemMargin(0);238. //使设置生效239. renderer.setBaseItemLabelsVisible(true);240. //生成url连接(没有试验成功, 好像只有在jsp页面才ok,在jsp里面有个简单demo,做数据挖掘研究用,还没有改善)241. renderer.setBaseItemURLGenerator(new StandardCateg oryURLGenerator(""));242. //让上面所有的设置都生效243. plot.setRenderer(renderer);244.245. //设置图线246. //设置第二y轴坐标名247. NumberAxis numberAxis = new NumberAxis("y轴值");248. plot.setRangeAxis(1, numberAxis);249. plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_O R_RIGHT);250. plot.setDataset(1, dataset1);251. plot.setRenderer(1, new LineAndShapeRenderer());252. plot.mapDatasetToDomainAxis(1, 0);253. plot.mapDatasetToRangeAxis(1,1);254. plot.addRangeMarker(createIntervalMarker(0, 2, Col or.GREEN, "0~2"), Layer.BACKGROUND);255.256. plot.addRangeMarker(createIntervalMarker(2, 4, Col or.BLACK, "2~4"), Layer.BACKGROUND);257.258. plot.addRangeMarker(createIntervalMarker(4, 6, Col or.PINK, "4~6"), Layer.BACKGROUND);259.260. plot.addRangeMarker(createIntervalMarker(6, 8, Col or.BLUE, "6~8"), Layer.BACKGROUND);261.262. plot.addRangeMarker(createIntervalMarker(8, 10, Co lor.YELLOW, "8~10"), Layer.BACKGROUND);263.264.265.266.267. //x坐标轴实例化268. CategoryAxis xaxis = plot.getDomainAxis(); 269. //坐标轴标尺值字体270. xaxis.setTickLabelFont(new Font("Serif",Font.CENTE R_BASELINE,13));271. xaxis.setLabelFont(new Font("Serif",Font.CENTER_BA SELINE,20));272. //设置栏目名称的旋转角度273. xaxis.setCategoryLabelPositions(CategoryLabelPosit ions.createUpRotationLabelPositions(Math.PI / 6.0));274. //设置距离图片左端距离,参数为图片的百分比275. xaxis.setLowerMargin(0.05);276. //设置距离图片右端距离277. xaxis.setUpperMargin(0.05);278.279.280. //y坐标轴实例化281. ValueAxis yaxis = plot.getRangeAxis();282. //坐标轴标尺值字体283. yaxis.setTickLabelFont(new Font("Serif",Font.CENTE R_BASELINE,13));284. yaxis.setLabelFont(new Font("Serif",Font.CENTER_BA SELINE,15));285. // 设置的范围轴,以显示只有整数286. final NumberAxis rangeAxis = (NumberAxis) plot.get RangeAxis();287. rangeAxis.setStandardTickUnits(NumberAxis.createIn tegerTickUnits());288. //将纵坐标间距设置为3289. rangeAxis.setTickUnit(new NumberTickUnit(3)); 290. //设置最高的一个柱与图片顶端的距离291. rangeAxis.setUpperMargin(0.2);292. //设置最低的一个柱与图片底端的距离293. rangeAxis.setLowerMargin(0.05);294. //设置竖坐标标签的旋转角度295. rangeAxis.setLabelAngle(0.05);296.297.298.299.300.301. //修改图例的字体302. LegendTitle legend = chart.getLegend();303. legend.setItemFont(new Font("宋体", Font.BOLD, 14));304. //设置图例中图示的位置(最短距离)305. legend.setPadding(10D,10D,10D,10D);306. //设置图例的背景颜色307. legend.setBackgroundPaint(Color.CYAN);308. //设置图例在图片中的位置(上下左右)309. legend.setPosition(RectangleEdge.RIGHT);310. //设置图例在图片中的位置(左中右)311. legend.setHorizontalAlignment(HorizontalAlignment.CENTER);312. //设置图例在图片中的位置(上中下)313. legend.setVerticalAlignment(VerticalAlignment.TOP) ;314. //手动设置图例是否可见315. legend.setVisible(false);316.317. //重新生成图例(契机)318. //实例化图例319. LegendTitle legendtitle = new LegendTitle(chart.ge tPlot());320. //设置图片背景颜色321. legendtitle.setBackgroundPaint(Color.CYAN); 322. //实例化图例块323. BlockContainer blockcontainer = new BlockContainer (new BorderArrangement());324. //图例的边界宽度325. blockcontainer.setBorder(1.0D, 1.0D, 1.0D, 1.0D);326. //自定义图例标题(标签)327. LabelBlock labelblock = new LabelBlock("test菜单:", new Font("宋体", 1, 12));328. //自定义边界距离329. labelblock.setPadding(5D, 5D, 5D, 5D);330. //自定义图例标签的位置并使之装入自定义图例框331. blockcontainer.add(labelblock, RectangleEdge.TOP);332. //自定义图例标题(标签)333. LabelBlock labelblock1 = new LabelBlock("by thomas 2008.12.19");334. //自定义边界距离335. labelblock1.setPadding(8D, 20D, 2D, 5D);336. //自定义图例标签的位置并使之装入自定义图例框337. blockcontainer.add(labelblock1, RectangleEdge.BOTT OM);338. //获得原图例的实例项目集339. BlockContainer blockcontainer1 = legendtitle.getIt emContainer();340. //自定义边界距离341. blockcontainer1.setPadding(2D, 10D, 5D, 2D); 342. //自定义图例标签的位置并使之装入自定义图例框343. blockcontainer.add(blockcontainer1);344. //画出图例边界345. legendtitle.setWrapper(blockcontainer);346. //设置图例在图片中的位置(上下左右)347. legendtitle.setPosition(RectangleEdge.RIGHT); 348. //设置图例在图片中的位置(左中右)349. legendtitle.setHorizontalAlignment(HorizontalAlign ment.LEFT);350.351. chart.addSubtitle(legendtitle);352.353.354. return chart;355.356. }357. private static IntervalMarker createIntervalMarker(dou ble low, double height, Color color, String label) { 358. IntervalMarker intervalmarker = new IntervalMarker (low, height);359.360. intervalmarker.setPaint(color);361.362. intervalmarker.setLabel(label);363.364. intervalmarker.setLabelFont(new Font("宋体", Font.BOLD, 8));365.366. intervalmarker.setLabelAnchor(RectangleAnchor.LEFT );367.368. intervalmarker.setLabelTextAnchor(TextAnchor.CENTE R_LEFT);369.370. return intervalmarker;371.372. }373. /**374. * Starting point for the demonstration application.375. *376. * @param args ignored.377. */378. public static void main(String[] args) {379. BarChartDemo1 demo = new BarChartDemo1("Bar 图 Dem o 1");380. demo.pack();381. RefineryUtilities.centerFrameOnScreen(demo);382. demo.setVisible(true);383. }384.385.}二、改造后的2D饼图demo1Java代码1./**2. * 生成一个2D饼图3. *4. * */5.6.package org.jfree.chart.demo;7.8.import java.awt.Color;9.import java.awt.Font;10.import java.awt.GradientPaint;11.import java.awt.Image;12.import java.io.IOException;13.import java.text.DecimalFormat;14.import java.text.NumberFormat;15.16.import javax.imageio.ImageIO;17.import javax.swing.JPanel;18.19.import org.jfree.chart.ChartFactory;20.import org.jfree.chart.ChartPanel;21.import org.jfree.chart.JFreeChart;22.import org.jfree.chart.block.BlockContainer;23.import org.jfree.chart.block.BorderArrangement;24.import belBlock;25.import bels.StandardPieSectionLabelGenerator;26.import org.jfree.chart.plot.PiePlot;27.import org.jfree.chart.title.LegendTitle;28.import org.jfree.data.general.DefaultPieDataset;29.import org.jfree.data.general.PieDataset;30.import org.jfree.ui.ApplicationFrame;31.import org.jfree.ui.HorizontalAlignment;32.import org.jfree.ui.RectangleEdge;33.import org.jfree.ui.RefineryUtilities;34.import org.jfree.ui.VerticalAlignment;35.36./**37. * 生成一个2D饼图(基础图形)38. */39.public class PieChartDemo1 extends ApplicationFrame {40.41. /**42. *43. */44. private static final long serialVersionUID = 1L;45.46. /**47. * Default constructor.48. *49. * @param title the frame title.50. */51. public PieChartDemo1(String title) {52. super(title);53. setContentPane(createDemoPanel(title));54. }55.56. /**57. * Creates a sample dataset.58. *59. * @return A sample dataset.60. */61. private static PieDataset createDataset() {62. DefaultPieDataset dataset = new DefaultPieDataset();63. dataset.setValue("One", new Double(43.2));64. dataset.setValue("Two", new Double(10.0));65. dataset.setValue("Three", new Double(27.5));66. dataset.setValue("Four", new Double(17.5));67. dataset.setValue("Five", new Double(11.0));68. dataset.setValue("Six", new Double(19.4));69. return dataset;70. }71.72. /**73. * Creates a chart.74. *75. * @param dataset the dataset.76. *77. * @return A chart.78. */79. private static JFreeChart createChart(String title,PieDataset dataset) {80.81. JFreeChart chart = ChartFactory.createPieChart(82. title, // chart title83. dataset, // data84. true, // include legend85. true,86. false87. );88. //总图片设置89. //设置背景颜色的图表90. GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue,91. 500.0f, 270.0f, new Color(0, 0, 64));92. gp = null;93. chart.setBackgroundPaint(gp);94. //设置图片背景图片95. if(gp == null){96. Image image = null;97. try {98. image = ImageIO.read(new java.io.File("D:\\2006110821482378503.jpg"));99. } catch (IOException e) {100. // TODO Auto-generated catch block101. e.printStackTrace();102. }103. chart.setBackgroundImage(image);104. }105. //设置图片的边框是否显示106. chart.setBorderVisible(false);107. //设置背景图片透明度(0.0~1.0)108. chart.setBackgroundImageAlpha(1.0f);109. //是否字体去锯齿110. chart.setAntiAlias(true);111.112.113.114. //手动设置饼图样式115. PiePlot plot = (PiePlot) chart.getPlot(); 116. //设置图片的背景颜色117. plot.setBackgroundPaint(Color.lightGray); 118. //设置图片的透明度(0.0~1.0)119. plot.setBackgroundAlpha(0.6f);120. //把Lable 为"One" 的那一块”挖“出来30%121. plot.setExplodePercent("One",0.3D);122. plot.setExplodePercent("Six",0.3D);123. //设置无数据时的信息124. plot.setNoDataMessage("无对应的数据,请重新查询。
JFreeChart快速指南说明书
required libraries can be linked into your Java program. The following image shows the structure of the directories and files :Add complete path of jfreechart-1.0.18.jar and jcommon-1.0.22.jar files to the CLASSPATH as shown below :OS DescriptionWindows Append the Strings “C:\ jfreechart-1.0.18\lib\ jfreechart-1.0.18.jar” and “C:\ jfreechart-1.0.18\lib\ jcommon-1.0.22.jar” to the end of the user variable CLASSPATH Linux Export CLASSPATH=$CLASSPATH: /usr/share/jfreechart-1.0.18/lib/jfreechart-1.0.18.jar: /usr/share/jfreechart-1.0.18/lib/jcommon-1.0.22.jarJFREECHART ARCHITECTUREThis chapter explains basic class level and application level architectures of JFreeChart to give you an idea about how JFreeChart interacts with different classes and how it fits in your Java based application.Class Level ArchitectureThe class level architecture explains how various classes from the library interacts with each other to create various types of charts.Following is the detail of the units used in the above block diagram :Units DescriptionFile The source having user input to be used for creating a dataset inthe file.Database The source having user input to be used for creating a dataset inthe database.Create Dataset Accepts the dataset and stores the dataset into dataset object. General Dataset This type of dataset is mainly used for pie charts.Category Dataset This type of dataset is used for bar chart, line chart,etc.Series Dataset This type of dataset is used for storing series of data and constructline charts.Series Collection Dataset The different categories of series datasets are added to seriescollection dataset. This type of dataset is used for XYLine Charts. Create Chart This is the method which is executed to create final chart.Frame/Image The chart is displayed on a Swing Frame or an image is created. Application Level ArchitectureThe application level architecture explains where JFreeChart library sits inside a Java Application.The client program receives user data and then it make use standard Java and JFreeChart APIs based on requirements to generate the output in the form of either a frame, which can be displayed directly inside the application or independently in the image formats such as JPEG or PNG.JFREECHART - PIE CHARTIn a pie chart, the arc length of each sector is proportional to the quantity it represents. This chapter demonstrates how we can use JFreeChart to create Pie Chart from a given set of business data.Business dataThe following example depicts mobile sale with the help of a pie chart. Following is a list of different mobile brands and their sale unitsperday.S.N.Mobile Brands Sales UNITSperday1Iphone 5S202Samsung Grand203MOTO G404Nokia Lumia10AWT Based ApplicationFollowing is the code to create Pie Chart from the above given information. This code helps you embed a pie chart in any AWT based application.import javax.swing.JPanel;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartPanel;import org.jfree.chart.JFreeChart;import org.jfree.data.general.DefaultPieDataset;import org.jfree.data.general.PieDataset;import org.jfree.ui.ApplicationFrame;import org.jfree.ui.RefineryUtilities;public class PieChart_AWT extends ApplicationFrame{public PieChart_AWT(String title ){super( title );setContentPane(createDemoPanel());}private static PieDataset createDataset(){DefaultPieDataset dataset =new DefaultPieDataset();dataset.setValue("IPhone 5s",new Double(20));dataset.setValue("SamSung Grand",new Double(20));dataset.setValue("MotoG",new Double(40));dataset.setValue("Nokia Lumia",new Double(10));return dataset;}private static JFreeChart createChart(PieDataset dataset ){JFreeChart chart =ChartFactory.createPieChart("Mobile Sales",// chart titledataset,// datatrue,// include legendtrue,false);return chart;}public static JPanel createDemoPanel(){JFreeChart chart = createChart(createDataset());return new ChartPanel( chart );}public static void main(String[] args ){PieChart_AWT demo =new PieChart_AWT("Mobile Sales");demo.setSize(560,367);RefineryUtilities.centerFrameOnScreen( demo );demo.setVisible(true);}}dataset,// datatrue,// include legendtrue,false);int width =640;/* Width of the image */int height =480;/* Height of the image */File pieChart =new File("PieChart.jpeg");ChartUtilities.saveChartAsJPEG( pieChart , chart , width , height );}}Let us keep the above Java code in PieChart.java file, and then compile and run it from command prompt as follows :$javac PieChart.java$java PieChartIf everything is fine , it will compile and run to create JPEG image file named PieChart.jpeg in your current directory.JFREECHART - BAR CHARTThis chapter demonstrates how we can use JFreeChart to create Bar Chart from a given set of business data.A bar chart uses different orientation horizontalorvertical bars to show comparisons in various categories. One axis domainaxis of the chart shows the specific domain being compared, and the other axis rangeaxis represents discrete values.Business DataThe following example depicts various car statistics with the help of a bar chart. Following is a list of car brands along with their different characteristics, which we will show using a bar chart :Car Speed User Rating Millage SafetyFiat 1.0 3.0 5.0 5.oAudi 5.0 6.010.0 4.0Ford 4.0 2.0 3.0 6.0AWT Based ApplicationFollowing is the code to create Bar Chart from the above given information. This code helps you embed a bar chart in any AWT based application.import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartPanel;import org.jfree.chart.JFreeChart;import org.jfree.chart.plot.PlotOrientation;import org.jfree.data.category.CategoryDataset;import org.jfree.data.category.DefaultCategoryDataset;import org.jfree.ui.ApplicationFrame;import org.jfree.ui.RefineryUtilities;public class BarChart_AWT extends ApplicationFrame{public BarChart_AWT(String applicationTitle ,String chartTitle ){super( applicationTitle );JFreeChart barChart =ChartFactory.createBarChart(chartTitle,"Category","Score",createDataset(),PlotOrientation.VERTICAL,true,true,false);ChartPanel chartPanel =new ChartPanel( barChart );chartPanel.setPreferredSize(new java.awt.Dimension(560,367));setContentPane( chartPanel );}private CategoryDataset createDataset(){final String fiat ="FIAT";final String audi ="AUDI";final String ford ="FORD";final String speed ="Speed";final String millage ="Millage";final String userrating ="User Rating";final String safety ="safety";final DefaultCategoryDataset dataset =new DefaultCategoryDataset();dataset.addValue(1.0, fiat , speed );dataset.addValue(3.0, fiat , userrating );dataset.addValue(5.0, fiat , millage );dataset.addValue(5.0, fiat , safety );dataset.addValue(5.0, audi , speed );dataset.addValue(6.0, audi , userrating );dataset.addValue(10.0, audi , millage );dataset.addValue(4.0, audi , safety );dataset.addValue(4.0, ford , speed );dataset.addValue(2.0, ford , userrating );dataset.addValue(3.0, ford , millage );dataset.addValue(6.0, ford , safety );return dataset;}public static void main(String[] args ){BarChart_AWT chart =new BarChart_AWT("Car Usage Statistics","Which car do you like?);chart.pack( );RefineryUtilities.centerFrameOnScreen( chart );chart.setVisible( true );}}Let us keep the above Java code in BarChart_AWT.java file, and then compile and run it from command prompt as follows :$javac BarChar_AWT.java$java BarChart_AWTIf everything is fine , it will compile and run to generate the following Bar Graph :JPEG Image CreationLet us re-write above example to generate a JPEG image from command line. import java.io.*;import org.jfree.chart.ChartFactory;import org.jfree.chart.JFreeChart;import org.jfree.chart.plot.PlotOrientation;import org.jfree.data.category.DefaultCategoryDataset;import org.jfree.chart.ChartUtilities;public class BarChart{public static void main(String[] args )throws Exception{final String fiat ="FIAT";final String audi ="AUDI";final String ford ="FORD";final String speed ="Speed";final String millage ="Millage";final String userrating ="User Rating";final String safety ="safety";final DefaultCategoryDataset dataset =new DefaultCategoryDataset();dataset.addValue(1.0, fiat , speed );dataset.addValue(3.0, fiat , userrating );dataset.addValue(5.0, fiat , millage );dataset.addValue(5.0, fiat , safety );dataset.addValue(5.0, audi , speed );dataset.addValue(6.0, audi , userrating );dataset.addValue(10.0, audi , millage );dataset.addValue(4.0, audi , safety );dataset.addValue(4.0, ford , speed );dataset.addValue(2.0, ford , userrating );dataset.addValue(3.0, ford , millage );dataset.addValue(6.0, ford , safety );JFreeChart barChart =ChartFactory.createBarChart("CAR USAGE STATIStICS","Category","Score",dataset,PlotOrientation.VERTICAL,true,true,false);int width =640;/* Width of the image */int height =480;/* Height of the image */File BarChart=new File("BarChart.jpeg");ChartUtilities.saveChartAsJPEG(BarChart, barChart , width , height );}}Let us keep the above Java code in BarChart.java file, and then compile and run it from command prompt as follows:$javac BarChart.java$java BarChartIf everything is fine , it will compile and run to create JPEG image file named BarChart.jpeg in your current directoryLoading [MathJax]/jax/output/HTML-CSS/jax.js。
JFreeChart快速入门(所有版本皆可)
三、创建图表对象JFreeChart CategoryDataset dataset = getDataSet(); JFreeChart jfreechart = ChartFactory.createBarChart3D(―图表标题”, ―目录轴的显 示标签", "数值轴的显示标签", dataset, PlotOrientation.VERTICAL, false, false, false); // 其中的八个参数分别代表:图形的标题、X 轴标题、Y 轴标题、 CategoryDataset // 类的实例对象、显示标题hart 核心类库详细介绍
四、Renderer对象 1.定义:Renderer 对象是图形的绘制单元。
JFreeChart 提供了两个接口 CategoryItemRenderer 和 XYItemRenderer 、 1 个抽 象类 AbstractRenderer 供具体的 Renderer 类实现,给出了将近 50 种具体实现类 。 在含有 Renderer 对象的 JFreeChart 对象中, Renderer 对象决定了JFreeChart对 象的显示方式。 例如:
饼状图相关的 Plot 对象( MultiplePiePlot 、 PiePlot 、 PiePlot3D 、 RingPlot ) 中都不含有 Renderer 对象、 DomainAxis 对象、 RangeAxis 对象。 一般来说, Datset 对象存储数据模型, Renderer 对象存储显示模型, Plot 对象 根据 Datset 对象、 Renderer 对象完成画图操作。
5.设置:
所有的 Plot 共有的:背景(背景颜色、背景图片、透明度等)、前景透明度、无 数据存在情况的设置(显示的字符内容、显示的字体、显示的 Paint )、放大缩 小比例的, 大部分 Plot 对象还有设置 Dataset 、设置 Renderer 对象操作。
JFreeChart使用教程(中文)
用JFreeChart增强JSP报表的用户体验JFreeChart是一组功能强大、灵活易用的Java绘图API,使用它可以生成多种通用性的报表,包括柱状图、饼图、曲线图、甘特图等。
它能够用在Swing和Web等中制作自定义的图表或报表,并且得到广泛的应用。
本文将通过引领读者学习在JFreeChart中饼图、柱状图和曲线图的进阶应用,来达到熟练使用JFreeChart的目的。
一.下载与环境配置1. 下载JFreeChartJFreeChart是开放源代码的免费软件,但是它的支持文档需要付费才能得到。
其下载地址为:/project/showfiles.php?g roup_id=15494,当前最新版本为1.0.6。
笔者下载的是1.0.6最新版。
说明:1)source目录:为jfreechart的源码目录;2)lib目录:为包目录,我们需要关注的包为jfreechart-1.0.6.ja r、gnujaxp.jar和jcommon-1.0.10.jar这三个包;3)根目录下的jfreechart-1.0.6-demo.jar是例子程序,大家双击后可看到其中有很多例子的运行结果。
2. 环境配置笔者的开发环境如下:JDK:1.5MyEclipse:5.1.1 GATomcat:5.5.28为了后续的“用JFreeChart创建基于Web的图表”的一个例子的展示,我们在MyEclipse中创建一个名为jfreechart的Web工程。
将下载的JFreeChart1.0.6下lib目录下的jar包拷贝到WebRoot/WEB-INF/lib目录下。
另外还需要在web.xml文件中增加如下配置:<servlet><servlet-name>DisplayChart</servlet-name><servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-clas s></servlet><servlet-mapping><servlet-name>DisplayChart</servlet-name><url-pattern>/DisplayChart</url-pattern></servlet-mapping>二.柱状图在WebRoot目录下建立bar目录,用来存放柱状图的各个例子。
JFreeChart入门教程
JFreeChart 是一组功能强大、灵活易用的Java绘图API,使用它可以生成多种通用性的报表,包括柱状图、饼图、曲线图、甘特图等。
它能够用在Swing 和Web等中制作自定义的图表或报表,并且得到广泛的应用。
本文将通过引领读者学习在JFreeChart中饼图、柱状图和曲线图的进阶应用,来达到熟练使用JFreeChart的目的。
一.下载与环境配置1. 下载JFreeChartJFreeChart是开放源代码的免费软件,但是它的支持文档需要付费才能得到。
其下载地址为:/projects/jfreechart/files/,当前最新版本为1.0.14。
笔者下载的是1.0.14最新版。
说明:1)source目录:为jfreechart的源码目录;2)lib目录:为包目录,我们需要关注的包为jfreechart-1.0.13.jar、gnujaxp.jar和jcommon-1.0.16.jar这三个包;3)根目录下的jfreechart-1.0.13-demo.jar是例子程序,大家双击后可看到其中有很多例子的运行结果。
2. 环境配置笔者的开发环境如下:JDK:1.6MyEclipse:6.6Tomcat:6.0.18为了后续的“用JFreeChart创建基于Web的图表”的一个例子的展示,我们在MyEclipse中创建一个名为jfreechart的Web工程。
将下载的JFreeChart1.0.14下lib目录下的jar包拷贝到WebRoot/WEB-INF/lib目录下。
另外还需要在web.xml文件中增加如下配置:<servlet><servlet-name>DisplayChart</servlet-name><servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class> </servlet><servlet-mapping><servlet-name>DisplayChart</servlet-name><url-pattern>/DisplayChart</url-pattern></servlet-mapping>参数介绍利用JF reeC ha rt插件生成动态统计图表的基本步骤如下:1.准备绘图时需要的相关属性2.创建Datas et对象3.创建JF reeC ha rt实例4.生成自定格式的图片J F r e e C h a r t核心简介:JF r e e Char t:图表对象。
Jfreechart开发文档
Jfreechart图形开发指南廊坊市大华夏神农信息技术有限公司2010年05月修订历史记录目录目录1.引言 (3)2.JFREECHART开发 (3)2.1绘制曲线图 (3)2.2绘制柱状图 (5)2.3绘制三维柱状图 (6)2.4绘制平面饼状图 (7)2.5绘制3D饼状图 (8)2.6绘制时序图 (9)2.7绘制甘特图 (11)3.依赖的JAR包 (13)1.引言JFreeChart是JAVA平台上的一个开放的图表绘制类库。
它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计。
JFreeChart可生成饼图(pie chart s)、柱状图(bar charts)、散点图(scatter plots)、时序图(time series)、甘特图(G antt charts)等等多种图表,并且可以产生PNG和JPEG格式的输出,还可以与PDF和EX CEL关联。
JFreeChart目前是最好的java图形解决方案,基本能够解决目前的图形方面的需求。
2.jfreechart开发2.1绘制曲线图工具类< LineChart >示例代码:图样:2.2绘制柱状图工具类<BarChart>示例代码:图样:2.3绘制三维柱状图工具类<BarChart>示例代码:图样:2.4绘制平面饼状图工具类<PieChart>示例代码:图样:2.5绘制3D饼状图工具类<PieChart3D>示例代码:图样:2.6绘制时序图工具类< TimeSeriesChart> 示例代码:图样:2.7绘制甘特图工具类< TimeSeriesChart> 示例代码:图样:3.依赖的jar包。
JFreeChat中文教程(入门篇)
dataset.addValue(200, null, "梨子");
dataset.addValue(300, null, "葡萄");
dataset.addValue(400, null, "香蕉");
dataset.addValue(500, null, "荔枝");
at sun.awt.Win32GraphicsEnvironment.makeScreenDevice(Win32GraphicsEnvironment.java:168)
at sun.java2d.SunGraphicsEnvironment.getScreenDevices(SunGraphicsEnvironment.java:240)
WWW的发展使得基于因特网的应用程序不再局限于静态或者简单的动态内容提
供。传统的一些以软件包形式发布应用程序例如报表系统等都在逐渐搬到因特网
上。但是这两者之间有着天壤之别,虽然对于数据获取、业务处理等方面基本类
似,但是最大的差别在于用户界面。为了能在web浏览器上显示要求用户界面使
用HTML以及图片的方式来展现数据,而传统的一些利用操作系统本身的控件来
三、使用JFreeChart生成各种样式的图表
四、将生成的图表移到浏览器上
高级主题
参考资料
关于作者
Java 专区中还有:
教学
工具与产品
代码与组件
所有文章
实用技巧
刘冬 (u@)
珠海市创我科技发展有限公司软件工程师
jfreechart 中文帮助文档
void setAntiAlias(boolean flag)字体模糊边界void setBackgroundImage(Image image)背景图片void setBackgroundImageAlignment(int alignment)背景图片对齐方式(参数常量在org.jfree.ui.Align 类中定义)void setBackgroundImageAlpha(float alpha)背景图片透明度(0.0~1.0)void setBackgroundPaint(Paint paint)背景色void setBorderPaint(Paint paint)边界线条颜色void setBorderStroke(Stroke stroke)边界线条笔触void setBorderVisible(boolean visible)边界线条是否可见TextTitle类:void setFont(Font font)标题字体void setPaint(Paint paint)标题字体颜色void setText(String text)标题内容StandardLegend(Legend)类:void setBackgroundPaint(Paint paint)图示背景色void setTitle(String title)图示标题内容void setTitleFont(Font font)图示标题字体void setBoundingBoxArcWidth(int arcWidth)图示边界圆角宽void setBoundingBoxArcHeight(int arcHeight)图示边界圆角高void setOutlinePaint(Paint paint)图示边界线条颜色void setOutlineStroke(Stroke stroke)图示边界线条笔触void setDisplaySeriesLines(boolean flag)图示项是否显示横线(折线图有效)void setDisplaySeriesShapes(boolean flag)图示项是否显示形状(折线图有效)void setItemFont(Font font)图示项字体void setItemPaint(Paint paint)图示项字体颜色void setAnchor(int anchor)图示在图表中的显示位置(参数常量在Legend类中定义)Axis类:void setVisible(boolean flag)坐标轴是否可见void setAxisLinePaint(Paint paint)坐标轴线条颜色(3D轴无效)void setAxisLineStroke(Stroke stroke)坐标轴线条笔触(3D轴无效)void setAxisLineVisible(boolean visible)坐标轴线条是否可见(3D轴无效)void setFixedDimension(double dimension)(用于复合表中对多坐标轴的设置)void setLabel(String label)坐标轴标题void setLabelFont(Font font)坐标轴标题字体void setLabelPaint(Paint paint)坐标轴标题颜色void setLabelAngle(double angle)`坐标轴标题旋转角度(纵坐标可以旋转)void setTickLabelFont(Font font)坐标轴标尺值字体void setTickLabelPaint(Paint paint)坐标轴标尺值颜色void setTickLabelsVisible(boolean flag)坐标轴标尺值是否显示void setTickMarkPaint(Paint paint)坐标轴标尺颜色void setTickMarkStroke(Stroke stroke)坐标轴标尺笔触void setTickMarksVisible(boolean flag)坐标轴标尺是否显示ValueAxis(Axis)类:文章转载自网管网:/pdb/java/200904/161114_2.htmlvoid setAutoRange(boolean auto)自动设置数据轴数据范围void setAutoRangeMinimumSize(double size)自动设置数据轴数据范围时数据范围的最小跨度void setAutoTickUnitSelection(boolean flag)数据轴的数据标签是否自动确定(默认为true)void setFixedAutoRange(double length)数据轴固定数据范围(设置100的话就是显示MAXV ALUE到MAXV ALUE-100那段数据范围)void setInverted(boolean flag)数据轴是否反向(默认为false)void setLowerMargin(double margin)数据轴下(左)边距void setUpperMargin(double margin)数据轴上(右)边距void setLowerBound(double min)数据轴上的显示最小值void setUpperBound(double max)数据轴上的显示最大值void setPositiveArrowVisible(boolean visible)是否显示正向箭头(3D轴无效)void setNegativeArrowVisible(boolean visible)是否显示反向箭头(3D轴无效)void setVerticalTickLabels(boolean flag)数据轴数据标签是否旋转到垂直void setStandardTickUnits(TickUnitSource source)数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)NumberAxis(ValueAxis)类:void setAutoRangeIncludesZero(boolean flag)是否强制在自动选择的数据范围中包含0void setAutoRangeStickyZero(boolean flag)是否强制在整个数据轴中包含0,即使0不在数据范围中void setNumberFormatOverride(NumberFormat formatter)数据轴数据标签的显示格式void setTickUnit(NumberTickUnit unit)数据轴的数据标签(需要将AutoTickUnitSelection设false)DateAxis(ValueAxis)类:void setMaximumDate(Date maximumDate)日期轴上的最小日期void setMinimumDate(Date minimumDate)日期轴上的最大日期void setRange(Date lower,Date upper)日期轴范围void setDateFormatOverride(DateFormat formatter)日期轴日期标签的显示格式void setTickUnit(DateTickUnit unit)日期轴的日期标签(需要将AutoTickUnitSelection设false)void setTickMarkPosition(DateTickMarkPosition position)日期标签位置(参数常量在org.jfree.chart.axis.DateTickMarkPosition类中定义)CategoryAxis(Axis)类:void setCategoryMargin(double margin)分类轴边距void setLowerMargin(double margin)分类轴下(左)边距void setUpperMargin(double margin)分类轴上(右)边距void setVerticalCategoryLabels(boolean flag)分类轴标题是否旋转到垂直void setMaxCategoryLabelWidthRatio(float ratio)分类轴分类标签的最大宽度AbstractRenderer类:void setItemLabelAnchorOffset(double offset)数据标签的与数据点的偏移void setItemLabelsVisible(boolean visible)数据标签是否可见void setItemLabelFont(Font font)数据标签的字体void setItemLabelPaint(Paint paint)数据标签的字体颜色void setItemLabelPosition(ItemLabelPosition position)数据标签位置void setPositiveItemLabelPosition(ItemLabelPosition position)正数标签位置void setNegativeItemLabelPosition(ItemLabelPosition position)负数标签位置void setOutLinePaint(Paint paint)图形边框的线条颜色void setOutLineStroke(Stroke stroke)图形边框的线条笔触void setPaint(Paint paint)所有分类图形的颜色void setShape(Shape shape)所有分类图形的形状(如折线图的点)void setStroke(Stroke stroke)所有分类图形的笔触(如折线图的线)void setSeriesItemLabelsVisible(int series,boolean visible)指定分类的数据标签是否可见void setSeriesItemLabelFont(int series,Font font)指定分类的数据标签的字体void setSeriesItemLabelPaint(int series,Paint paint)指定分类的数据标签的字体颜色void setSeriesItemLabelPosition(int series,ItemLabelPosition position)数据标签位置void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition position)正数标签位置void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition position)负数标签位置void setSeriesOutLinePaint(int series,Paint paint)指定分类的图形边框的线条颜色void setSeriesOutLineStroke(int series,Stroke stroke)指定分类的图形边框的线条笔触void setSeriesPaint(int series,Paint paint)指定分类图形的颜色void setSeriesShape(int series,Shape shape)指定分类图形的形状(如折线图的点)void setSeriesStroke(int series,Stroke stroke)指定分类图形的笔触(如折线图的线)AbstractCategoryItemRenderer(AbstractRenderer)类:void setLabelGenerator(CategoryLabelGenerator generator)数据标签的格式void setToolTipGenerator(CategoryToolTipGenerator generator)MAP中鼠标移上的显示格式void setItemURLGenerator(CategoryURLGenerator generator)MAP中钻取链接格式void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator)指定分类的数据标签的格式void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator)指定分类的MAP 中鼠标移上的显示格式void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator)指定分类的MAP 中钻取链接格式BarRenderer(AbstractCategoryItemRenderer)类:void setDrawBarOutline(boolean draw)是否画图形边框void setItemMargin(double percent)每个BAR之间的间隔void setMaxBarWidth(double percent)每个BAR的最大宽度void setMinimumBarLength(double min)最短的BAR长度,避免数值太小而显示不出void setPositiveItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的正数标签位置void setNegativeItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的负数标签位置BarRenderer3D(BarRenderer)类:void setWallPaint(Paint paint)3D坐标轴的墙体颜色StackedBarRenderer(BarRenderer)类:没有特殊的设置StackedBarRenderer3D(BarRenderer3D)类:没有特殊的设置GroupedStackedBarRenderer(StackedBarRenderer)类:void setSeriesToGroupMap(KeyToGroupMap map)将分类自由的映射成若干个组(KeyToGroupMap.mapKeyToGroup(series,group))LayeredBarRenderer(BarRenderer)类:void setSeriesBarWidth(int series,double width)设定每个分类的宽度(注意设置不要使某分类被覆盖)WaterfallBarRenderer(BarRenderer)类:void setFirstBarPaint(Paint paint)第一个柱图的颜色void setLastBarPaint(Paint paint)最后一个柱图的颜色void setPositiveBarPaint(Paint paint)正值柱图的颜色void setNegativeBarPaint(Paint paint)负值柱图的颜色IntervalBarRenderer(BarRenderer)类:需要传IntervalCategoryDataset作为数据源GanttBarRenderer(IntervalBarRenderer)类:void setCompletePaint(Paint paint)完成进度颜色void setIncompletePaint(Paint paint)未完成进度颜色void setStartPercent(double percent)设置进度条在整条中的起始位置(0.0~1.0)void setEndPercent(double percent)设置进度条在整条中的结束位置(0.0~1.0)StatisticBarRenderer(BarRenderer)类:需要传StatisticCategoryDataset作为数据源LineAndShapeRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean draw)是否折线的数据点之间用线连void setDrawShapes(boolean draw)是否折线的数据点根据分类使用不同的形状void setShapesFilled(boolean filled)所有分类是否填充数据点图形void setSeriesShapesFilled(int series,boolean filled)指定分类是否填充数据点图形void setUseFillPaintForShapeOutline(boolean use)指定是否填充数据点的Paint也被用于画数据点形状的边框LevelRenderer(AbstractCategoryItemRenderer)类:void setItemMargin(double percent)每个分类之间的间隔void setMaxItemWidth(double percent)每个分类的最大宽度CategoryStepRenderer(AbstractCategoryItemRenderer)类:void setStagger(boolean shouldStagger)不同分类的图是否交错MinMaxCategoryRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean drawLines)是否在每个分类线间画连接线void setGroupPaint(Paint groupPaint)一组图形连接线的颜色void setGroupStroke(Stroke groupStroke)一组图形连接线的笔触void setMaxIcon(Icon maxIcon)最大值的ICONvoid setMinIcon(Icon minIcon)最小值的ICONvoid setObjectIcon(Icon objectIcon)所有值的ICONAreaRender(AbstractCategoryItemRenderer)类:没有特殊的设置StackedAreaRender(AreaRender)类:没有特殊的设置关键就是用好Renderer这个类了,再贴个例子:String sFont = "宋体";chart.setBorderVisible(true);chart.setBorderPaint(new Color(0xFF,0x66,0x00));chart.setBackgroundPaint(new Color(0xFF,0xF3,0xDE));chart.getTitle().setPaint(Color.red);chart.getTitle().setFont(new Font(sFont,Font.BOLD,14));//设置Plot,不显示所有网格((CategoryPlot)chart.getPlot()).setOutlinePaint(null);((CategoryPlot)chart.getPlot()).setDomainGridlinesVisible(false);((CategoryPlot)chart.getPlot()).setRangeGridlinesVisible(false);//设置横轴字体,设定横轴轴线不可见,隐藏纵轴((CategoryPlot)chart.getPlot()).getDomainAxis().setTickLabelFont(new Font(sFont,Font.PLAIN,12));((CategoryPlot)chart.getPlot()).getDomainAxis().setAxisLineVisible(false);((CategoryPlot)chart.getPlot()).getRangeAxis().setVisible(false);//采用BarRenderer作为表示器BarRenderer renderer = new BarRenderer();renderer.setPaint(new GradientPaint(0.0f,0.0f,Color.orange,0.0f,0.0f,Color.yellow));renderer.setOutlinePaint(Color.orange);renderer.setDrawBarOutline(true);//在条中央显示投票数值renderer.setItemLabelAnchorOffset(-20.0f);renderer.setLabelGenerator(new StandardCategoryLabelGenerator("{2}",new DecimalFormat()));renderer.setPositiveItemLabelPosition(new ItemLabelPosition());renderer.setItemLabelsVisible(true);文章转载自网管网:/pdb/java/200904/161114_4.html文章转载自网管网:/pdb/java/200904/161114_3.html文章转载自网管网:/pdb/java/200904/161114_2.html。
JFreeChart 教程说明书
About the T utorialThis tutorial describes various ways to incorporate JFreeChart in Java-based standalone and web-based applications. The tutorial is categorized into various chapters to provide a comprehensive and easy understanding of JFreeChart programming with Java applications.AudienceThis reference has been prepared for beginners to help them understand the basic-to-advanced concepts related to JFreeChart library.PrerequisitesBefore you start practicing the examples given in the tutorial, it is expected that you have a basic understanding of Java programming with JDK1.6 or later versions, Swing, file management and database management in Java.Copyright & Disclaimer© Copyright 2017 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of the contents of this e-book in any manner without written consent of the publisher.We strive to update the contents of our website and tutorials as timely and as precisely as possibly; however, the contents may contain inaccuracies or errors. Tutorials Point (I) provides no guarantee regarding the accuracy, timeliness, or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at **************************T able of ContentsAbout the Tutorial (i)Audience (i)Prerequisites (i)Copyright & Disclaimer (i)Table of Contents .................................................................................................................................... i i 1.JFREECHART ─ OVERVIE W (1)What is JFreeChart? (1)Why JFreeChart? (1)2.JFREECHART ─ INSTALL ATION (2)System Requirements (2)Installing JFreeChart (2)3.JFREECHART ─ ARCHITE CTURE (6)Class Level Architecture (6)Application Level Architecture (7)4.JFREECHART ─ REFEREN CED APIS (8)ChartFactory Class (8)ChartFrame Class (9)ChartPanel Class (10)ChartUtilities Class (10)JFreeChart Class (11)PiePlot Class (12)PiePlot3D Class (12)PlotOrientation Class (13)XYPlot Class (14)XYLineAndShapeRenderer Class (15)XYItemRenderer general datasets (16)PieDataset (16)DefaultPieDataset Class (16)SeriesException Class (17)DefaultCategoryDataset (17)Series Datasets (18)XYDataset (18)XYZDataset (18)XYSeries (18)XYSeriesCollection (19)Default XYZDataset (20)Time Series in JFreeCharts (20)TimeSeriesCollection (21)Second (22)Frames in JFreeCharts (22)ApplicationFrame (23)RefineryUtilities (23)5.JFREECHART ─ PIE CHA RT (24)Business data (24)AWT Based Application (24)JPEG Image Creation (26)6.JFREECHART ─ BAR CHA RT (28)Business Data (28)AWT Based Application (28)7.JFREECHART ─ LINE CH ART (33)Business Data (33)AWT Based Application (33)JPEG Image Creation (35)8.JFREECHART ─ XY CHAR T (37)Business Data (37)AWT Based Application (38)JPEG Image Creation (40)9.JFREECHART ─ 3D PIE/BAR CHART (43)3D Pie chart (43)3D Bar Chart (45)10.JFREECHART ─ BUBBLE CHART (48)Business Data (48)AWT Based Application (48)JPEG Image Creation (51)11.JFREECHART ─ TIMESER IES CHART (54)Business Data (54)AWT Based Application (54)JPEG Image Creation (56)12.JFREECHART ─ FILE IN TERFACE (59)Business Data (59)Chart Generation Based on File (59)13.JFREECHART ─ DATABAS E INTERFACE (62)Business Data (62)Chart Generation Using Database (62)JFreeChart6A chart is a graphical representation of information. There are various tools available, which can be used to create different types of charts. The JFreeChart project was founded in February 2000, by David Gilbert. Today, it is the most widely used charting library among Java developers.This tutorial will help you understand what exactly JFreeChart is, why is it required, and the various ways to create different types of charts within a Java-based application or independently.What is JFreeChart?JfreeChart is an open source library developed in Java. It can be used within Java based applications to create a wide range of charts. By using JFreeChart, we can create all the major type of 2D and 3D charts such as pie chart, bar chart, line chart, XY chart and 3D charts. Why JFreeChart?JFreeChart is open source and 100% free, which permits usage in the commercial applications without any cost. We have enlisted here some more points in favor of why you should use JFreeChart:∙It comes with well documented APIs, which makes it quite easy to understand. ∙ It supports a wide range of chart types such as Pie Chart, Line Chart, Bar Chart, Area Chart and 3D charts.∙ JFreeChart is easy to extend and can be used in both, the client-side, as well as the server-side applications.∙ It supports multiple output formats like PNG, JPEG, PDF, SVG etc.∙It allows extensive customizations of charts. Consider a situation where you are developing an application and you need to show the data in the form of charts, and the data itself is populated dynamically. In such case, displaying the data in the form of charts using JFreeChart programming is very simple.1.JFreeChart 7JFreeChart is popular for its efficient chart creation and user-friendly installation setup. This chapter describes the process of setting up JFreeChart on Windows and Linux. User administration is needed while installing JFreeChart.System RequirementsInstalling JFreeChartTo install JFreeChart, there are three following steps viz …Step 1: Verifying Java InstallationTo verify Java installation, open the console and execute the following java command:2.Once Java installation is done properly, then you should get the following output for both the operating systems:If you do not have Java installed, then install the Java Software Development Kit (SDK) from the link:/technetwork/java/javase/downloads/index.htmlWe assume that you have installed Java 1.7.0_60 version before proceeding for this tutorial.Step 2: Setting JAVA EnvironmentSet the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example,Append Java compiler location to System Path.Verify the command java -version from the command prompted as explained above.Step 3: Installing JFreeChart8Download the latest version of JFreeChart.zip from the link /jfreechart/download/. Unzip the downloaded file at any location from where required libraries can be linked into your Java program. The following image shows the structure of the directories and files:Add complete path of jfreechart-1.0.18.jar and jcommon-1.0.22.jar files to the CLASSPATH as shown below:9JFreeChart10This chapter explains basic class level and application level architectures of JFreeChart to give you an idea about how JFreeChart interacts with different classes and how it fits in your Java based application.Class Level ArchitectureThe class level architecture explains how various classes from the library interact with each other to create various types of charts.Following is the detail of the units used in the above block diagram:3.JFreeChartApplication Level ArchitectureThe application level architecture explains where JFreeChart library sits inside a Java Application.The client program receives user data and then it uses standard Java and JFreeChart APIs based on requirements to generate the output in the form of either a frame, which can be displayed directly inside the application or independently in the image formats such as JPEG or PNG.11JFreeChart12In this chapter, we will discuss about some of the important packages, classes, and methods from JFreeChart library. These packages, classes, and methods are the most frequently used while creating a variety of charts using JFreeChart library.ChartFactory ClassChartFactory is an abstract class under the org.jfree.chart package. It provides a collection of utility methods for generating standard charts. Following is a list of few of the important methods:Class ConstructorClass Methods4.ChartFrame ClassChartFrame class under the org.jfree.chart package, provides all frame related functions and utilities. ChartFrame class inherits functionalities from parent classes such as Frame, Window, Container, and Component classes.13Class ConstructorClass MethodChartPanel ClassChartPanel class from the org.jfree.chart package is used as a swing GUI component for displaying JfreeChart object.Class Constructor14Class MethodChartUtilities ClassCharUtilites class from the org.jfree.chart package provides a collection of utility methods of JFreeCharts including methods for converting charts into image file format such as PNG, JPEG, and creating HTML image maps.Class ConstructorClass Method15JFreeChart ClassJFreeChart class is the core class under the org.jfree.chart package. This class provides JFreeChart method to create bar charts, line charts, pie charts, and xy plots including time series data.Class ConstructorClass MethodPiePlot ClassThis class is a part of org.jfree.chart.plot package and extends Plot class from the same package. This class provides methods to create Pie Plots.Class Constructor16Class MethodPiePlot3D ClassPiePlot3D class is a subclass of PiePlot class under the same package. Hence, this class has the same features as PiePlot class, except it is used to create 3D plots.Class ConstructorClass Method17PlotOrientation ClassThis is a serialized class available in org.jfree.chart.plot package and it is used to show the orientation of a 2D plot. The orientation can either be vertical or horizontal. It sets the orientation of Y-axis. A conventional plot has a vertical Y- axis.Field summaryClass MethodXYPlot ClassThis is a general class available in org.jfree.chart.plot package and it is used for the plotting data in the form of (x,y) pairs. This plot can use data from any other class that implements the XYDataSet Interface. XYPlot makes use of a XYItemRenderer to draw each point on the plot.1819Class ConstructorClass MethodNumberAxis ClassThis class is available in org.jfree.chart.axispackage and it can access the numerical data of any axis. When we set the range of any axis to default, it fits according to the range of the data. But using NumberAxis, class we can set the lower margin and upper margin of domain and range axes.Class ConstructorClass MethodXYLineAndShapeRenderer ClassThis is the class, available under org.jfree.chart.renderer.xy package, which takes care of connecting data points with lines and draws shapes at each data point. This renderer class is designed for use with the XYPlot class.Class ConstructorClass Method20XYItemRenderer general datasetsThis is an interface for rendering the format of a single (x, y) item on a XYPlot. The package is org.Jfree.data.general, which has classes and interfaces to define different types of datasets to construct charts.PieDatasetThis is an interface used as a general purpose dataset, where values are associated with keys. As the name suggests, you can use this dataset to supply data for pie charts. This interface extends KeyedValues and DataSet interfaces. All the methods used for this interface are taken from KeyedValues, Values, and Dataset interfaces.DefaultPieDataset ClassThis is a Default implementation class of a PieDataset interface.Class ConstructorClass Method21SeriesException ClassThis is an exception class. It raises an exception occurred in the time series of data in the dataset. Exceptions are raised on the occurrence of duplicate or invalid data. The time series must not be applied with duplicates and the format must be valid. DefaultCategoryDatasetThis is a default implementation class of CategoryDataset interface.Class ConstructorClass Method22Refer JFreeChart API for more information on various other methods and fields.Series DatasetsThe series dataset is used by XY charts. The package is org.Jfree.data.xy, which contains classes and interfaces belonging to xy charts. The core interface is XYDataset. XYDatasetThis is an interface through which data in the form of (x,y) items can be accessed. As the name suggests, you can use this dataset to serve XY chart. Some of the methods in this interface are taken from SeriesDateset interface.XYZDatasetThis is an interface through which data in the form of (x,y,z) items can be accessed. As the name suggests, you can use this dataset to serve XYZ chart. Some of the methods in this interface are taken from SeriesDateset.XYSeriesThis is a class, which represents a sequence of zero or more data items in the form (x, y). By default, the items in the series are sorted into ascending order by x-value, and duplicate x-values are permitted. Both the sorting and duplicate defaults can be changed in the constructor. Y-values can be denoted as null to represent missing values.Class Constructor23Class MethodThe above method is used in the tutorial example. If you want to learn the remaining methods and fields, please refer JFreeChart API.XYSeriesCollectionXYSeriesCollection class has parent classes like AbstractIntervelDataset, AbstractXYDatset, AbstractSeriesDataset and AbstractDataset. Some of the methods in this class belong to parent classes of this class.Class ConstructorClass Method2425Refer JFreeChart API for the remaining methods and fields.Default XYZDatasetDefaultXYZDataset class have parent classes like AbstractIntervelDataset, AbstractXYDatset, AbstractSeriesDataset, AbstractDataset and AbstractXYZDataset. Some of the methods in this class belong to parent classes of this class.Class ConstructorClass MethodPlease refer JFreeChart API for the remaining methods and fields.Time Series in JFreeChartsThe package is org.jfree.data.time . This package contains classes and interfaces, which are used for the time related data.TimeSeriesThis class represents a sequence of data items in the form of period values, where period is some instance ofRegularTimePeriod abstract class such as Time, Day, Hour, Minute, and Second classes.Class ConstructorClass MethodRefer JFreeChart API for the remaining methods and fields.TimeSeriesCollectionThis is a class used as a collection of time series objects. This class implements the XYDataset interface, as well as it extends IntervelXYDataset interface. This makes it convenient to collect series data objects.Class ConstructorClass Method26Please refer JFreeChart API for the remaining methods and fields.SecondThis class represents a second in a particular day. This class is immutable, which is a requirement for all RegularTimePeriod subclass.Class ConstructorClass Method27Please refer JFreeChart API for the remaining methods and fields.Frames in JFreeChartsThe package is org.jfree.ui. This is the package belongs to JCommons API of JFreeChart. It contains utility classes used for creating frames for pre-configured charts. ApplicationFrameThis is a base class for creating the main frame for simple applications. The frame listens for window closing events, and responds by shutting down the JVM. This is fine for small demo applications. For enterprise applications, you need to use something more robust. The main core methods in this class are taken from Component, Container, Window, Frame, and Jframe classes.Class ConstructorThis class helps to create AWT Frames. This is the reason for why we use this class as super class in this tutorial examples.The methods, which are taken form the parent classes are used for opening a frame, closinga frame, changing the size, changing the background or foreground color, and listeners.28RefineryUtilitiesThis is a class collection of utility methods relating to user interface.Class MethodThe above method is used in the tutorial example. Refer JFreeChart API for remaining methods and fields.29JFreeChartEnd of ebook previewIf you liked what you saw…Buy it from our store @ https://30。
JfreeChar中文手册
JFreeChart中文手册JFreeChart类:void setAntiAlias(boolean flag) 字体模糊边界void setBackgroundImage(Image image) 背景图片void setBackgroundImageAlignment(int alignment) 背景图片对齐方式(参数常量在org.jfree.ui.Align类中定义)void setBackgroundImageAlpha(float alpha) 背景图片透明度(0.0~1.0)void setBackgroundPaint(Paint paint) 背景色void setBorderPaint(Paint paint) 边界线条颜色void setBorderStroke(Stroke stroke) 边界线条笔触void setBorderVisible(boolean visible) 边界线条是否可见-----------------------------------------------------------------------------------------------------------TextTitle类:void setFont(Font font) 标题字体void setPaint(Paint paint) 标题字体颜色void setText(String text) 标题内容-----------------------------------------------------------------------------------------------------------StandardLegend(Legend)类:void setBackgroundPaint(Paint paint) 图示背景色void setTitle(String title) 图示标题内容void setTitleFont(Font font) 图示标题字体void setBoundingBoxArcWidth(int arcWidth) 图示边界圆角宽void setBoundingBoxArcHeight(int arcHeight) 图示边界圆角高void setOutlinePaint(Paint paint) 图示边界线条颜色void setOutlineStroke(Stroke stroke) 图示边界线条笔触void setDisplaySeriesLines(boolean flag) 图示项是否显示横线(折线图有效)void setDisplaySeriesShapes(boolean flag) 图示项是否显示形状(折线图有效)void setItemFont(Font font) 图示项字体void setItemPaint(Paint paint) 图示项字体颜色void setAnchor(int anchor) 图示在图表中的显示位置(参数常量在Legend 类中定义)-----------------------------------------------------------------------------------------------------------Axis类:void setVisible(boolean flag) 坐标轴是否可见void setAxisLinePaint(Paint paint) 坐标轴线条颜色(3D轴无效)void setAxisLineStroke(Stroke stroke) 坐标轴线条笔触(3D轴无效)void setAxisLineVisible(boolean visible) 坐标轴线条是否可见(3D轴无效)void setFixedDimension(double dimension) (用于复合表中对多坐标轴的设置)void setLabel(String label) 坐标轴标题void setLabelFont(Font font) 坐标轴标题字体void setLabelPaint(Paint paint) 坐标轴标题颜色void setLabelAngle(double angle)` 坐标轴标题旋转角度(纵坐标可以旋转)void setTickLabelFont(Font font) 坐标轴标尺值字体void setTickLabelPaint(Paint paint) 坐标轴标尺值颜色void setTickLabelsVisible(boolean flag) 坐标轴标尺值是否显示void setTickMarkPaint(Paint paint) 坐标轴标尺颜色void setTickMarkStroke(Stroke stroke) 坐标轴标尺笔触void setTickMarksVisible(boolean flag) 坐标轴标尺是否显示ValueAxis(Axis)类:void setAutoRange(boolean auto) 自动设置数据轴数据范围void setAutoRangeMinimumSize(double size) 自动设置数据轴数据范围时数据范围的最小跨度void setAutoTickUnitSelection(boolean flag) 数据轴的数据标签是否自动确定(默认为true)void setFixedAutoRange(double length) 数据轴固定数据范围(设置100的话就是显示MAXVALUE到MAXVALUE-100那段数据范围)void setInverted(boolean flag) 数据轴是否反向(默认为false)void setLowerMargin(double margin) 数据轴下(左)边距void setUpperMargin(double margin) 数据轴上(右)边距void setLowerBound(double min) 数据轴上的显示最小值void setUpperBound(double max) 数据轴上的显示最大值void setPositiveArrowVisible(boolean visible) 是否显示正向箭头(3D轴无效)void setNegativeArrowVisible(boolean visible) 是否显示反向箭头(3D轴无效)void setVerticalTickLabels(boolean flag) 数据轴数据标签是否旋转到垂直void setStandardTickUnits(TickUnitSource source) 数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)NumberAxis(ValueAxis)类:void setAutoRangeIncludesZero(boolean flag) 是否强制在自动选择的数据范围中包含0void setAutoRangeStickyZero(boolean flag) 是否强制在整个数据轴中包含0,即使0不在数据范围中void setNumberFormatOverride(NumberFormat formatter) 数据轴数据标签的显示格式void setTickUnit(NumberTickUnit unit) 数据轴的数据标签(需要将AutoTickUnitSelection设false)DateAxis(ValueAxis)类:void setMaximumDate(Date maximumDate) 日期轴上的最小日期void setMinimumDate(Date minimumDate) 日期轴上的最大日期void setRange(Date lower,Date upper) 日期轴范围void setDateFormatOverride(DateFormat formatter) 日期轴日期标签的显示格式void setTickUnit(DateTickUnit unit) 日期轴的日期标签(需要将AutoTickUnitSelection设false)void setTickMarkPosition(DateTickMarkPosition position) 日期标签位置(参数常量在org.jfree.chart.axis.DateTickMarkPosition类中定义)CategoryAxis(Axis)类:void setCategoryMargin(double margin) 分类轴边距void setLowerMargin(double margin) 分类轴下(左)边距void setUpperMargin(double margin) 分类轴上(右)边距void setVerticalCategoryLabels(boolean flag) 分类轴标题是否旋转到垂直void setMaxCategoryLabelWidthRatio(float ratio) 分类轴分类标签的最大宽度-----------------------------------------------------------------------------------------------------------Plot类:void setBackgroundImage(Image image) 数据区的背景图片void setBackgroundImageAlignment(int alignment) 数据区的背景图片对齐方式(参数常量在org.jfree.ui.Align类中定义)void setBackgroundPaint(Paint paint) 数据区的背景图片背景色void setBackgroundAlpha(float alpha) 数据区的背景透明度(0.0~1.0)void setForegroundAlpha(float alpha) 数据区的前景透明度(0.0~1.0)void setDataAreaRatio(double ratio) 数据区占整个图表区的百分比void setOutLinePaint(Paint paint) 数据区的边界线条颜色void setOutLineStroke(Stroke stroke) 数据区的边界线条笔触void setNoDataMessage(String message) 没有数据时显示的消息void setNoDataMessageFont(Font font) 没有数据时显示的消息字体void setNoDataMessagePaint(Paint paint) 没有数据时显示的消息颜色CategoryPlot(Plot)类:void setDataset(CategoryDataset dataset) 数据区的2维数据表void setColumnRenderingOrder(SortOrder order) 数据分类的排序方式void setAxisOffset(Spacer offset) 坐标轴到数据区的间距void setOrientation(PlotOrientation orientation) 数据区的方向(PlotOrientation.HORIZONTAL或PlotOrientation.VERTICAL)void setDomainAxis(CategoryAxis axis) 数据区的分类轴void setDomainAxisLocation(AxisLocation location) 分类轴的位置(参数常量在org.jfree.chart.axis.AxisLocation类中定义)void setDomainGridlinesVisible(boolean visible) 分类轴网格是否可见void setDomainGridlinePaint(Paint paint) 分类轴网格线条颜色void setDomainGridlineStroke(Stroke stroke) 分类轴网格线条笔触void setRangeAxis(ValueAxis axis) 数据区的数据轴void setRangeAxisLocation(AxisLocation location) 数据轴的位置(参数常量在org.jfree.chart.axis.AxisLocation类中定义)void setRangeGridlinesVisible(boolean visible) 数据轴网格是否可见void setRangeGridlinePaint(Paint paint) 数据轴网格线条颜色void setRangeGridlineStroke(Stroke stroke) 数据轴网格线条笔触void setRenderer(CategoryItemRenderer renderer) 数据区的表示者(详见Renderer组)void addAnnotation(CategoryAnnotation annotation) 给数据区加一个注释void addRangeMarker(Marker marker,Layer layer) 给数据区加一个数值范围区域PiePlot(Plot)类:void setDataset(PieDataset dataset) 数据区的1维数据表void setIgnoreNullValues(boolean flag) 忽略无值的分类void setCircular(boolean flag) 饼图是否一定是正圆void setStartAngle(double angle) 饼图的初始角度void setDirection(Rotation direction) 饼图的旋转方向void setExplodePercent(int section,double percent) 抽取的那块(1维数据表的分类下标)以及抽取出来的距离(0.0~1.0),3D饼图无效void setLabelBackgroundPaint(Paint paint) 分类标签的底色void setLabelFont(Font font) 分类标签的字体void setLabelPaint(Paint paint) 分类标签的字体颜色void setLabelLinkMargin(double margin) 分类标签与图的连接线边距void setLabelLinkPaint(Paint paint) 分类标签与图的连接线颜色void setLabelLinkStroke(Stroke stroke) 分类标签与图的连接线笔触void setLabelOutlinePaint(Paint paint) 分类标签边框颜色void setLabelOutlineStroke(Paint paint) 分类标签边框笔触void setLabelShadowPaint(Paint paint) 分类标签阴影颜色void setMaximumLabelWidth(double width) 分类标签的最大长度(0.0~1.0)void setPieIndex(int index) 饼图的索引(复合饼图中用到)void setSectionOutlinePaint(int section,Paint paint) 指定分类饼的边框颜色void setSectionOutlineStroke(int section,Stroke stroke) 指定分类饼的边框笔触void setSectionPaint(int section,Paint paint) 指定分类饼的颜色void setShadowPaint(Paint paint) 饼图的阴影颜色void setShadowXOffset(double offset) 饼图的阴影相对图的水平偏移void setShadowYOffset(double offset) 饼图的阴影相对图的垂直偏移void setLabelGenerator(PieSectionLabelGenerator generator) 分类标签的格式,设置成null则整个标签包括连接线都不显示void setToolTipGenerator(PieToolTipGenerator generator) MAP中鼠标移上的显示格式void setURLGenerator(PieURLGenerator generator) MAP中钻取链接格式PiePlot3D(PiePlot)类:void setDepthFactor(double factor) 3D饼图的Z轴高度(0.0~1.0)MultiplePiePlot(Plot)类:void setLimit(double limit) 每个饼图之间的数据关联(详细比较复杂)void setPieChart(JFreeChart pieChart) 每个饼图的显示方式(见JFreeChart类个PiePlot类)-----------------------------------------------------------------------------------------------------------AbstractRenderer类:void setItemLabelAnchorOffset(double offset) 数据标签的与数据点的偏移void setItemLabelsVisible(boolean visible) 数据标签是否可见void setItemLabelFont(Font font) 数据标签的字体void setItemLabelPaint(Paint paint) 数据标签的字体颜色void setItemLabelPosition(ItemLabelPosition position) 数据标签位置void setPositiveItemLabelPosition(ItemLabelPosition position) 正数标签位置void setNegativeItemLabelPosition(ItemLabelPosition position) 负数标签位置void setOutLinePaint(Paint paint) 图形边框的线条颜色void setOutLineStroke(Stroke stroke) 图形边框的线条笔触void setPaint(Paint paint) 所有分类图形的颜色void setShape(Shape shape) 所有分类图形的形状(如折线图的点)void setStroke(Stroke stroke) 所有分类图形的笔触(如折线图的线)void setSeriesItemLabelsVisible(int series,boolean visible) 指定分类的数据标签是否可见void setSeriesItemLabelFont(int series,Font font) 指定分类的数据标签的字体void setSeriesItemLabelPaint(int series,Paint paint) 指定分类的数据标签的字体颜色void setSeriesItemLabelPosition(int series,ItemLabelPosition position) 数据标签位置void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition position) 正数标签位置void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition position) 负数标签位置void setSeriesOutLinePaint(int series,Paint paint) 指定分类的图形边框的线条颜色void setSeriesOutLineStroke(int series,Stroke stroke) 指定分类的图形边框的线条笔触void setSeriesPaint(int series,Paint paint) 指定分类图形的颜色void setSeriesShape(int series,Shape shape) 指定分类图形的形状(如折线图的点)void setSeriesStroke(int series,Stroke stroke) 指定分类图形的笔触(如折线图的线)AbstractCategoryItemRenderer(AbstractRenderer)类:void setLabelGenerator(CategoryLabelGenerator generator) 数据标签的格式void setToolTipGenerator(CategoryToolTipGenerator generator) MAP中鼠标移上的显示格式void setItemURLGenerator(CategoryURLGenerator generator) MAP中钻取链接格式void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator) 指定分类的数据标签的格式void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator) 指定分类的MAP中鼠标移上的显示格式void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator) 指定分类的MAP中钻取链接格式BarRenderer(AbstractCategoryItemRenderer)类:void setDrawBarOutline(boolean draw) 是否画图形边框void setItemMargin(double percent) 每个BAR之间的间隔void setMaxBarWidth(double percent) 每个BAR的最大宽度void setMinimumBarLength(double min) 最短的BAR长度,避免数值太小而显示不出void setPositiveItemLabelPositionFallback(ItemLabelPosition position) 无法在BAR中显示的正数标签位置void setNegativeItemLabelPositionFallback(ItemLabelPosition position) 无法在BAR中显示的负数标签位置BarRenderer3D(BarRenderer)类:void setWallPaint(Paint paint) 3D坐标轴的墙体颜色StackedBarRenderer(BarRenderer)类:没有特殊的设置StackedBarRenderer3D(BarRenderer3D)类:没有特殊的设置GroupedStackedBarRenderer(StackedBarRenderer)类:void setSeriesToGroupMap(KeyToGroupMap map) 将分类自由的映射成若干个组(KeyToGroupMap.mapKeyToGroup(series,group))LayeredBarRenderer(BarRenderer)类:void setSeriesBarWidth(int series,double width) 设定每个分类的宽度(注意设置不要使某分类被覆盖)WaterfallBarRenderer(BarRenderer)类:void setFirstBarPaint(Paint paint) 第一个柱图的颜色void setLastBarPaint(Paint paint) 最后一个柱图的颜色void setPositiveBarPaint(Paint paint) 正值柱图的颜色void setNegativeBarPaint(Paint paint) 负值柱图的颜色IntervalBarRenderer(BarRenderer)类:需要传IntervalCategoryDataset作为数据源GanttBarRenderer(IntervalBarRenderer)类:void setCompletePaint(Paint paint) 完成进度颜色void setIncompletePaint(Paint paint) 未完成进度颜色void setStartPercent(double percent) 设置进度条在整条中的起始位置(0.0~1.0)void setEndPercent(double percent) 设置进度条在整条中的结束位置(0.0~1.0)StatisticBarRenderer(BarRenderer)类:需要传StatisticCategoryDataset作为数据源LineAndShapeRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean draw) 是否折线的数据点之间用线连void setDrawShapes(boolean draw) 是否折线的数据点根据分类使用不同的形状void setShapesFilled(boolean filled) 所有分类是否填充数据点图形void setSeriesShapesFilled(int series,boolean filled) 指定分类是否填充数据点图形void setUseFillPaintForShapeOutline(boolean use) 指定是否填充数据点的Paint也被用于画数据点形状的边框LevelRenderer(AbstractCategoryItemRenderer)类:void setItemMargin(double percent) 每个分类之间的间隔void setMaxItemWidth(double percent) 每个分类的最大宽度CategoryStepRenderer(AbstractCategoryItemRenderer)类:void setStagger(boolean shouldStagger) 不同分类的图是否交错MinMaxCategoryRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean drawLines) 是否在每个分类线间画连接线void setGroupPaint(Paint groupPaint) 一组图形连接线的颜色void setGroupStroke(Stroke groupStroke) 一组图形连接线的笔触void setMaxIcon(Icon maxIcon) 最大值的ICONvoid setMinIcon(Icon minIcon) 最小值的ICONvoid setObjectIcon(Icon objectIcon) 所有值的ICONAreaRender(AbstractCategoryItemRenderer)类:没有特殊的设置StackedAreaRender(AreaRender)类:没有特殊的设置。
JFreeChart API中文文档
JFreeChart API中文文档JFreeChart目前是最好的java图形解决方案,基本能够解决目前的图形方面的需求,主要包括如下几个方面:JFreeChart类:void setAntiAlias(boolean flag)字体模糊边界void setBackgroundImage(Image image)背景图片void setBackgroundImageAlignment(int alignment)背景图片对齐方式(参数常量在org.jfree.ui.Align类中定义)void setBackgroundImageAlpha(float alpha)背景图片透明度(0.0~1.0)void setBackgroundPaint(Paint paint)背景色void setBorderPaint(Paint paint)边界线条颜色void setBorderStroke(Stroke stroke)边界线条笔触void setBorderVisible(boolean visible)边界线条是否可见TextTitle类:void setFont(Font font)标题字体void setPaint(Paint paint)标题字体颜色void setText(String text)标题内容StandardLegend(Legend)类:void setBackgroundPaint(Paint paint)图示背景色void setTitle(String title)图示标题内容void setTitleFont(Font font)图示标题字体void setBoundingBoxArcWidth(int arcWidth)图示边界圆角宽void setBoundingBoxArcHeight(int arcHeight)图示边界圆角高void setOutlinePaint(Paint paint)图示边界线条颜色void setOutlineStroke(Stroke stroke)图示边界线条笔触void setDisplaySeriesLines(boolean flag)图示项是否显示横线(折线图有效)void setDisplaySeriesShapes(boolean flag)图示项是否显示形状(折线图有效)void setItemFont(Font font)图示项字体void setItemPaint(Paint paint)图示项字体颜色void setAnchor(int anchor)图示在图表中的显示位置(参数常量在Legend类中定义)Axis类:void setVisible(boolean flag)坐标轴是否可见void setAxisLinePaint(Paint paint)坐标轴线条颜色(3D轴无效)void setAxisLineStroke(Stroke stroke)坐标轴线条笔触(3D 轴无效)void setAxisLineVisible(boolean visible)坐标轴线条是否可见(3D轴无效)void setFixedDimension(double dimension)(用于复合表中对多坐标轴的设置)void setLabel(String label)坐标轴标题void setLabelFont(Font font)坐标轴标题字体void setLabelPaint(Paint paint)坐标轴标题颜色void setLabelAngle(double angle)`坐标轴标题旋转角度(纵坐标可以旋转)void setTickLabelFont(Font font)坐标轴标尺值字体void setTickLabelPaint(Paint paint)坐标轴标尺值颜色void setTickLabelsVisible(boolean flag)坐标轴标尺值是否显示void setTickMarkPaint(Paint paint)坐标轴标尺颜色void setTickMarkStroke(Stroke stroke)坐标轴标尺笔触void setTickMarksVisible(boolean flag)坐标轴标尺是否显示ValueAxis(Axis)类:void setAutoRange(boolean auto)自动设置数据轴数据范围void setAutoRangeMinimumSize(double size)自动设置数据轴数据范围时数据范围的最小跨度void setAutoTickUnitSelection(boolean flag)数据轴的数据标签是否自动确定(默认为true)void setFixedAutoRange(double length)数据轴固定数据范围(设置100的话就是显示MAXVALUE到MAXVALUE-100那段数据范围)void setInverted(boolean flag)数据轴是否反向(默认为false)void setLowerMargin(double margin)数据轴下(左)边距void setUpperMargin(double margin)数据轴上(右)边距void setLowerBound(double min)数据轴上的显示最小值void setUpperBound(double max)数据轴上的显示最大值void setPositiveArrowVisible(boolean visible)是否显示正向箭头(3D轴无效)void setNegativeArrowVisible(boolean visible)是否显示反向箭头(3D轴无效)void setVerticalTickLabels(boolean flag)数据轴数据标签是否旋转到垂直void setStandardTickUnits(TickUnitSource source)数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)NumberAxis(ValueAxis)类:void setAutoRangeIncludesZero(boolean flag)是否强制在自动选择的数据范围中包含0void setAutoRangeStickyZero(boolean flag)是否强制在整个数据轴中包含0,即使0不在数据范围中void setNumberFormatOverride(NumberFormat formatter)数据轴数据标签的显示格式void setTickUnit(NumberTickUnit unit)数据轴的数据标签(需要将AutoTickUnitSelection设false)DateAxis(ValueAxis)类:void setMaximumDate(Date maximumDate)日期轴上的最小日期void setMinimumDate(Date minimumDate)日期轴上的最大日期void setRange(Date lower,Date upper)日期轴范围void setDateFormatOverride(DateFormat formatter)日期轴日期标签的显示格式void setTickUnit(DateTickUnit unit)日期轴的日期标签(需要将AutoTickUnitSelection设false)void setTickMarkPosition(DateTickMarkPosition position)日期标签位置(参数常量在org.jfree.chart.axis.DateTickMarkPosition类中定义)CategoryAxis(Axis)类:void setCategoryMargin(double margin)分类轴边距void setLowerMargin(double margin)分类轴下(左)边距void setUpperMargin(double margin)分类轴上(右)边距void setVerticalCategoryLabels(boolean flag)分类轴标题是否旋转到垂直void setMaxCategoryLabelWidthRatio(float ratio)分类轴分类标签的最大宽度AbstractRenderer类:void setItemLabelAnchorOffset(double offset)数据标签的与数据点的偏移void setItemLabelsVisible(boolean visible)数据标签是否可见void setItemLabelFont(Font font)数据标签的字体void setItemLabelPaint(Paint paint)数据标签的字体颜色void setItemLabelPosition(ItemLabelPosition position)数据标签位置void setPositiveItemLabelPosition(ItemLabelPosition position)正数标签位置void setNegativeItemLabelPosition(ItemLabelPosition position)负数标签位置void setOutLinePaint(Paint paint)图形边框的线条颜色void setOutLineStroke(Stroke stroke)图形边框的线条笔触void setPaint(Paint paint)所有分类图形的颜色void setShape(Shape shape)所有分类图形的形状(如折线图的点)void setStroke(Stroke stroke)所有分类图形的笔触(如折线图的线)void setSeriesItemLabelsVisible(int series,boolean visible)指定分类的数据标签是否可见void setSeriesItemLabelFont(int series,Font font)指定分类的数据标签的字体void setSeriesItemLabelPaint(int series,Paint paint)指定分类的数据标签的字体颜色void setSeriesItemLabelPosition(intseries,ItemLabelPosition position)数据标签位置void setSeriesPositiveItemLabelPosition(intseries,ItemLabelPosition position)正数标签位置void setSeriesNegativeItemLabelPosition(intseries,ItemLabelPosition position)负数标签位置void setSeriesOutLinePaint(int series,Paint paint)指定分类的图形边框的线条颜色void setSeriesOutLineStroke(int series,Stroke stroke)指定分类的图形边框的线条笔触void setSeriesPaint(int series,Paint paint)指定分类图形的颜色void setSeriesShape(int series,Shape shape)指定分类图形的形状(如折线图的点)void setSeriesStroke(int series,Stroke stroke)指定分类图形的笔触(如折线图的线)AbstractCategoryItemRenderer(AbstractRenderer)类:void setLabelGenerator(CategoryLabelGenerator generator)数据标签的格式void setToolTipGenerator(CategoryToolTipGenerator generator)MAP中鼠标移上的显示格式void setItemURLGenerator(CategoryURLGenerator generator)MAP中钻取链接格式void setSeriesLabelGenerator(intseries,CategoryLabelGenerator generator)指定分类的数据标签的格式void setSeriesToolTipGenerator(intseries,CategoryToolTipGenerator generator)指定分类的MAP中鼠标移上的显示格式void setSeriesItemURLGenerator(intseries,CategoryURLGenerator generator)指定分类的MAP 中钻取链接格式BarRenderer(AbstractCategoryItemRenderer)类:void setDrawBarOutline(boolean draw)是否画图形边框void setItemMargin(double percent)每个BAR之间的间隔void setMaxBarWidth(double percent)每个BAR的最大宽度void setMinimumBarLength(double min)最短的BAR长度,避免数值太小而显示不出voidsetPositiveItemLabelPositionFallback(ItemLabelPositionposition)无法在BAR中显示的正数标签位置voidsetNegativeItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的负数标签位置BarRenderer3D(BarRenderer)类:void setWallPaint(Paint paint)3D坐标轴的墙体颜色StackedBarRenderer(BarRenderer)类:没有特殊的设置StackedBarRenderer3D(BarRenderer3D)类:没有特殊的设置GroupedStackedBarRenderer(StackedBarRenderer)类:void setSeriesToGroupMap(KeyToGroupMap map)将分类自由的映射成若干个组(KeyToGroupMap.mapKeyToGroup(series,group))LayeredBarRenderer(BarRenderer)类:void setSeriesBarWidth(int series,double width)设定每个分类的宽度(注意设置不要使某分类被覆盖)WaterfallBarRenderer(BarRenderer)类:void setFirstBarPaint(Paint paint)第一个柱图的颜色void setLastBarPaint(Paint paint)最后一个柱图的颜色void setPositiveBarPaint(Paint paint)正值柱图的颜色void setNegativeBarPaint(Paint paint)负值柱图的颜色IntervalBarRenderer(BarRenderer)类:需要传IntervalCategoryDataset作为数据源GanttBarRenderer(IntervalBarRenderer)类:void setCompletePaint(Paint paint)完成进度颜色void setIncompletePaint(Paint paint)未完成进度颜色void setStartPercent(double percent)设置进度条在整条中的起始位置(0.0~1.0)void setEndPercent(double percent)设置进度条在整条中的结束位置(0.0~1.0)StatisticBarRenderer(BarRenderer)类:需要传StatisticCategoryDataset作为数据源LineAndShapeRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean draw)是否折线的数据点之间用线连void setDrawShapes(boolean draw)是否折线的数据点根据分类使用不同的形状void setShapesFilled(boolean filled)所有分类是否填充数据点图形void setSeriesShapesFilled(int series,boolean filled)指定分类是否填充数据点图形void setUseFillPaintForShapeOutline(boolean use)指定是否填充数据点的Paint也被用于画数据点形状的边框LevelRenderer(AbstractCategoryItemRenderer)类:void setItemMargin(double percent)每个分类之间的间隔void setMaxItemWidth(double percent)每个分类的最大宽度CategoryStepRenderer(AbstractCategoryItemRenderer)类:void setStagger(boolean shouldStagger)不同分类的图是否交错MinMaxCategoryRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean drawLines)是否在每个分类线间画连接线void setGroupPaint(Paint groupPaint)一组图形连接线的颜色void setGroupStroke(Stroke groupStroke)一组图形连接线的笔触void setMaxIcon(Icon maxIcon)最大值的ICONvoid setMinIcon(Icon minIcon)最小值的ICONvoid setObjectIcon(Icon objectIcon)所有值的ICONAreaRender(AbstractCategoryItemRenderer)类:没有特殊的设置StackedAreaRender(AreaRender)类:没有特殊的设置关键就是用好Renderer这个类了,再贴个例子:String sFont = "宋体"; chart.setBorderVisible(true); chart.setBorderPaint(new Color(0xFF,0x66,0x00)); chart.setBackgroundPaint(new Color(0xFF,0xF3,0xDE)); chart.getTitle().setPaint(Color.red);chart.getTitle().setFont(new Font(sFont,Font.BOLD,14)); //设置Plot,不显示所有网格((CategoryPlot)chart.getPlot()).setOutlinePaint(null); ((CategoryPlot)chart.getPlot()).setDomainGridlinesVisible(f alse);((CategoryPlot)chart.getPlot()).setRangeGridlinesVisible(f alse); //设置横轴字体,设定横轴轴线不可见,隐藏纵轴((CategoryPlot)chart.getPlot()).getDomainAxis().setTickLa belFont(new Font(sFont,Font.PLAIN,12)); ((CategoryPlot)chart.getPlot()).getDomainAxis().setAxisLin eVisible(false);((CategoryPlot)chart.getPlot()).getRangeAxis().setVisible(f alse); //采用BarRenderer作为表示器BarRenderer renderer = new BarRenderer(); renderer.setPaint(new GradientPaint(0.0f,0.0f,Color.orange,0.0f,0.0f,Color.yellow )); renderer.setOutlinePaint(Color.orange);renderer.setDrawBarOutline(true); //在条中央显示投票数值renderer.setItemLabelAnchorOffset(-20.0f);renderer.setLabelGenerator(new StandardCategoryLabelGenerator("{2}",new DecimalFormat()));renderer.setPositiveItemLabelPosition(new ItemLabelPosition());renderer.setItemLabelsVisible(true); pie charts (2D and3D):饼图(平面和立体)bar charts (regular and stacked, with an optional 3D effect):柱状图line and area charts:曲线图scatter plots and bubble chartstime series,high/low/open/close charts and candle stick charts:时序图combination charts:复合图Pareto chartsGantt charts:甘特图wind plots, meter charts and symbol chartswafer map charts(态图表,饼图(二维和三维) , 柱状图(水平,垂直),线图,点图,时间变化图,甘特图, 股票行情图,混和图, 温度计图,刻度图等常用商用图表)图形可以导出成PNG和JPEG格式,同时还可以与PDF和EXCEL关联JFreeChart核心类库介绍:研究jfreechart源码发现源码的主要由两个大的包组成:org.jfree.chart,org.jfree.data。
JFreeChart中文乱码和文字模糊问题的通用解决方案
JFreeChart中文乱码和文字模糊问题的通用解决方案在使用JFreeChart ( )做中文的图表时,中文乱码是一个最常要处理的问题,看网上许多文章都是在JFreeChart对象上下功夫,每次都得重新设置字体,比较麻烦。
其实JFreeChart为我们提供了一个通用的解决方案——ChartTheme 。
ChartTheme有一个默认的实现类StandardChartTheme ,该类提供了图表主题的默认实现,通过ChartFactory 默认将这一实现应用到所有ChartFactory所生成的JFreeChart 对象中,你可以利用ChartFactory的setChartTheme(ChartTheme theme) 方法改变这一默认实现,让所有由ChartFactory生成的图表都应用你所指定的主题。
StandardChartTheme提供如下方法来定制字体:•public void setExtraLargeFont(Font font)•public void setLargeFont(Font font)•public void setRegularFont(Font font)•public void setSmallFont(Font font)只要重写这几个方法,就可以制定出一个适合中文图表的主题了:StandardChartTheme theme = new StandardChartTheme("unicode") {public void apply(JFreeChart chart) {chart.getRenderingHints().put(RenderingHints.KEY_TEXT_A NTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);super.apply(chart);}};theme.setExtraLargeFont(new Font("宋体", Font.PLAIN, 14));theme.setLargeFont(new Font("宋体", Font.PLAIN, 14));theme.setRegularFont(new Font("宋体", Font.PLAIN, 12));theme.setSmallFont(new Font("宋体", Font.PLAIN, 10));ChartFactory.setChartTheme(theme);重写apply(...)方法是为了借机消除文字锯齿.VALUE_TEXT_ANTIALIAS_OFFChartFactory.setChartTheme(theme); 用于将该主题作为工厂的默认主题。
JFreeChart_API文档
JFreeChart目前是最好的java图形解决方案,基本能够解决目前的图形方面的需求,主要包括如下几个方面:JFreeChart类:void setAntiAlias(boolean flag)字体模糊边界void setBackgroundImage(Image image)背景图片void setBackgroundImageAlignment(int alignment)背景图片对齐方式(参数常量在org.jfree.ui.Align类中定义)void setBackgroundImageAlpha(float alpha)背景图片透明度(0.0~1.0)void setBackgroundPaint(Paint paint)背景色void setBorderPaint(Paint paint)边界线条颜色void setBorderStroke(Stroke stroke)边界线条笔触void setBorderVisible(boolean visible)边界线条是否可见-----------------------------------------------------------------------------------------------------------TextTitle类:void setFont(Font font)标题字体void setPaint(Paint paint)标题字体颜色void setText(String text)标题内容-----------------------------------------------------------------------------------------------------------StandardLegend(Legend)类:void setBackgroundPaint(Paint paint)图示背景色void setTitle(String title)图示标题内容void setTitleFont(Font font)图示标题字体void setBoundingBoxArcWidth(int arcWidth)图示边界圆角宽void setBoundingBoxArcHeight(int arcHeight)图示边界圆角高void setOutlinePaint(Paint paint)图示边界线条颜色void setOutlineStroke(Stroke stroke)图示边界线条笔触void setDisplaySeriesLines(boolean flag)图示项是否显示横线(折线图有效)void setDisplaySeriesShapes(boolean flag)图示项是否显示形状(折线图有效)void setItemFont(Font font)图示项字体void setItemPaint(Paint paint)图示项字体颜色void setAnchor(int anchor)图示在图表中的显示位置(参数常量在Legend类中定义)Axis类:void setVisible(boolean flag)坐标轴是否可见void setAxisLinePaint(Paint paint)坐标轴线条颜色(3D轴无效)void setAxisLineStroke(Stroke stroke)坐标轴线条笔触(3D轴无效)void setAxisLineVisible(boolean visible)坐标轴线条是否可见(3D轴无效)void setFixedDimension(double dimension)(用于复合表中对多坐标轴的设置)void setLabel(String label)坐标轴标题void setLabelFont(Font font)坐标轴标题字体void setLabelPaint(Paint paint)坐标轴标题颜色void setLabelAngle(double angle)`坐标轴标题旋转角度(纵坐标可以旋转)void setTickLabelFont(Font font)坐标轴标尺值字体void setTickLabelPaint(Paint paint)坐标轴标尺值颜色void setTickLabelsVisible(boolean flag)坐标轴标尺值是否显示void setTickMarkPaint(Paint paint)坐标轴标尺颜色void setTickMarkStroke(Stroke stroke)坐标轴标尺笔触void setTickMarksVisible(boolean flag)坐标轴标尺是否显示ValueAxis(Axis)类:void setAutoRange(boolean auto)自动设置数据轴数据范围void setAutoRangeMinimumSize(double size)自动设置数据轴数据范围时数据范围的最小跨度void setAutoTickUnitSelection(boolean flag)数据轴的数据标签是否自动确定(默认为true)void setFixedAutoRange(double length)数据轴固定数据范围(设置100的话就是显示MAXVALUE到MAXVALUE-100那段数据范围)void setInverted(boolean flag)数据轴是否反向(默认为false)void setLowerMargin(double margin)数据轴下(左)边距void setUpperMargin(double margin)数据轴上(右)边距void setLowerBound(double min)数据轴上的显示最小值void setUpperBound(double max)数据轴上的显示最大值void setPositiveArrowVisible(boolean visible)是否显示正向箭头(3D轴无效)void setNegativeArrowVisible(boolean visible)是否显示反向箭头(3D轴无效)void setVerticalTickLabels(boolean flag)数据轴数据标签是否旋转到垂直void setStandardTickUnits(TickUnitSource source)数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)NumberAxis(ValueAxis)类:void setAutoRangeIncludesZero(boolean flag)是否强制在自动选择的数据范围中包含0void setAutoRangeStickyZero(boolean flag)是否强制在整个数据轴中包含0,即使0不在数据范围中void setNumberFormatOverride(NumberFormat formatter)数据轴数据标签的显示格式void setTickUnit(NumberTickUnit unit)数据轴的数据标签(需要将AutoTickUnitSelection设false)DateAxis(ValueAxis)类:void setMaximumDate(Date maximumDate)日期轴上的最小日期void setMinimumDate(Date minimumDate)日期轴上的最大日期void setRange(Date lower,Date upper)日期轴范围void setDateFormatOverride(DateFormat formatter)日期轴日期标签的显示格式void setTickUnit(DateTickUnit unit)日期轴的日期标签(需要将AutoTickUnitSelection设false)void setTickMarkPosition(DateTickMarkPosition position)日期标签位置(参数常量在org.jfree.chart.axis.DateTickMarkPosition类中定义)CategoryAxis(Axis)类:void setCategoryMargin(double margin)分类轴边距void setLowerMargin(double margin)分类轴下(左)边距void setUpperMargin(double margin)分类轴上(右)边距void setVerticalCategoryLabels(boolean flag)分类轴标题是否旋转到垂直void setMaxCategoryLabelWidthRatio(float ratio)分类轴分类标签的最大宽度AbstractRenderer类:void setItemLabelAnchorOffset(double offset)数据标签的与数据点的偏移void setItemLabelsVisible(boolean visible)数据标签是否可见void setItemLabelFont(Font font)数据标签的字体void setItemLabelPaint(Paint paint)数据标签的字体颜色void setItemLabelPosition(ItemLabelPosition position)数据标签位置void setPositiveItemLabelPosition(ItemLabelPosition position)正数标签位置void setNegativeItemLabelPosition(ItemLabelPosition position)负数标签位置void setOutLinePaint(Paint paint)图形边框的线条颜色void setOutLineStroke(Stroke stroke)图形边框的线条笔触void setPaint(Paint paint)所有分类图形的颜色void setShape(Shape shape)所有分类图形的形状(如折线图的点)void setStroke(Stroke stroke)所有分类图形的笔触(如折线图的线)void setSeriesItemLabelsVisible(int series,boolean visible)指定分类的数据标签是否可见void setSeriesItemLabelFont(int series,Font font)指定分类的数据标签的字体void setSeriesItemLabelPaint(int series,Paint paint)指定分类的数据标签的字体颜色void setSeriesItemLabelPosition(int series,ItemLabelPosition position)数据标签位置void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition position)正数标签位置void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition position)负数标签位置void setSeriesOutLinePaint(int series,Paint paint)指定分类的图形边框的线条颜色void setSeriesOutLineStroke(int series,Stroke stroke)指定分类的图形边框的线条笔触void setSeriesPaint(int series,Paint paint)指定分类图形的颜色void setSeriesShape(int series,Shape shape)指定分类图形的形状(如折线图的点)void setSeriesStroke(int series,Stroke stroke)指定分类图形的笔触(如折线图的线)AbstractCategoryItemRenderer(AbstractRenderer)类:void setLabelGenerator(CategoryLabelGenerator generator)数据标签的格式void setToolTipGenerator(CategoryToolTipGenerator generator)MAP中鼠标移上的显示格式void setItemURLGenerator(CategoryURLGenerator generator)MAP中钻取链接格式void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator)指定分类的数据标签的格式void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator)指定分类的MAP中鼠标移上的显示格式void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator)指定分类的MAP中钻取链接格式BarRenderer(AbstractCategoryItemRenderer)类:void setDrawBarOutline(boolean draw)是否画图形边框void setItemMargin(double percent)每个BAR之间的间隔void setMaxBarWidth(double percent)每个BAR的最大宽度void setMinimumBarLength(double min)最短的BAR长度,避免数值太小而显示不出void setPositiveItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的正数标签位置void setNegativeItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的负数标签位置BarRenderer3D(BarRenderer)类:void setWallPaint(Paint paint)3D坐标轴的墙体颜色StackedBarRenderer(BarRenderer)类:没有特殊的设置StackedBarRenderer3D(BarRenderer3D)类:没有特殊的设置GroupedStackedBarRenderer(StackedBarRenderer)类:void setSeriesToGroupMap(KeyToGroupMap map)将分类自由的映射成若干个组(KeyToGroupMap.mapKeyToGroup(series,group))LayeredBarRenderer(BarRenderer)类:void setSeriesBarWidth(int series,double width)设定每个分类的宽度(注意设置不要使某分类被覆盖)WaterfallBarRenderer(BarRenderer)类:void setFirstBarPaint(Paint paint)第一个柱图的颜色void setLastBarPaint(Paint paint)最后一个柱图的颜色void setPositiveBarPaint(Paint paint)正值柱图的颜色void setNegativeBarPaint(Paint paint)负值柱图的颜色IntervalBarRenderer(BarRenderer)类:需要传IntervalCategoryDataset作为数据源GanttBarRenderer(IntervalBarRenderer)类:void setCompletePaint(Paint paint)完成进度颜色void setIncompletePaint(Paint paint)未完成进度颜色void setStartPercent(double percent)设置进度条在整条中的起始位置(0.0~1.0)void setEndPercent(double percent)设置进度条在整条中的结束位置(0.0~1.0)StatisticBarRenderer(BarRenderer)类:需要传StatisticCategoryDataset作为数据源LineAndShapeRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean draw)是否折线的数据点之间用线连void setDrawShapes(boolean draw)是否折线的数据点根据分类使用不同的形状void setShapesFilled(boolean filled)所有分类是否填充数据点图形void setSeriesShapesFilled(int series,boolean filled)指定分类是否填充数据点图形void setUseFillPaintForShapeOutline(boolean use)指定是否填充数据点的Paint也被用于画数据点形状的边框LevelRenderer(AbstractCategoryItemRenderer)类:void setItemMargin(double percent)每个分类之间的间隔void setMaxItemWidth(double percent)每个分类的最大宽度CategoryStepRenderer(AbstractCategoryItemRenderer)类:void setStagger(boolean shouldStagger)不同分类的图是否交错MinMaxCategoryRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean drawLines)是否在每个分类线间画连接线void setGroupPaint(Paint groupPaint)一组图形连接线的颜色void setGroupStroke(Stroke groupStroke)一组图形连接线的笔触void setMaxIcon(Icon maxIcon)最大值的ICONvoid setMinIcon(Icon minIcon)最小值的ICONvoid setObjectIcon(Icon objectIcon)所有值的ICONAreaRender(AbstractCategoryItemRenderer)类:没有特殊的设置StackedAreaRender(AreaRender)类:没有特殊的设置关键就是用好Renderer这个类了,再贴个例子:String sFont = "宋体";chart.setBorderVisible(true);chart.setBorderPaint(new Color(0xFF,0x66,0x00));chart.setBackgroundPaint(new Color(0xFF,0xF3,0xDE));chart.getTitle().setPaint(Color.red);chart.getTitle().setFont(new Font(sFont,Font.BOLD,14));//设置Plot,不显示所有网格((CategoryPlot)chart.getPlot()).setOutlinePaint(null);((CategoryPlot)chart.getPlot()).setDomainGridlinesVisible(false);((CategoryPlot)chart.getPlot()).setRangeGridlinesVisible(false);//设置横轴字体,设定横轴轴线不可见,隐藏纵轴((CategoryPlot)chart.getPlot()).getDomainAxis().setTickLabelFont(new Font(sFont,Font.PLAIN,12));((CategoryPlot)chart.getPlot()).getDomainAxis().setAxisLineVisible(false);((CategoryPlot)chart.getPlot()).getRangeAxis().setVisible(false);//采用BarRenderer作为表示器BarRenderer renderer = new BarRenderer();renderer.setPaint(new GradientPaint(0.0f,0.0f,Color.orange,0.0f,0.0f,Color.yellow));renderer.setOutlinePaint(Color.orange);renderer.setDrawBarOutline(true);//在条中央显示投票数值renderer.setItemLabelAnchorOffset(-20.0f);renderer.setLabelGenerator(new StandardCategoryLabelGenerator("{2}",new DecimalFormat()));renderer.setPositiveItemLabelPosition(new ItemLabelPosition());renderer.setItemLabelsVisible(true);pie charts (2D and 3D):饼图(平面和立体)bar charts (regular and stacked, with an optional 3D effect):柱状图line and area charts:曲线图scatter plots and bubble chartstime series, high/low/open/close charts and candle stick charts:时序图combination charts:复合图Pareto chartsGantt charts:甘特图wind plots, meter charts and symbol chartswafer map charts(态图表,饼图(二维和三维) , 柱状图(水平,垂直),线图,点图,时间变化图,甘特图, 股票行情图,混和图, 温度计图, 刻度图等常用商用图表)图形可以导出成PNG和JPEG格式,同时还可以与PDF和EXCEL关联JFreeChart核心类库介绍:研究jfreechart源码发现源码的主要由两个大的包组成:org.jfree.chart,org.jfree.data。
JFreeChart使用详细教程
1页
JFreeChart的下载与使用
JFreeChart是开放源代码的图形报表组件(开源 站点上的一个Jave项目),其主页为 /jfreechart/index.html。 在主页中单击DOWNLOAD导航链接将进入下 载页面,选择所要下载的JfreeChart版本即可进行下 载,目前最新版本为1.0.13。 在下载成功后将得到一个名为jfreechart1.0.13.zip的压缩包,此压缩包包含JFreeChart组件源 码、示例、支持类库等文件,将其解压缩后的文件 结构如右图所示。
3页
饼形图:一个划分为几个 饼形图 扇区的圆形图表,用于描述量、 频率或百分比之间的相对关系。 在饼图中,每个扇区的弧长 (以及(圆心角)和面积)大 小为其所表示的数量的比例。 这些扇区合在一起刚好是一个 完全的圆形。顾名思义,这些 扇区拼成了一个切开的饼形图 案。
JFreeChart开发前准备
开发前的准备,JfreeChart开发环境的搭建分为两步:导入 JFreeChart组件包;配置JFreeChart。 1、导入JFreeChart包:导入在lib目录下的jfreechart1.0.13.jar、jcommon-1.0.16.jar两个Jar包到工程。 2、配置JFreeChart: JFreeChart组件能够成.JPEG、.PNG 格式的图片,其输出方式可以直接存储在硬盘中,也可以交给 JFreeChart组件进行管理。在Web应用中,所生成的图形报表一 般均为动态图表,如果对每次生成的图表都进行直接存储,将
14页
通过此方法生成图片后,调用已注册的JFreeChart提供的 Servlet类DisplayChart,即可获取图片的相对路径。 输出图片在Jsp中的应用关键代码如下,可参照该代码将 其运用到servlet或Struts2的Action中。
JFreeChart调用技术文档(JSP页面实现折线图)
创建柱状图1 引入jFreechart的包jcommon-1.0.15.jarjfreechart-1.0.12.jarjfreechart-1.0.12-experimental.jar2 在web.xml中加入<servlet><servlet-nam e>DisplayChart</servlet-nam e><servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class></servlet><servlet-m apping><servlet-nam e>DisplayChart</servlet-nam e><url-pattern>/servlet/DisplayChart</url-pattern></servlet-m apping>3 在jsp或者servlet或者action中写// 创建一个柱状图DefaultCategoryDataset dataSet =new DefaultCategoryDataset();// 数据装入for(int i=0;i<list.size();i++){Item item =(Item)list.get(i);dataSet.setValue(Item.getRating(), "testNam e", Item.getTime());}JFreeChart chart = ChartFactory.createBarChart("统计图","ratings", "time", dataSet, PlotOrientation.VERTICAL,false, true, false);try{String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, ses sion);String graphURL = request.getContextPath() + "/servlet/DisplayChart?filen am e=" + filename;request.setAttribute("graphURL",graphURL);} catch (Exception e){}4 在页面引入<img src="<%= request.getAttribute("graphURL") %>">这种方式会生成临时图片文件,默认是不对其进行清理的,所以要手工进行处理对于临时文件的清除,jfreechart提供了一个实现了HttpSessionBindingListener的类Chart Deleter,里面有个valueUnbound方法,这个方法是在session执行remove的时候被自动执行,所以我们只需要在页面刚进入的时候调用session.removeAttribute("JFreeChart_Deleter");这样会删除当前session之前生成的图表。
JFreeChart使用方法
JFreeChart使用方法概述1.JFreeChart Itext StrutsJFreeChartJFreeChart(/) 主要是用来制作各种各样的图表,包括:饼图、柱状图( 普通柱状图以及堆栈柱状图)、线图、区域图、分布图、混合图、甘特图以及一些仪表盘等等。
本文中使用的是jfreechart-1.0.13.jar。
iTextiText(/) 是一个能够快速产生PDF 文件的Java 类库,与Servlet 有很好的给合,可以非常方便完成PDF 输出,最新的版本是iText-5.0.4.jar。
如果需要在报表中支持中文显示,还需要下载iTextAsian.jar。
2.JFreeChart配置3.JFreeChart相关资料JFreeChart使用基础/view/0ff1f8e8e009581b6bd9ebbc.html?from=rec&pos=2&weight=2&lastweight=0&count=2JFreeChart乱码修改http://www.zihou.me/html/2009/12/17/708.htmlJFreeChart与Itext 生成PDF图片/articles/42891.shtmlJFreeChart使用框架创建数据集柱状图数据集的获取DefaultCategoryDataset类例子:CategoryDataset dataset =DatasetUtilities.createCategoryDataset(rowKeys, // String[]{柱子的名称} 位于说明框columnKeys, // String[]{柱子组名称} 位于X轴data) // Double型2维数组折线图的数据集的获取DefaultCategoryDataset类例子:CategoryDataset dataset =DatasetUtilities.createCategoryDataset(rowKeys, // String[]{每一条线的名称} 位于说明框columnKeys, // String[]{每一个节点名称} 位于X轴data) // Double型2维数组,饼图的数据集的获取DefaultPieDataset类例子:DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue(“分饼的名称”, “分饼的数据”);创建JFreeChart对象通过制图工厂ChartFactroy创建JFreeChart对象://创建一个常规的柱形图对象Public static JFreeChart createBarChart()例子:JFreeChart chart = new ChartFactroy. createBarChart(chartTitle, // 图表标题xName, // 目录轴的显示标签yName, // 数值轴的显示标签dataset, // 数据集PlotOrientation.VERTICAL, // 图表方向:水平、垂直true, // 是否显示图例(对于简单的柱状图必须是false)true, // 是否生成工具true// 是否生成URL链接)//创建一个常规的饼形图对象Public static JFreeChart createPieChart()例子:JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart titledataset,// datatrue,// include legendtrue,false)//创建一个常规的折线图对象Public static JFreeChart createLineChart()例子:JFreeChart chart = ChartFactory.createLineChart(chartTitle, // 图表标题xName, // X轴的显示标签yName, // Y轴的显示标签dataset, // 数据集PlotOrientation.VERTICAL, // 图表方向:水平、垂直true, // 是否显示图例(对于简单的柱状图必须是false)true, // 是否生成工具true) // 是否生成URL链接获取图片:1.在F:\工具\Tomcat\Tomcat6.0\webapps\gms\web\report\images\temp 目录下生成图片:生成JFreeChart组件所绘制的图片:调用ChartUtilities类的saveChartAsPNG()方法声称.png格式的图片Public static String saveChartAsPNG(84437JFreeChart chart, //JFreeChart对象Int width, //生成图片的宽度Int height, //生成图片的高度HttpSession sseion) // HttpSession对象显示图片:在JSP中使用图片:例子:<%String filename = ChartUtilities. saveChartAsPNG(Chart,500,700,Session)String graphURL = request.getContextPath()+“/Servlet/DisplayChart?filename=”+filename;%><img src="<% = graphURL %>">2.采用输出流方式获取图片,不会产生垃圾文件生成JFreeChart组件所绘制的图片:调用ChartUtilities类的 writeChartAsPNG()方法可以将图片直接输出到页面并运用到servlet或Struts2的Action中,不用存储到硬盘例子:ChartUtilities.writeChartAsPNG(response.getOutputStream(), //选择servlet方式输出图片chart, //生成的JFreeChart的对象700, //生成图片的宽度500) //生成图片的高度显示图片:在JSP上把图片的src请求路径设置为产生输出流的action即可例子:<img src="/JfreeChart.action"> JFreeChart 调整:柱状图调整:1.整体的调整获取plotCategoryPlot plot = chart.getCategoryPlot();// 设置横虚线可见plot.setRangeGridlinesVisible(true);// 虚线色彩plot.setRangeGridlinePaint(Color.gray);// 数据轴精度NumberAxis vn = (NumberAxis) plot.getRangeAxis();// 数据轴数据标签的显示格式DecimalFormat df = new DecimalFormat("#0.00");vn.setNumberFormatOverride(df);2.X轴调整获取X轴CategoryAxis domainAxis = plot.getDomainAxis();// X轴标题字体设置domainAxis.setLabelFont(new Font("SansSerif", Font.TRUETYPE_FONT, 12));//X轴数值字体设置domainAxis.setTickLabelFont(new Font("SansSerif", Font.TRUETYPE_FONT, 12));//设置X轴文字倾斜度domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 3.0));// X轴上的Lable 是否完整显示domainAxis.setMaximumCategoryLabelWidthRatio(0.6f);// 设置距离图片左端距离domainAxis.setLowerMargin(0.1);// 设置距离图片右端距离domainAxis.setUpperMargin(0.1);调整完成后要将X轴set 到plot 中plot.setDomainAxis(domainAxis);3.Y轴调整获取Y轴ValueAxis rangeAxis = plot.getRangeAxis();// Y轴标题字体设置rangeAxis.setLabelFont(labelFont);//Y轴数值字体设置rangeAxis.setTickLabelFont(labelFont);// 设置最高的一个Item 与图片顶端的距离rangeAxis.setUpperMargin(0.15);// 设置最低的一个Item 与图片底端的距离rangeAxis.setLowerMargin(0.15);调整完成后要将Y轴set 到plot 中plot.setRangeAxis(rangeAxis);4.背景调整// 设置柱图背景色(注意,系统取色的时候要使用16位的模式来查看颜色编码,这样比较准确)plot.setBackgroundPaint(new Color(255, 255, 204))// 设置柱子宽度renderer.setMaximumBarWidth(0.05);// 设置柱子高度renderer.setMinimumBarLength(0.2);// 设置柱子边框颜色renderer.setBaseOutlinePaint(Color.BLACK);// 设置柱子边框可见renderer.setDrawBarOutline(true);// // 设置柱的颜色renderer.setSeriesPaint(0, new Color(204, 255, 255));renderer.setSeriesPaint(1, new Color(153, 204, 255));renderer.setSeriesPaint(2, new Color(51, 204, 204));// 设置每个地区所包含的平行柱的之间距离renderer.setItemMargin(0.0);// 显示每个柱的数值,并修改该数值的字体属性renderer.setIncludeBaseInRange(true);renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());renderer.setBaseItemLabelsVisible(true);plot.setRenderer(renderer);// 设置柱的透明度plot.setForegroundAlpha(1.0f);//设置图片背景色chart.setBackgroundPaint(Color.white);5.注意问题:1.在调整柱形图的过程中在设置柱子颜色的时候,设置的数量不得大于柱子量2.数据中说明文字的数据个数要等于设置的分组数量3.数据中列的数量要等于X轴列的数量饼图的调整// 使下说明标签字体清晰,去锯齿chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);// 图片背景色chart.setBackgroundPaint(Color.white)// 设置图标题的字体重新设置titleFont font = new Font("隶书", Font.BOLD, 25);TextTitle title = new TextTitle(chartTitle);title.setFont(font);chart.setTitle(title);// 指定饼图轮廓线的颜色plot.setBaseSectionOutlinePaint(Color.BLACK);plot.setBaseSectionPaint(Color.BLACK);// 设置无数据时的信息plot.setNoDataMessage("无对应的数据,请重新查询。
Jfreechart 图表开发文档
Jfreechart 图表开发文档目标简介:只要按要求写好sql 语句就能生成相应的图表。
实现步骤:1.置图表属性2.写sql 语句3.取图表数据对象4.生成图表5.显示图表详细说明:1.置图表属性图表属性类中定义了图表的属性信息,如,图表标题,图表热链接,是否3D效果显示code:String title = "统计图2";ChartProperty cp = new ChartProperty(title);cp.setChart3D(false);cp.setHitUrl("/servlet/_test");2.写sql 语句sql语句要求:饼型图,柱型图要求sql 语句的select 字段,第一个为String 型,第二个为number 型,曲线图第一个字段要求为日期型,第二个字段为number型,可以有第三个字段,第四个字段…..(n个)这个可生成多曲线图表。
code:1.String sql = "select basepricetype, sum(saleprice)" +" from tb_builsrc_contractinfo" +" where affirm_date >= to_date('2004-06-01', 'yyyy-MM-dd') and" +" affirm_date <= to_date('2004-06-02', 'yyyy-MM-dd')" +" group by basepricetype";2.sql = "select affirm_date, baseprice, saleprice" +" from tb_builsrc_contractinfo" +" where affirm_date >= to_date('2004-06-01 00:00:00', 'yyyy-MM-dd HH24:mi:SS') and " +" affirm_date <= to_date('2004-06-01 23:59:59', 'yyyy-MM-dd HH24:mi:SS')" +" order by affirm_date ";3.取图表数据对象生成不同图表所在生成的jfreechart 数据对象不同,jfreechart提供三个接口,饼型图为,PieDataset,要柱型图为CategoryDataset, 曲线图为XYDataset,同时在交易系统包中提供有DbChartCenter类,静态封装生成不同图表。
jfreechart中文乱码
JFreeChart中文乱码的解决方法使用JFreeChart绘制图表的时候,如果使用默认的字体会导致图标中的汉字显示为乱码。
解决方法如下:JFreeChart是用户使用该库提供的各类图标的统一接口,JFreeChart主要由三个部分构成:title(标题),legend(图释),plot(图表主体)。
三个部分设置字体的方法分别如下: 1.Title1.TextTitle textTitle = freeChart.getTitle();2.textTitle.setFont(new Font("宋体",Font.BOLD,20));2.Legent1.LegendTitle legend = freeChart.getLegend();2.if (legend!=null) {3. legend.setItemFont(new Font("宋体", Font.BOLD, 20));}3.Plot对于不同类型的图表对应Plot的不同的实现类,设置字体的方法也不完全相同。
对于使用CategoryPlot的图表(如柱状图):实用文档 1.CategoryPlot plot = (CategoryPlot)freeChart.getPlot(); 2.CategoryAxis domainAxis = plot.getDomainAxis();//(柱状图的x 轴) 3. domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置x 轴坐标上的字体4. domainAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置x 轴上的标题的字体5.ValueAxis valueAxis = plot.getRangeAxis();//(柱状图的y 轴) 6. valueAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置y 轴坐标上的字体7. valueAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置y 轴坐标上的标题的字体对于使用PiePlot 的图标(如饼状图):1.PiePlot plot = (PiePlot)freeChart.getPlot(); 2. plot.setLabelFont(new Font("宋体",Font.BOLD,15));柱状图(CategoryPlot):CategoryPlot plot=chart.getCategoryPlot();//获取图表区域对象CategoryAxis domainAxis=plot.getDomainAxis();//水平底部列表domainAxis.setLabelFont(new Font("黑体",Font.BOLD,14));//水平底部标题domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,12));//垂直标题ValueAxis rangeAxis=plot.getRangeAxis();//获取柱状rangeAxis.setLabelFont(new Font("黑体",Font.BOLD,15));饼图(PiePlot):JFreeChart chart = ChartFactory.createPieChart3D("IT行业职业分布图", dataset, true, false, false);chart.getTitle().setFont(new Font("黑体",Font.BOLD,20));//设置标题字体PiePlot piePlot= (PiePlot) chart.getPlot();//获取图表区域对象piePlot.setLabelFont(new Font("黑体",Font.BOLD,10));chart.getLegend().setItemFont(new Font("黑体",Font.BOLD,10));时序图(TimeSeries)XYPlot :实用文档XYPlot plot = (XYPlot) chart.getPlot();//纵轴字体plot.getRangeAxis().setLabelFont(new Font("宋体", Font.BOLD, 15));//横轴框里的标题字体chart.getLegend().setItemFont(new Font("宋体", Font.ITALIC, 15));//横轴列表字体plot.getDomainAxis().setTickLabelFont(new Font("新宋体", 1, 15));//横轴小标题字体plot.getDomainAxis().setLabelFont(new Font("新宋体", 1, 12));实用文档。
解决jfreechart中文乱码方案整1
解决jfreechart中文乱码方案整理【图】http://www.zihou.me/2009/12/17/708/2009年12月17日admin发表评论阅读评论这篇博文只是对网上关于jfreechart中文乱码解决方法的一个汇总整理。
我也是最近要使用到jfreechart这个图表工具,也是碰到了中文乱码这个问题,后来通过搜索(jfreechart图片乱码等关键词)解决了这个乱码,但发现一个问题就是有的文章只是解决了图表中乱码的某一个方面,比如图表标题,而有的文章不是解决图表标题乱码,却能够解决图表X、Y轴上文字和标题乱码以及底部中文乱码,有鉴于此,于是我就将这些解决方法都汇总在了一起,希望对碰到jfreechart中文乱码的朋友有帮助。
下图是一个柱形图表,非常典型的中文乱码(其他形式图表就不说明了,因为柱形非常有代表性):以上图表对应的jsp文件代码为:<%@ page contentType="text/html;charset=UTF-8"%><%@ page import="org.jfree.chart.ChartFactory,org.jfree.chart.JFreeChart,org.jfree.chart.plot.PlotOrientation,org.jfree.chart.servlet.ServletUtilities,org.jfree.data.category.CategoryDataset,org.jfree.data.general.DatasetUtilities,org.jfree.chart.plot.*,bels.*,org.jfree.chart.renderer.category.BarRenderer3D,java.awt.*,org.jfree.ui.*,org.jfree.chart.axis.AxisLocation,org.jfree.chart.title.TextTitle,org .jfree.chart.axis.CategoryAxis,org.jfree.chart.axis.NumberAxis"%><%double[][] data = newdouble[][] {{1310, 1220, 1110, 1000},{720, 700, 680, 640},{1130, 1020, 980, 800},{440, 400, 360, 300}};String[] rowKeys = {"猪肉", "niurou","鸡肉", "鱼肉"};String[] columnKeys = {"广州", "shenzhen", "东莞", "佛山"};CategoryDataset dataset =DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);JFreeChart chart = ChartFactory.createBarChart3D("","肉类","销量",dataset,PlotOrientation.VERTICAL,true,true,false);CategoryPlot plot = chart.getCategoryPlot();//设置网格背景颜色plot.setBackgroundPaint(Color.white);//设置网格竖线颜色plot.setDomainGridlinePaint(Color.pink);//设置网格横线颜色plot.setRangeGridlinePaint(Color.pink);//显示每个柱的数值,并修改该数值的字体属性BarRenderer3D renderer = new BarRenderer3D();renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());renderer.setBaseItemLabelsVisible(true);//默认的数字显示在柱子中,通过如下两句可调整数字的显示//注意:此句很关键,若无此句,那数字的显示会被覆盖,给人数字没有显示出来的问题renderer.setBasePositiveItemLabelPosition(newItemLabelPosition(ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT));renderer.setItemLabelAnchorOffset(10D);renderer.setItemLabelFont(new Font("宋体", Font.PLAIN, 12));renderer.setItemLabelsVisible(true);//设置每个地区所包含的平行柱的之间距离//renderer.setItemMargin(0.3);plot.setRenderer(renderer);//设置地区、销量的显示位置//将下方的“肉类”放到上方plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);//将默认放在左边的“销量”放到右方plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);String filename = ServletUtilities.saveChartAsPNG(chart, 700, 400, null, session);String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;%><img src="<%= graphURL %>" width=700 height=400 border=0 usemap="#<%= filename %>">注意到在以上的图表中,有四个位置的中文乱码:1、图表标题以及副标题乱码2、X轴乱码3、Y轴乱码4、图表底部乱码如下图所示:对这四个位置的乱码分别进行解决:NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();CategoryAxis domainAxis = plot.getDomainAxis();1、图表标题以及副标题乱码Font font = new Font("宋体", Font.BOLD, 16);TextTitle title = new TextTitle("肉类销量统计图", font);//副标题TextTitle subtitle = new TextTitle(“副标题”, new Font(“黑体”, Font.BOLD, 12)); chart.addSubtitle(subtitle);chart.setTitle(title); //标题2、X轴乱码2.1、X轴坐标上的文字:domainAxis.setTickLabelFont(new Font(“sans-serif”, Font.PLAIN, 11));2.2、X轴坐标标题(肉类)domainAxis.setLabelFont(new Font(“宋体”, Font.PLAIN, 12));3、Y轴乱码3.1、Y轴坐标上的文字:numberaxis.setTickLabelFont(new Font(“sans-serif”, Font.PLAIN, 12));3.2、Y轴坐标标题(销量):numberaxis.setLabelFont(new Font(“黑体”, Font.PLAIN, 12));4、图表底部乱码(猪肉等文字)chart.getLegend().setItemFont(new Font(“宋体”, Font.PLAIN, 12));通过以上设置就解决了中文乱码了,解决中文乱码后的图表如下所示:对应的完整代码为(jsp):<%@ page contentType="text/html;charset=UTF-8"%><%@ page import="org.jfree.chart.ChartFactory,org.jfree.chart.JFreeChart,org.jfree.chart.plot.PlotOrientation,org.jfree.chart.servlet.ServletUtilities,org.jfree.data.category.CategoryDataset,org.jfree.data.general.DatasetUtilities,org.jfree.chart.plot.*,bels.*,org.jfree.chart.renderer.category.BarRenderer3D,java.awt.*,org.jfree.ui.*,org.jfree.chart.axis.AxisLocation,org.jfree.chart.title.TextTitle,org .jfree.chart.axis.CategoryAxis,org.jfree.chart.axis.NumberAxis"%><%double[][] data = newdouble[][] {{1310, 1220, 1110, 1000},{720, 700, 680, 640},{1130, 1020, 980, 800},{440, 400, 360, 300}};String[] rowKeys = {"猪肉", "niurou","鸡肉", "鱼肉"};String[] columnKeys = {"广州", "shenzhen", "东莞", "佛山"};CategoryDataset dataset =DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);JFreeChart chart = ChartFactory.createBarChart3D("","肉类","销量",dataset,PlotOrientation.VERTICAL,true,true,false);CategoryPlot plot = chart.getCategoryPlot();//设置字体,不然会中文乱码的Font font = new Font("宋体", Font.BOLD, 16);TextTitle title = new TextTitle("肉类销量统计图", font);//副标题TextTitle subtitle = new TextTitle("副标题", new Font("黑体", Font.BOLD, 12));chart.addSubtitle(subtitle);chart.setTitle(title); //标题//////////////////////////NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();CategoryAxis domainAxis = plot.getDomainAxis();/*------设置 X 轴坐标上的文字-----------*/domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));/*------设置 X 轴的标题文字------------*/domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));/*------设置 Y 轴坐标上的文字-----------*/numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));/*------设置 Y 轴的标题文字------------*/numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));/*------这句代码解决了底部汉字乱码的问题-----------*/chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));//设置网格背景颜色plot.setBackgroundPaint(Color.white);//设置网格竖线颜色plot.setDomainGridlinePaint(Color.pink);//设置网格横线颜色plot.setRangeGridlinePaint(Color.pink);//显示每个柱的数值,并修改该数值的字体属性BarRenderer3D renderer = new BarRenderer3D();renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());renderer.setBaseItemLabelsVisible(true);//默认的数字显示在柱子中,通过如下两句可调整数字的显示//注意:此句很关键,若无此句,那数字的显示会被覆盖,给人数字没有显示出 来的问题renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));renderer.setItemLabelAnchorOffset(10D);renderer.setItemLabelFont(new Font("宋体", Font.PLAIN, 12));renderer.setItemLabelsVisible(true);//设置每个地区所包含的平行柱的之间距离//renderer.setItemMargin(0.3);plot.setRenderer(renderer);//设置地区、销量的显示位置//将下方的“肉类”放到上方plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);//将默认放在左边的“销量”放到右方plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);String filename = ServletUtilities.saveChartAsPNG(chart, 700, 400, null, session);String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;%><img src="<%= graphURL %>" width=700 height=400 border=0 usemap="#<%=filename %>">附录: 1、 在使用前必须先在 web.xml 中配置一下 servlet,配置很简单,可以根据自己具体情 况配置,以下是我配置的:<servlet><servlet-name>DisplayChart</servlet-name><servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>DisplayChart</servlet-name><url-pattern>/DisplayChart</url-pattern></servlet-mapping>2、附件中是关于饼图、柱形图、曲线图的使用写法例子,也是从网上搜集而来,感觉还是 很不错的,也整理在这里了。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
JFreeChart类:void setAntiAlias(boolean flag) 字体模糊边界void setBackgroundImage(Image image) 背景图片void setBackgroundImageAlignment(int alignment) 背景图片对齐方式(参数常量在org.jfree.ui.Align类中定义)void setBackgroundImageAlpha(float alpha) 背景图片透明度(0.0~1.0)void setBackgroundPaint(Paint paint) 背景色void setBorderPaint(Paint paint) 边界线条颜色void setBorderStroke(Stroke stroke) 边界线条笔触void setBorderVisible(boolean visible) 边界线条是否可见-----------------------------------------------------------------------------------------------------------TextTitle类:void setFont(Font font) 标题字体void setPaint(Paint paint) 标题字体颜色void setText(String text) 标题内容-----------------------------------------------------------------------------------------------------------StandardLegend(Legend)类:void setBackgroundPaint(Paint paint) 图示背景色void setTitle(String title) 图示标题内容void setTitleFont(Font font) 图示标题字体void setBoundingBoxArcWidth(int arcWidth) 图示边界圆角宽void setBoundingBoxArcHeight(int arcHeight) 图示边界圆角高void setOutlinePaint(Paint paint) 图示边界线条颜色void setOutlineStroke(Stroke stroke) 图示边界线条笔触void setDisplaySeriesLines(boolean flag) 图示项是否显示横线(折线图有效)void setDisplaySeriesShapes(boolean flag) 图示项是否显示形状(折线图有效)void setItemFont(Font font) 图示项字体void setItemPaint(Paint paint) 图示项字体颜色void setAnchor(int anchor) 图示在图表中的显示位置(参数常量在Legend类中定义)-----------------------------------------------------------------------------------------------------------Axis类:void setVisible(boolean flag) 坐标轴是否可见void setAxisLinePaint(Paint paint) 坐标轴线条颜色(3D轴无效)void setAxisLineStroke(Stroke stroke) 坐标轴线条笔触(3D轴无效)void setAxisLineVisible(boolean visible) 坐标轴线条是否可见(3D轴无效)void setFixedDimension(double dimension) (用于复合表中对多坐标轴的设置)void setLabel(String label) 坐标轴标题void setLabelFont(Font font) 坐标轴标题字体void setLabelPaint(Paint paint) 坐标轴标题颜色void setLabelAngle(double angle)` 坐标轴标题旋转角度(纵坐标可以旋转)void setTickLabelFont(Font font) 坐标轴标尺值字体void setTickLabelPaint(Paint paint) 坐标轴标尺值颜色void setTickLabelsVisible(boolean flag) 坐标轴标尺值是否显示void setTickMarkPaint(Paint paint) 坐标轴标尺颜色void setTickMarkStroke(Stroke stroke) 坐标轴标尺笔触void setTickMarksVisible(boolean flag) 坐标轴标尺是否显示ValueAxis(Axis)类:void setAutoRange(boolean auto) 自动设置数据轴数据范围void setAutoRangeMinimumSize(double size) 自动设置数据轴数据范围时数据范围的最小跨度void setAutoTickUnitSelection(boolean flag) 数据轴的数据标签是否自动确定(默认为true)void setFixedAutoRange(double length) 数据轴固定数据范围(设置100的话就是显示MAXVALUE到MAXVALUE-100那段数据范围)void setInverted(boolean flag) 数据轴是否反向(默认为false)void setLowerMargin(double margin) 数据轴下(左)边距void setUpperMargin(double margin) 数据轴上(右)边距void setLowerBound(double min) 数据轴上的显示最小值void setUpperBound(double max) 数据轴上的显示最大值void setPositiveArrowVisible(boolean visible) 是否显示正向箭头(3D轴无效)void setNegativeArrowVisible(boolean visible) 是否显示反向箭头(3D轴无效)void setVerticalTickLabels(boolean flag) 数据轴数据标签是否旋转到垂直void setStandardTickUnits(TickUnitSource source) 数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)NumberAxis(ValueAxis)类:void setAutoRangeIncludesZero(boolean flag) 是否强制在自动选择的数据范围中包含0void setAutoRangeStickyZero(boolean flag) 是否强制在整个数据轴中包含0,即使0不在数据范围中void setNumberFormatOverride(NumberFormat formatter) 数据轴数据标签的显示格式void setTickUnit(NumberTickUnit unit) 数据轴的数据标签(需要将AutoTickUnitSelection设false)DateAxis(ValueAxis)类:void setMaximumDate(Date maximumDate) 日期轴上的最小日期void setMinimumDate(Date minimumDate) 日期轴上的最大日期void setRange(Date lower,Date upper) 日期轴范围void setDateFormatOverride(DateFormat formatter) 日期轴日期标签的显示格式void setTickUnit(DateTickUnit unit) 日期轴的日期标签(需要将AutoTickUnitSelection设false)void setTickMarkPosition(DateTickMarkPosition position) 日期标签位置(参数常量在org.jfree.chart.axis.DateTickMarkPosition类中定义)CategoryAxis(Axis)类:void setCategoryMargin(double margin) 分类轴边距void setLowerMargin(double margin) 分类轴下(左)边距void setUpperMargin(double margin) 分类轴上(右)边距void setVerticalCategoryLabels(boolean flag) 分类轴标题是否旋转到垂直void setMaxCategoryLabelWidthRatio(float ratio) 分类轴分类标签的最大宽度-----------------------------------------------------------------------------------------------------------Plot类:void setBackgroundImage(Image image) 数据区的背景图片void setBackgroundImageAlignment(int alignment) 数据区的背景图片对齐方式(参数常量在org.jfree.ui.Align类中定义)void setBackgroundPaint(Paint paint) 数据区的背景图片背景色void setBackgroundAlpha(float alpha) 数据区的背景透明度(0.0~1.0)void setForegroundAlpha(float alpha) 数据区的前景透明度(0.0~1.0)void setDataAreaRatio(double ratio) 数据区占整个图表区的百分比void setOutLinePaint(Paint paint) 数据区的边界线条颜色void setOutLineStroke(Stroke stroke) 数据区的边界线条笔触void setNoDataMessage(String message) 没有数据时显示的消息void setNoDataMessageFont(Font font) 没有数据时显示的消息字体void setNoDataMessagePaint(Paint paint) 没有数据时显示的消息颜色CategoryPlot(Plot)类:void setDataset(CategoryDataset dataset) 数据区的2维数据表void setColumnRenderingOrder(SortOrder order) 数据分类的排序方式void setAxisOffset(Spacer offset) 坐标轴到数据区的间距void setOrientation(PlotOrientation orientation) 数据区的方向(PlotOrientation.HORIZONTAL或PlotOrientation.VERTICAL)void setDomainAxis(CategoryAxis axis) 数据区的分类轴void setDomainAxisLocation(AxisLocation location) 分类轴的位置(参数常量在org.jfree.chart.axis.AxisLocation类中定义)void setDomainGridlinesVisible(boolean visible) 分类轴网格是否可见void setDomainGridlinePaint(Paint paint) 分类轴网格线条颜色void setDomainGridlineStroke(Stroke stroke) 分类轴网格线条笔触void setRangeAxis(ValueAxis axis) 数据区的数据轴void setRangeAxisLocation(AxisLocation location) 数据轴的位置(参数常量在org.jfree.chart.axis.AxisLocation类中定义)void setRangeGridlinesVisible(boolean visible) 数据轴网格是否可见void setRangeGridlinePaint(Paint paint) 数据轴网格线条颜色void setRangeGridlineStroke(Stroke stroke) 数据轴网格线条笔触void setRenderer(CategoryItemRenderer renderer) 数据区的表示者(详见Renderer组)void addAnnotation(CategoryAnnotation annotation) 给数据区加一个注释void addRangeMarker(Marker marker,Layer layer) 给数据区加一个数值范围区域PiePlot(Plot)类:void setDataset(PieDataset dataset) 数据区的1维数据表void setIgnoreNullValues(boolean flag) 忽略无值的分类void setCircular(boolean flag) 饼图是否一定是正圆void setStartAngle(double angle) 饼图的初始角度void setDirection(Rotation direction) 饼图的旋转方向void setExplodePercent(int section,double percent) 抽取的那块(1维数据表的分类下标)以及抽取出来的距离(0.0~1.0),3D饼图无效void setLabelBackgroundPaint(Paint paint) 分类标签的底色void setLabelFont(Font font) 分类标签的字体void setLabelPaint(Paint paint) 分类标签的字体颜色void setLabelLinkMargin(double margin) 分类标签与图的连接线边距void setLabelLinkPaint(Paint paint) 分类标签与图的连接线颜色void setLabelLinkStroke(Stroke stroke) 分类标签与图的连接线笔触void setLabelOutlinePaint(Paint paint) 分类标签边框颜色void setLabelOutlineStroke(Paint paint) 分类标签边框笔触void setLabelShadowPaint(Paint paint) 分类标签阴影颜色void setMaximumLabelWidth(double width) 分类标签的最大长度(0.0~1.0)void setPieIndex(int index) 饼图的索引(复合饼图中用到)void setSectionOutlinePaint(int section,Paint paint) 指定分类饼的边框颜色void setSectionOutlineStroke(int section,Stroke stroke) 指定分类饼的边框笔触void setSectionPaint(int section,Paint paint) 指定分类饼的颜色void setShadowPaint(Paint paint) 饼图的阴影颜色void setShadowXOffset(double offset) 饼图的阴影相对图的水平偏移void setShadowYOffset(double offset) 饼图的阴影相对图的垂直偏移void setLabelGenerator(PieSectionLabelGenerator generator) 分类标签的格式,设置成null则整个标签包括连接线都不显示void setToolTipGenerator(PieToolTipGenerator generator) MAP中鼠标移上的显示格式void setURLGenerator(PieURLGenerator generator) MAP中钻取链接格式PiePlot3D(PiePlot)类:void setDepthFactor(double factor) 3D饼图的Z轴高度(0.0~1.0)MultiplePiePlot(Plot)类:void setLimit(double limit) 每个饼图之间的数据关联(详细比较复杂)void setPieChart(JFreeChart pieChart) 每个饼图的显示方式(见JFreeChart 类个PiePlot类)-----------------------------------------------------------------------------------------------------------AbstractRenderer类:void setItemLabelAnchorOffset(double offset) 数据标签的与数据点的偏移void setItemLabelsVisible(boolean visible) 数据标签是否可见void setItemLabelFont(Font font) 数据标签的字体void setItemLabelPaint(Paint paint) 数据标签的字体颜色void setItemLabelPosition(ItemLabelPosition position) 数据标签位置void setPositiveItemLabelPosition(ItemLabelPosition position) 正数标签位置void setNegativeItemLabelPosition(ItemLabelPosition position) 负数标签位置void setOutLinePaint(Paint paint) 图形边框的线条颜色void setOutLineStroke(Stroke stroke) 图形边框的线条笔触void setPaint(Paint paint) 所有分类图形的颜色void setShape(Shape shape) 所有分类图形的形状(如折线图的点)void setStroke(Stroke stroke) 所有分类图形的笔触(如折线图的线)void setSeriesItemLabelsVisible(int series,boolean visible) 指定分类的数据标签是否可见void setSeriesItemLabelFont(int series,Font font) 指定分类的数据标签的字体void setSeriesItemLabelPaint(int series,Paint paint) 指定分类的数据标签的字体颜色void setSeriesItemLabelPosition(int series,ItemLabelPosition position) 数据标签位置void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition position) 正数标签位置void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition position) 负数标签位置void setSeriesOutLinePaint(int series,Paint paint) 指定分类的图形边框的线条颜色void setSeriesOutLineStroke(int series,Stroke stroke) 指定分类的图形边框的线条笔触void setSeriesPaint(int series,Paint paint) 指定分类图形的颜色void setSeriesShape(int series,Shape shape) 指定分类图形的形状(如折线图的点)void setSeriesStroke(int series,Stroke stroke) 指定分类图形的笔触(如折线图的线)AbstractCategoryItemRenderer(AbstractRenderer)类:void setLabelGenerator(CategoryLabelGenerator generator) 数据标签的格式void setToolTipGenerator(CategoryToolTipGenerator generator) MAP中鼠标移上的显示格式void setItemURLGenerator(CategoryURLGenerator generator) MAP中钻取链接格式void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator)指定分类的数据标签的格式void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator) 指定分类的MAP中鼠标移上的显示格式void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator) 指定分类的MAP中钻取链接格式BarRenderer(AbstractCategoryItemRenderer)类:void setDrawBarOutline(boolean draw) 是否画图形边框void setItemMargin(double percent) 每个BAR之间的间隔void setMaxBarWidth(double percent) 每个BAR的最大宽度void setMinimumBarLength(double min) 最短的BAR长度,避免数值太小而显示不出void setPositiveItemLabelPositionFallback(ItemLabelPosition position) 无法在BAR中显示的正数标签位置void setNegativeItemLabelPositionFallback(ItemLabelPosition position) 无法在BAR中显示的负数标签位置BarRenderer3D(BarRenderer)类:void setWallPaint(Paint paint) 3D坐标轴的墙体颜色StackedBarRenderer(BarRenderer)类:没有特殊的设置StackedBarRenderer3D(BarRenderer3D)类:没有特殊的设置GroupedStackedBarRenderer(StackedBarRenderer)类:void setSeriesToGroupMap(KeyToGroupMap map) 将分类自由的映射成若干个组(KeyToGroupMap.mapKeyToGroup(series,group))LayeredBarRenderer(BarRenderer)类:void setSeriesBarWidth(int series,double width) 设定每个分类的宽度(注意设置不要使某分类被覆盖)WaterfallBarRenderer(BarRenderer)类:void setFirstBarPaint(Paint paint) 第一个柱图的颜色void setLastBarPaint(Paint paint) 最后一个柱图的颜色void setPositiveBarPaint(Paint paint) 正值柱图的颜色void setNegativeBarPaint(Paint paint) 负值柱图的颜色IntervalBarRenderer(BarRenderer)类:需要传IntervalCategoryDataset作为数据源GanttBarRenderer(IntervalBarRenderer)类:void setCompletePaint(Paint paint) 完成进度颜色void setIncompletePaint(Paint paint) 未完成进度颜色void setStartPercent(double percent) 设置进度条在整条中的起始位置(0.0~1.0)void setEndPercent(double percent) 设置进度条在整条中的结束位置(0.0~1.0)StatisticBarRenderer(BarRenderer)类:需要传StatisticCategoryDataset作为数据源LineAndShapeRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean draw) 是否折线的数据点之间用线连void setDrawShapes(boolean draw) 是否折线的数据点根据分类使用不同的形状void setShapesFilled(boolean filled) 所有分类是否填充数据点图形void setSeriesShapesFilled(int series,boolean filled) 指定分类是否填充数据点图形void setUseFillPaintForShapeOutline(boolean use) 指定是否填充数据点的Paint也被用于画数据点形状的边框LevelRenderer(AbstractCategoryItemRenderer)类:void setItemMargin(double percent) 每个分类之间的间隔void setMaxItemWidth(double percent) 每个分类的最大宽度CategoryStepRenderer(AbstractCategoryItemRenderer)类:void setStagger(boolean shouldStagger) 不同分类的图是否交错MinMaxCategoryRenderer(AbstractCategoryItemRenderer)类:void setDrawLines(boolean drawLines) 是否在每个分类线间画连接线void setGroupPaint(Paint groupPaint) 一组图形连接线的颜色void setGroupStroke(Stroke groupStroke) 一组图形连接线的笔触void setMaxIcon(Icon maxIcon) 最大值的ICONvoid setMinIcon(Icon minIcon) 最小值的ICONvoid setObjectIcon(Icon objectIcon) 所有值的ICONAreaRender(AbstractCategoryItemRenderer)类:没有特殊的设置StackedAreaRender(AreaRender)类:没有特殊的设置。