问题描述
packagefangp;importjava.io.*;importjava.sql.*;importorg.jfree.data.*;importorg.jfree.data.category.*;importorg.jfree.chart.*;importorg.jfree.chart.plot.*;importorg.jfree.chart.axis.*;importjava.awt.Font;importjava.awt.geom.Ellipse2D.Float;importorg.jfree.chart.title.TextTitle;importorg.jfree.chart.title.LegendTitle;publicclassBarChart3D{publicstaticvoidmain(String[]args)throwsException{JFreeChartchart=ChartFactory.createBarChart3D("营业员营业额统计图",//图表标题"营业员",//目录轴的显示标签"营业额",//数值轴的显示标签getDataSet(),//数据集//PlotOrientation.HORIZONTAL,//图表方向:水平PlotOrientation.VERTICAL,//图表方向:垂直true,//是否显示图例(对于简单的柱状图必须是false)false,//是否生成工具false//是否生成URL链接);//重新设置图标标题,改变字体chart.setTitle(newTextTitle("营业员营业额统计图",newFont("黑体",Font.ITALIC,22)));//取得统计图标的第一个图例LegendTitlelegend=chart.getLegend(0);//修改图例的字体legend.setItemFont(newFont("宋体",Font.BOLD,14));CategoryPlotplot=(CategoryPlot)chart.getPlot();//取得横轴CategoryAxiscategoryAxis=plot.getDomainAxis();//设置横轴显示标签的字体categoryAxis.setLabelFont(newFont("宋体",Font.BOLD,22));//分类标签以45度角倾斜categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);categoryAxis.setTickLabelFont(newFont("宋体",Font.BOLD,18));//取得纵轴NumberAxisnumberAxis=(NumberAxis)plot.getRangeAxis();//设置纵轴显示标签的字体numberAxis.setLabelFont(newFont("宋体",Font.BOLD,22));FileOutputStreamfos=null;fos=newFileOutputStream("sale.jpg");//将统计图标输出成JPG文件ChartUtilities.writeChartAsJPEG(fos,//输出到哪个输出流1,//JPEG图片的质量,0~1之间chart,//统计图标对象800,//宽600,//宽null//ChartRenderingInfo信息);fos.close();}//返回一个CategoryDataset实例privatestaticCategoryDatasetgetDataSet()throwsException{Connectionconn=DbConn.getConn();Statementstmt=conn.createStatement();Stringsql="selectsum(sale),month(sale_date),sale_namefromfgp"+"groupbymonth(sale_date),sale_name";ResultSetrs=stmt.executeQuery(sql);DefaultCategoryDatasetdataset=newDefaultCategoryDataset();while(rs.next()){dataset.addValue(rs.getInt(1),rs.getString(2)+"月份",rs.getString(3));}returndataset;}}此代码是直接生成图片的,我想改下但是java还不是很熟练,请问要窗口的代码要加的哪里才能使输出是用窗口的?
解决方案
解决方案二:
publicstaticvoidmain(Stringargs[]){String[]str=newString[16];for(inti=1;i<13;i++){str[i-1]="08"+(i<10?("0"+i):""+i);}str[12]="0901";str[13]="0902";str[14]="0903";str[15]="0904";//折点值float[]value=newfloat[16];for(inti=0;i<value.length;i++){value[i]=i+2;}DefaultCategoryDatasetdgd=newDefaultCategoryDataset();for(inti=0;i<value.length;i++){dgd.addValue(value[i],"2007年",str[i]);}JFreeChartjfc=ChartFactory.createLineChart("标题","","二",dgd,PlotOrientation.VERTICAL,true,true,false);//取得统计图表的第一个图例LegendTitlelegend=jfc.getLegend(0);legend.setVisible(false);//按曲线图创建chartPanelChartPanelchartPanel=newChartPanel(jfc);JPanelcontent=newJPanel(newBorderLayout());content.add(chartPanel,BorderLayout.CENTER);//JLayeredPanejlp=newJLayeredPane();//jlp.add(chartPanel,newInteger(100));//创建tablefinalMyCellRenderer2mcr=newMyCellRenderer2();JTablejtable=newJTable(newDemoTableModel(3,value.length+1)){publicTableCellRenderergetCellRenderer(introw,intcolumn){returnmcr;}};//JTablejtable=getJTable(3,value.length+1);JPaneltablePanel=newJPanel(newBorderLayout());tablePanel.setPreferredSize(newDimension(800,52));tablePanel.add(newJScrollPane(jtable));//jtable.setForeground(Color.RED);//jtable.setSelectionForeground(Color.RED);jtable.setValueAt("黄色标题",0,0);jtable.setValueAt("蓝色标题",1,0);jtable.setValueAt("红色标题",2,0);content.add(tablePanel,BorderLayout.SOUTH);JFramejf=newJFrame();jf.add(content);//jf.add(jlp);jf.pack();jf.setVisible(true);}}