柱状图:

1. package
2.   
3. import
4. import
5. import
6. import
7. import
8.   
9. import
10. import
11. import
12. import
13. import
14. import
15. import
16. import
17. import
18. import
19. import
20. import
21.   
22. /**
23.  * @author shenchao
24.  *      柱状图
25.  */
26. public class
27.   
28. public
29.         Map<String,Integer> map = initDataSet();  
30.         showChart(map);  
31.     }  
32.   
33. /**
34.      *  初始化数据集
35.      *      柱状图的数据集接受三个参数,第一个参数为柱子的高度,第二个为几个类别进行比较,第三个为共有几组数据
36.      *  
37.      * @return
38.      */
39. private
40. return null;  
41.     }  
42.   
43. /**
44.      * @param map
45.      */
46. private void
47. // 创建饼图数据对象
48. new
49.         Set<Entry<String, Integer>> set = map.entrySet();  
50. for
51. "评论数量",entry.getKey());  
52.         }  
53.           
54. "评论次数TOP10", "好友昵称",  
55. "评论数量", dataset, PlotOrientation.VERTICAL, false, true, true);  
56. new ChartFrame("评论次数TOP10", chart, true);  
57. // 自定义设定背景色
58. // chart.setBackgroundPaint(Color.getHSBColor(23,192,223));
59.         chart.setBackgroundPaint(Color.WHITE);  
60. // 获得 plot:3dBar为CategoryPlot
61.         CategoryPlot categoryPlot = chart.getCategoryPlot();  
62. // 设定图表数据显示部分背景色
63.         categoryPlot.setBackgroundPaint(Color.WHITE);  
64. // 横坐标网格线
65.         categoryPlot.setDomainGridlinePaint(Color.GRAY);  
66. // 设置网格线可见
67. true);  
68. // 纵坐标网格线
69.         categoryPlot.setRangeGridlinePaint(Color.GRAY);  
70. // 重要的类,负责生成各种效果
71. // BarRenderer3D renderer=(BarRenderer3D) categoryPlot.getRenderer();
72. // 获取纵坐标
73.         NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis();  
74.           
75. // 设置纵坐标的标题字体和大小
76. new Font("黑体", Font.CENTER_BASELINE, 16));  
77. // 设置丛坐标的坐标值的字体颜色
78.         numberaxis.setLabelPaint(Color.BLACK);  
79. // 设置丛坐标的坐标轴标尺颜色
80.         numberaxis.setTickLabelPaint(Color.BLACK);  
81. // 坐标轴标尺颜色
82.         numberaxis.setTickMarkPaint(Color.BLUE);  
83. // 丛坐标的默认间距值
84. // numberaxis.setAutoTickUnitSelection(true);
85. // 设置丛坐标间距值
86. true);  
87. // numberaxis.setTickUnit(new NumberTickUnit(150));
88.           
89. //在柱体的上面显示数据 
90. new
91. //数据字体的颜色 
92. new
93. true);   
94.         categoryPlot.setRenderer(custombarrenderer3d);   
95.           
96.           
97. // 获取横坐标
98.         CategoryAxis domainAxis = categoryPlot.getDomainAxis();  
99. // 设置横坐标的标题字体和大小
100. new Font("宋体", Font.PLAIN, 16));  
101. // 设置横坐标的坐标值的字体颜色
102.         domainAxis.setTickLabelPaint(Color.GRAY);  
103. // 设置横坐标的坐标值的字体
104. new Font("宋体", Font.PLAIN, 16));  
105. // 设置横坐标的显示
106.         domainAxis.setCategoryLabelPositions(CategoryLabelPositions  
107. 0.4));  
108. // 这句代码解决了底部汉字乱码的问题
109. //      chart.getLegend().setItemFont(new Font("黑体", 0, 16));
110. // 设置图例标题
111. new java.awt.Font("黑体", java.awt.Font.CENTER_BASELINE, 20);  
112. new TextTitle("谁是评论你最多的人?");  
113.         title.getBackgroundPaint();  
114.         title.setFont(font);  
115. // 设置标题的字体颜色
116.         chart.setTitle(title);  
117.         frame.pack();  
118. true);  
119.     }  
120.   
121. }

