java实现各种数据统计图Word文件下载.docx

上传人:b****3 文档编号:7733339 上传时间:2023-05-09 格式:DOCX 页数:34 大小:653.23KB
下载 相关 举报
java实现各种数据统计图Word文件下载.docx_第1页
第1页 / 共34页
java实现各种数据统计图Word文件下载.docx_第2页
第2页 / 共34页
java实现各种数据统计图Word文件下载.docx_第3页
第3页 / 共34页
java实现各种数据统计图Word文件下载.docx_第4页
第4页 / 共34页
java实现各种数据统计图Word文件下载.docx_第5页
第5页 / 共34页
java实现各种数据统计图Word文件下载.docx_第6页
第6页 / 共34页
java实现各种数据统计图Word文件下载.docx_第7页
第7页 / 共34页
java实现各种数据统计图Word文件下载.docx_第8页
第8页 / 共34页
java实现各种数据统计图Word文件下载.docx_第9页
第9页 / 共34页
java实现各种数据统计图Word文件下载.docx_第10页
第10页 / 共34页
java实现各种数据统计图Word文件下载.docx_第11页
第11页 / 共34页
java实现各种数据统计图Word文件下载.docx_第12页
第12页 / 共34页
java实现各种数据统计图Word文件下载.docx_第13页
第13页 / 共34页
java实现各种数据统计图Word文件下载.docx_第14页
第14页 / 共34页
java实现各种数据统计图Word文件下载.docx_第15页
第15页 / 共34页
java实现各种数据统计图Word文件下载.docx_第16页
第16页 / 共34页
java实现各种数据统计图Word文件下载.docx_第17页
第17页 / 共34页
java实现各种数据统计图Word文件下载.docx_第18页
第18页 / 共34页
java实现各种数据统计图Word文件下载.docx_第19页
第19页 / 共34页
java实现各种数据统计图Word文件下载.docx_第20页
第20页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

java实现各种数据统计图Word文件下载.docx

《java实现各种数据统计图Word文件下载.docx》由会员分享,可在线阅读,更多相关《java实现各种数据统计图Word文件下载.docx(34页珍藏版)》请在冰点文库上搜索。

java实现各种数据统计图Word文件下载.docx

[plain] 

viewplaincopy

1. 

import 

java.awt.Font;

2. 

3.import 

org.jfree.chart.ChartFactory;

4.import 

org.jfree.chart.ChartPanel;

5.import 

org.jfree.chart.JFreeChart;

6.import 

org.jfree.chart.axis.CategoryAxis;

7.import 

org.jfree.chart.axis.ValueAxis;

8.import 

org.jfree.chart.plot.CategoryPlot;

9.import 

org.jfree.chart.plot.PlotOrientation;

10.import 

org.jfree.data.category.CategoryDataset;

11.import 

org.jfree.data.category.DefaultCategoryDataset;

12. 

13.public 

class 

BarChart 

14. 

ChartPanel 

frame1;

15. 

public 

BarChart(){ 

16. 

CategoryDataset 

dataset 

getDataSet();

17. 

JFreeChart 

chart 

ChartFactory.createBarChart3D( 

18. 

"

水果"

 

// 

图表标题 

19. 

水果种类"

目录轴的显示标签 

20. 

数量"

数值轴的显示标签 

21. 

dataset, 

数据集 

22. 

PlotOrientation.VERTICAL, 

图表方向:

水平、垂直 

23. 

true, 

是否显示图例(对于简单的柱状图必须是false) 

24. 

false, 

是否生成工具 

25. 

false 

是否生成URL链接 

26. 

);

27. 

28. 

//从这里开始 

29. 

CategoryPlot 

plot=chart.getCategoryPlot();

//获取图表区域对象 

30. 

CategoryAxis 

domainAxis=plot.getDomainAxis();

//水平底部列表 

31. 

domainAxis.setLabelFont(new 

Font("

黑体"

Font.BOLD,14));

//水平底部标题 

32. 

domainAxis.setTickLabelFont(new 

宋体"

Font.BOLD,12));

//垂直标题 

33. 

ValueAxis 

rangeAxis=plot.getRangeAxis();

//获取柱状 

34. 

rangeAxis.setLabelFont(new 

Font.BOLD,15));

35. 

chart.getLegend().setItemFont(new 

Font.BOLD, 

15));

36. 

chart.getTitle().setFont(new 

Font.BOLD,20));

//设置标题字体 

37. 

38. 

//到这里结束,虽然代码有点多,但只为一个目的,解决汉字乱码问题 

39. 

40. 

frame1=new 

ChartPanel(chart,true);

//这里也可以用chartFrame,可以直接生成一个独立的Frame 

