JFreeChart数据图表示例_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > JFreeChart数据图表示例

JFreeChart数据图表示例

 2013/11/5 21:36:42  wokao159  程序员俱乐部  我要评论(0)
  • 摘要:importjava.awt.Font;importjava.io.File;importorg.jfree.chart.ChartFactory;importorg.jfree.chart.ChartFrame;importorg.jfree.chart.ChartUtilities;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.labels.StandardCategoryItemLabelGenerator
  • 标签:数据
    class="dp-j" style="font-size: 12px; margin-bottom: 1px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace;">
  1. import?java.awt.Font;??
  2. import?java.io.File;??
  3. ??
  4. import?org.jfree.chart.ChartFactory;??
  5. import?org.jfree.chart.ChartFrame;??
  6. import?org.jfree.chart.ChartUtilities;??
  7. import?org.jfree.chart.JFreeChart;??
  8. import?org.jfree.chart.labels.StandardCategoryItemLabelGenerator;??
  9. import?org.jfree.chart.plot.CategoryPlot;??
  10. import?org.jfree.chart.plot.PiePlot;??
  11. import?org.jfree.chart.plot.PlotOrientation;??
  12. import?org.jfree.chart.renderer.category.LineAndShapeRenderer;??
  13. import?org.jfree.data.category.DefaultCategoryDataset;??
  14. import?org.jfree.data.general.DefaultPieDataset;??
  15. ??
  16. public?class?TestJFreeChart?{??
  17. ??
  18. ????public?static?void?main(String[]?args)?throws?Exception{??
  19. ??????????
  20. ????????System.out.println("start...");??
  21. ??????????
  22. ????????//测试饼图??
  23. ????????testPieChart();??
  24. ??????????
  25. ????????//测试折线图??
  26. ????????testLineChart();??
  27. ??????????
  28. ????????System.out.println("complete...");??
  29. ????}??
  30. ??
  31. ????/**?
  32. ?????*??
  33. ?????*?测试饼图?
  34. ?????*??
  35. ?????*?cjnetwork?2010-11-17下午05:21:15?
  36. ?????*/??
  37. ????private?static?void?testPieChart()?throws?Exception{??
  38. ????????DefaultPieDataset?dataset?=?new?DefaultPieDataset();??
  39. ??????????
  40. ????????dataset.setValue("初中",?25);??
  41. ????????dataset.setValue("高中",?55);??
  42. ????????dataset.setValue("大学",?100);??
  43. ??????????
  44. ????????JFreeChart?chart?=?ChartFactory.createPieChart3D("学历分布图",?dataset,?true,?true,?true);??
  45. ??????????
  46. ????????Font?font?=?new?Font("黑体",?Font.BOLD,?15);??
  47. ????????chart.getTitle().setFont(font);??
  48. ????????chart.getLegend().setItemFont(font);??
  49. ????????((PiePlot)chart.getPlot()).setLabelFont(font);??
  50. ??????????
  51. ????????ChartFrame?frame?=?new?ChartFrame("学历分布图",?chart);??
  52. ????????frame.pack();??
  53. ????????frame.setVisible(true);??
  54. ????????ChartUtilities.saveChartAsJPEG(new?File("d:/testPieChart.jpg"),?chart,?1024,?768);??
  55. ????}??
  56. ??
  57. ????/**?
  58. ?????*??
  59. ?????*?测试折线图?
  60. ?????*??
  61. ?????*?cjnetwork?2010-11-17下午05:21:07?
  62. ?????*/??
  63. ????private?static?void?testLineChart()?throws?Exception{??
  64. ??????????
  65. ????????DefaultCategoryDataset?dataset?=?new?DefaultCategoryDataset();??
  66. ??????????
  67. ????????dataset.addValue(100,?"苹果",?"2010-10-01");??
  68. ????????dataset.addValue(150,?"香蕉",?"2010-10-01");??
  69. ????????dataset.addValue(130,?"葡萄",?"2010-10-01");??
  70. ????????dataset.addValue(120,?"梨",?"2010-10-01");??
  71. ??????????
  72. ????????dataset.addValue(110,?"苹果",?"2010-10-02");??
  73. ????????dataset.addValue(160,?"香蕉",?"2010-10-02");??
  74. ????????dataset.addValue(70,?"葡萄",?"2010-10-02");??
  75. ????????dataset.addValue(145,?"梨",?"2010-10-02");??
  76. ??????????
  77. ????????dataset.addValue(150,?"苹果",?"2010-10-03");??
  78. ????????dataset.addValue(168,?"香蕉",?"2010-10-03");??
  79. ????????dataset.addValue(60,?"葡萄",?"2010-10-03");??
  80. ????????dataset.addValue(148,?"梨",?"2010-10-03");??
  81. ??????????
  82. ????????dataset.addValue(140,?"苹果",?"2010-10-04");??
  83. ????????dataset.addValue(190,?"香蕉",?"2010-10-04");??
  84. ????????dataset.addValue(60,?"葡萄",?"2010-10-04");??
  85. ????????dataset.addValue(163,?"梨",?"2010-10-04");??
  86. ??????????
  87. ????????JFreeChart?chart?=?ChartFactory.createLineChart("水果产量图",?"时间",?"产量",?dataset,?PlotOrientation.VERTICAL,?true,?true,?true);??
  88. ????????CategoryPlot?plot?=?chart.getCategoryPlot();??
  89. ????????plot.getRangeAxis().setUpperMargin(0.15);??
  90. ??????????
  91. ????????Font?font?=?new?Font("黑体",?Font.BOLD,?15);??
  92. ????????chart.getLegend().setItemFont(font);??
  93. ????????chart.getTitle().setFont(font);??
  94. ????????plot.getDomainAxis().setTickLabelFont(font);??
  95. ????????plot.getDomainAxis().setLabelFont(font);??
  96. ????????plot.getRangeAxis().setLabelFont(font);??
  97. ??????????
  98. ????????LineAndShapeRenderer?lineAndShapeRenderer?=?(LineAndShapeRenderer)?plot.getRenderer();??
  99. ????????lineAndShapeRenderer.setBaseLinesVisible(true);??
  100. ????????lineAndShapeRenderer.setBaseShapesVisible(true);??
  101. ????????lineAndShapeRenderer.setBaseItemLabelGenerator(new?StandardCategoryItemLabelGenerator());??
  102. ????????lineAndShapeRenderer.setBaseItemLabelsVisible(true);??
  103. ??????????
  104. ????????ChartFrame?frame?=?new?ChartFrame("水果产量图",?chart);??
  105. ????????frame.pack();??
  106. ????????frame.setVisible(true);???
  107. ??????????
  108. ????????ChartUtilities.saveChartAsJPEG(new?File("d:/testLineChart.jpg"),?chart,?1024,?768);??
  109. ????}??
  110. ??????
  111. ??????
  112. }
发表评论
用户名: 匿名