java编写图片表格 java 图表_数据



折线图:

1. package
2.   
3. import
4. import
5. import
6. import
7. import
8. import
9. import
10. import
11. import
12. import
13. import
14. import
15. import
16. import
17. import
18. import
19. import
20.   
21. public class
22.   
23. public
24.         Map<Integer, Integer> map = initDataSet();  
25.         showChart(map);  
26.     }  
27.   
28. /**
29.      *  初始化数据集
30.      *      柱状图的数据集接受三个参数,第一个参数为柱子的高度,第二个为几个类别进行比较,第三个为共有几组数据
31.      *  
32.      * @return
33.      */
34. private
35. return null;  
36.     }  
37.   
38. private void
39. // 创建饼图数据对象
40. new
41.         Set<Entry<Integer, Integer>> set = map.entrySet();  
42. for
43. "数量", entry.getKey());  
44.         }  
45.   
46. // 如果把createLineChart改为createLineChart3D就变为了3D效果的折线图
47. "每年说说的发布量", "年份", "数目",  
48. // 绘制方向
49. false, // 显示图例
50. true, // 采用标准生成器
51. false // 是否生成超链接
52.                 );  
53. new ChartFrame("图表标题", chart, true);  
54. // 设置背景色
55. // 获取绘图区对象
56.         CategoryPlot plot = chart.getCategoryPlot();  
57. // 设置绘图区背景色
58. // 设置水平方向背景线颜色
59. true);// 设置是否显示水平方向背景线,默认值为true
60. // 设置垂直方向背景线颜色
61. true); // 设置是否显示垂直方向背景线,默认值为false
62.   
63.         CategoryAxis domainAxis = plot.getDomainAxis();  
64. 0.01);// 左边距 边框距离
65. 0.06);// 右边距 边框距离,防止最后边的一个数据靠近了坐标轴。
66. 2);  
67. new Font("宋体", Font.PLAIN, 16));  
68.   
69.         ValueAxis rangeAxis = plot.getRangeAxis();  
70. // Y轴显示整数
71. 1); // 最小跨度
72. 0.18);// 上边距,防止最大的一个数据靠近了坐标轴。
73. 0); // 最小值显示0
74. false); // 不自动分配Y轴数据
75. new BasicStroke(1.6f)); // 设置坐标标记大小
76. // 设置坐标标记颜色
77. new Font("宋体", Font.PLAIN, 16));  
78.   
79. // 获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
80.         LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) plot  
81.                 .getRenderer();  
82. true); // series 点(即数据点)可见
83.   
84. true);  
85. // 显示折点数据
86.         lineandshaperenderer  
87. new
88. true);  
89.   
90.         frame.pack();  
91. true);  
92.     }  
93. }

java编写图片表格 java 图表_数据_02