41. 

42. 

43. 

private 

static 

getDataSet() 

44. 

DefaultCategoryDataset 

new 

DefaultCategoryDataset();

45. 

dataset.addValue(100, 

北京"

苹果"

46. 

上海"

47. 

广州"

48. 

dataset.addValue(200, 

梨子"

49. 

50. 

51. 

dataset.addValue(300, 

葡萄"

52. 

53. 

54. 

dataset.addValue(400, 

香蕉"

55. 

56. 

57. 

dataset.addValue(500, 

荔枝"

58. 

59. 

60. 

return 

dataset;

61.} 

62.public 

getChartPanel(){ 

63. 

64. 

65.} 

66.} 

效果图如下:

但我们把private 

CategoryDatasetgetDataSet(){}方法中的数据变化一下后,又会形成另一种效果,比如说我们改成:

1.private 

3. 

4. 

5. 

6. 

7. 

8. 

9.} 

三, 

实现饼状图的java代码:

package 

com.njue.testJFreeChart;

java.text.DecimalFormat;

java.text.NumberFormat;

javax.swing.JPanel;

12.import 

org.jfree.chart.labels.StandardPieSectionLabelGenerator;

13.import 

org.jfree.chart.plot.PiePlot;

14.import 

org.jfree.data.general.DefaultPieDataset;

16.public 

PieChart 

PieChart(){ 

DefaultPieDataset 

data 

ChartFactory.createPieChart3D("

水果产量"

data,true,false,false);

//设置百分比 

PiePlot 

pieplot 

(PiePlot) 

chart.getPlot();

DecimalFormat 

df 

DecimalFormat("

0.00%"

//获得一个DecimalFormat对象,主要是设置小数问题 

NumberFormat 

nf 

NumberFormat.getNumberInstance();

//获得一个NumberFormat对象 

StandardPieSectionLabelGenerator 

sp1 

StandardPieSectionLabelGenerator("

{0} 

{2}"

nf, 

df);

//获得StandardPieSectionLabelGenerator对象 

pieplot.setLabelGenerator(sp1);

//设置饼图显示百分比 

//没有数据的时候显示的内容 

pieplot.setNoDataMessage("

无数据显示"

pieplot.setCircular(false);

pieplot.setLabelGap(0.02D);

pieplot.setIgnoreNullValues(true);

//设置不显示空值 

pieplot.setIgnoreZeroValues(true);

//设置不显示负值 

(chart,true);

piePlot= 

piePlot.setLabelFont(new 

Font.BOLD,10));

//解决乱码 

DefaultPieDataset();

dataset.setValue("

100);

200);

300);

400);

500);

49.} 

54.} 

四, 

实现折线图的java代码:

1.package 

java.text.SimpleDateFormat;

org.jfree.chart.axis.DateAxis;

org.jfree.chart.plot.XYPlot;

org.jfree.data.time.Month;

org.jfree.data.time.TimeSeries;

org.jfree.data.time.TimeSeriesCollection;

15.import 

org.jfree.data.xy.XYDataset;

17.public 

TimeSeriesChart 

TimeSeriesChart(){ 

XYDataset 

xydataset 

createDataset();

jfreechart 

ChartFactory.createTimeSeriesChart("

Legal 

&

General单位信托基金价格"

日期"

价格"

xydataset, 

true);

XYPlot 

xyplot 

(XYPlot) 

jfreechart.getPlot();

DateAxis 

dateaxis 

(DateAxis) 

xyplot.getDomainAxis();

dateaxis.setDateFormatOverride(new 

SimpleDateFormat("

MMM-yyyy"

));

ChartPanel(jfreechart,true);

dateaxis.setLabelFont(new 

dateaxis.setTickLabelFont(new 

rangeAxis=xyplot.getRangeAxis();

jfreechart.getLegend().setItemFont(new 

jfreechart.getTitle().setFont(new 

createDataset() 

//这个数据集有点多,但都不难理解 

TimeSeries 

timeseries 

TimeSeries("

legal 

general欧洲指数信任"

org.jfree.data.time.Month.class);

timeseries.add(new 

Month(2, 

2001), 

181.80000000000001D);

Month(3, 

167.30000000000001D);

Month(4, 

153.80000000000001D);

Month(5, 

167.59999999999999D);

Month(6, 

158.80000000000001D);

Month(7, 

148.30000000000001D);

Month(8, 

153.90000000000001D);

Month(9, 

142.69999999999999D);

Month(10, 

123.2D);

Month(11, 

131.80000000000001D);

Month(12, 

139.59999999999999D);

Month(1, 

2002), 

142.90000000000001D);

138.69999999999999D);

timeseries.add(n

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2