JChartFree使用散点图

代码如下
View Code
 1 import java.awt.Font;
 2 import java.io.File;
 3 import java.io.IOException;
 4 
 5 import org.jfree.chart.ChartFactory;
 6 import org.jfree.chart.ChartFrame;
 7 import org.jfree.chart.ChartUtilities;
 8 import org.jfree.chart.JFreeChart;
 9 import org.jfree.chart.StandardChartTheme;
10 import org.jfree.chart.plot.PiePlot;
11 import org.jfree.chart.plot.PiePlot3D;
12 import org.jfree.chart.plot.PlotOrientation;
13 import org.jfree.chart.title.TextTitle;
14 import org.jfree.data.category.DefaultCategoryDataset;
15 import org.jfree.data.general.DefaultPieDataset;
16 import org.jfree.data.xy.XYSeries;
17 import org.jfree.data.xy.XYSeriesCollection;
18 
19 
20 public class xy {
21 
22     /**
23      * @param args
24      */
25     public static void main(String[] args) {
26         // TODO Auto-generated method stub
27         XYSeries xyseries = new XYSeries("First"); 
28         xyseries.add(1.0D, 1.0D);
29         xyseries.add(2D, 4D);
30         xyseries.add(3D, 3D);
31         xyseries.add(4D, 5D);
32         xyseries.add(5D, 5D);
33         xyseries.add(6D, 7D);
34         xyseries.add(7D, 7D);
35         xyseries.add(8D, 8D);
36         XYSeries xyseries1 = new XYSeries("Second");
37         xyseries1.add(1.0D, 5D);
38         xyseries1.add(2D, 7D);
39         xyseries1.add(3D, 6D);
40         xyseries1.add(4D, 8D);
41         xyseries1.add(5D, 4D);
42         xyseries1.add(6D, 4D);
43         xyseries1.add(7D, 2D);
44         xyseries1.add(8D, 1.0D);
45 
46         XYSeries xyseries2 = new XYSeries("Third");
47         xyseries2.add(3D, 4D);
48         xyseries2.add(4D, 3D);
49         xyseries2.add(5D, 2D);
50         xyseries2.add(6D, 3D);
51         xyseries2.add(7D, 6D);
52         xyseries2.add(8D, 3D);
53         xyseries2.add(9D, 4D);
54         xyseries2.add(10D, 3D);
55 
56         XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //再用XYSeriesCollection添加入XYSeries 对象
57         xyseriescollection.addSeries(xyseries);
58         xyseriescollection.addSeries(xyseries1);
59         xyseriescollection.addSeries(xyseries2);
60 
61 
62 
63         //创建主题样式         
64         StandardChartTheme standardChartTheme=new StandardChartTheme("CN");        
65         //设置标题字体         
66         standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,20));        
67         //设置图例的字体        
68         standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,15));        
69         //设置轴向的字体       
70         standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,15));        
71         //应用主题样式      
72         ChartFactory.setChartTheme(standardChartTheme);  
73         //    JFreeChart chart=ChartFactory.createXYAreaChart("xyPoit", "点的标号", "出现次数", xyseriescollection, PlotOrientation.VERTICAL, true, false, false);
74         JFreeChart chart=ChartFactory.createScatterPlot("xyPoit", "点的标号", "出现次数", xyseriescollection, PlotOrientation.VERTICAL, true, false, false);
75         
76                 try {
77                     ChartUtilities.saveChartAsPNG(new File("E:/chart/BarChart3D.png"), chart, 500, 500);
78                 } catch (IOException e) {
79                     // TODO Auto-generated catch block
80                     e.printStackTrace();
81                 }
82 //        ChartFrame ChartFrame = new ChartFrame("水果产量图",chart);
83 //        ChartFrame.pack();
84 //        //ChartFrame.setFont(new Font("宋体",Font.BOLD,20));
85 //        ChartFrame.setVisible(true);
86 //        System.out.println("绘图完成"); 
87 
88     }
89 
90 }

 

转载于:https://www.cnblogs.com/xinyonde/archive/2012/12/31/2840441.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值