饼图:

    1. package
    2.   
    3. import
    4. import
    5. import
    6. import
    7. import
    8. import
    9. import
    10. import
    11. import
    12. import
    13. import
    14. import
    15. import
    16.   
    17. /**
    18.  * @author shenchao
    19.  *      饼图
    20.  */
    21. public class
    22.       
    23. public
    24.         Map<String,Integer> map = initDataSet();  
    25.         showChart(map);  
    26.     }  
    27.   
    28.       
    29. /**
    30.      *  饼图接受的数据集要求是键值对<br>
    31.      * 
    32.      *      可以在这里初始化数据集
    33.      * @return map
    34.      */
    35. private
    36. return null;  
    37.     }  
    38.   
    39. /**
    40.      *  显示图表
    41.      * @param map
    42.      */
    43. private void
    44.   
    45. // 创建饼图数据对象
    46. new
    47.         Set<Entry<String, Integer>> set = map.entrySet();  
    48. for
    49.             dfp.setValue(entry.getKey(), entry.getValue());  
    50.         }  
    51. // createpieChart3D创建3D饼图
    52. "窗口标题",  
    53. true, true, true);  
    54. // 图片背景色
    55.         chart.setBackgroundPaint(Color.white);  
    56. // 设置标题文字
    57. new ChartFrame("窗口标题", chart, true);  
    58. // 取得3D饼图对象
    59.         PiePlot3D plot = (PiePlot3D) chart.getPlot();  
    60. // 图形边框颜色
    61.         plot.setBaseSectionOutlinePaint(Color.WHITE);  
    62. // 图形边框粗细
    63. new BasicStroke(1.0f));  
    64. // 指定图片的透明度(0.0-1.0)
    65. 0.45f);  
    66. // 指定显示的饼图上圆形(false)还椭圆形(true)
    67. true);  
    68. // 设置第一个 饼块section 的开始位置,默认是12点钟方向
    69. 360);  
    70. // 设置鼠标悬停提示
    71. new
    72. // 设置饼图各部分标签字体
    73. new Font("微软雅黑", Font.ITALIC, 16));  
    74. // 设置分饼颜色
    75. 0, new Color(244, 194, 144));  
    76. // 定义字体格式  
    77. new java.awt.Font("黑体", java.awt.Font.CENTER_BASELINE,20);    
    78. new TextTitle("图表标题");    
    79.         title.setFont(font);    
    80. // 设置字体,非常关键不然会出现乱码的,下方的字体  
    81.         chart.setTitle(title);    
    82.         frame.pack();   
    83. true);  
    84.     }  
    85.   
    86. }


    java编写图片表格 java 图表_数据_03



    散点图:

      1. package
      2.   
      3. import
      4. import
      5. import
      6. import
      7. import
      8.   
      9. import
      10. import
      11. import
      12. import
      13. import
      14. import
      15. import
      16. import
      17. import
      18.   
      19. /**
      20.  * @author shenchao 散点图
      21.  */
      22. public class
      23.   
      24. public
      25.         Map<Integer,List<Data>> map = initDataSet();  
      26.         showChart(map);  
      27.     }  
      28.   
      29. /**
      30.      *  这里的Data类是数据的封装,可以安装实际需求实现,map集合的键为类别
      31.      */
      32. private
      33. return null;  
      34.     }  
      35.   
      36. public void
      37.           
      38. new
      39.           
      40. //根据类别建立数据集
      41. for
      42.             List<Data> l = entry.getValue();  
      43.               
      44. int
      45. //散点图要求数据集为二维数组
      46. double[][] datas = new double[2][size];  
      47. for (int i = 0; i < size; i++) {  
      48.                 Data data = l.get(i);  
      49. 0][i] = data.getDistance();  
      50. 1][i] = data.getIcecream();  
      51.             }  
      52.             xydataset.addSeries(entry.getKey(), datas);  
      53.         }  
      54.           
      55. "散点图", "每年获取的飞行常客里程数", "每周所消费的冰淇淋公升数", xydataset, PlotOrientation.VERTICAL, true, false, false);  
      56. new ChartFrame("散点图", chart, true);  
      57.         chart.setBackgroundPaint(Color.white);    
      58.         chart.setBorderPaint(Color.GREEN);    
      59. new BasicStroke(1.5f));    
      60.         XYPlot xyplot = (XYPlot) chart.getPlot();    
      61.     
      62. new Color(255, 253, 246));    
      63.         ValueAxis vaaxis = xyplot.getDomainAxis();    
      64. new BasicStroke(1.5f));    
      65.     
      66. 0);    
      67. new BasicStroke(1.5f));    
      68.     
      69. new BasicStroke(1.5f)); // 坐标轴粗细  
      70. new Color(215, 215, 215)); // 坐标轴颜色  
      71. new BasicStroke(1.5f)); // 边框粗细  
      72. new Color(10, 10, 10)); // 坐标轴标题颜色  
      73. new Color(102, 102, 102)); // 坐标轴标尺值颜色  
      74.         ValueAxis axis = xyplot.getRangeAxis();    
      75. new BasicStroke(1.5f));    
      76.     
      77.         XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot    
      78.                 .getRenderer();    
      79. 0, Color.WHITE);    
      80. true);    
      81.         NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();    
      82. false);    
      83. 2.0F);    
      84. 0.0F);    
      85. new BasicStroke(1.5f));    
      86.           
      87.         frame.pack();  
      88. true);  
      89.     }  
      90.   
      91. }


      java编写图片表格 java 图表_java_04