您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > JAVA时间动态时序图的代码
JAVA时间动态时序图的代码importjava.awt.Color;importjava.io.FileInputStream;importjava.io.InputStream;importjava.util.Scanner;importjxl.Cell;importjxl.Sheet;importjxl.Workbook;importorg.jfree.chart.ChartFactory;importorg.jfree.chart.ChartPanel;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.StandardChartTheme;importorg.jfree.chart.axis.ValueAxis;importorg.jfree.chart.plot.PieLabelLinkStyle;importorg.jfree.chart.plot.XYPlot;import@SuppressWarnings(serial)publicclassTest9extendsChartPanelimplementsRunnable{privatestaticTimeSeriestimeSeries;publicTest9(StringchartContent,Stringtitle,StringyaxisName){super(createChart(chartContent,title,yaxisName));}@SuppressWarnings(deprecation)privatestaticJFreeChartcreateChart(StringchartContent,Stringtitle,StringyaxisName){StandardChartThemechartTheme=newStandardChartTheme(CN);chartTheme.setTitlePaint(newColor(51,51,51));//Paint可以理解为绘制颜色;标题字体颜色chartTheme.setSubtitlePaint(newColor(85,85,85));//副标题字体颜色chartTheme.setLegendBackgroundPaint(Color.WHITE);//设置标注背景色chartTheme.setLegendItemPaint(Color.BLACK);//设置字体颜色chartTheme.setChartBackgroundPaint(Color.WHITE);//图表背景色chartTheme.setPlotBackgroundPaint(Color.WHITE);//绘制区域背景色chartTheme.setPlotOutlinePaint(Color.WHITE);//绘制区域外边框chartTheme.setLabelLinkPaint(newColor(8,55,114));//链接标签颜色chartTheme.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);ChartFactory.setChartTheme(chartTheme);//设置主题样式//创建时序图对象timeSeries=newTimeSeries(chartContent,Millisecond.class);TimeSeriesCollectiontimeseriescollection=newTimeSeriesCollection(timeSeries);JFreeChartchart=ChartFactory.createTimeSeriesChart(title,time(minutes),yaxisName,timeseriescollection,true,true,false);XYPlotxyplot=chart.getXYPlot();//纵坐标设定ValueAxisvalueaxis=xyplot.getDomainAxis();//自动设置数据轴数据范围valueaxis.setAutoRange(true);//数据轴固定数据范围30svalueaxis.setFixedAutoRange(30000D);valueaxis=xyplot.getRangeAxis();//valueaxis.setRange(0.0D,200D);returnchart;}publicvoidrun(){doublea[]=newdouble[3003];jxl.Workbookrwb=null;System.out.println(请输入你要查看的曲线图的名字,查看lorenza输入1,lorenzb输入2,lorenzc输入3);Scannerin=newScanner(System.in);StringA=in.next();if(A.equals(1)){try{InputStreamis=newFileInputStream(D:\\lorenza.et);rwb=Workbook.getWorkbook(is);Sheetrs=rwb.getSheet(0);//获取Sheet表中所包含的总列数intrsColumns=rs.getColumns();//获取Sheet表中所包含的总行数intrsRows=rs.getRows();for(intj=0;jrsColumns;j++){for(inti=2;irsRows;i++){Cellcell=rs.getCell(j,i);a[i]=Double.parseDouble(cell.getContents());try{System.out.println(a[i]);timeSeries.add(newMillisecond(),a[i]);Thread.sleep(100);}catch(InterruptedExceptione){}}}}catch(Exceptione){e.printStackTrace();}finally{rwb.close();}}if(A.equals(2)){try{InputStreamis=newFileInputStream(D:\\lorenzb.et);rwb=Workbook.getWorkbook(is);Sheetrs=rwb.getSheet(0);//获取Sheet表中所包含的总列数intrsColumns=rs.getColumns();//获取Sheet表中所包含的总行数intrsRows=rs.getRows();for(intj=0;jrsColumns;j++){for(inti=2;irsRows;i++){Cellcell=rs.getCell(j,i);a[i]=Double.parseDouble(cell.getContents());try{System.out.println(a[i]);timeSeries.add(newMillisecond(),a[i]);Thread.sleep(100);}catch(InterruptedExceptione){}}}}catch(Exceptione){e.printStackTrace();}finally{rwb.close();}//}if(A.equals(3)){try{InputStreamis=newFileInputStream(D:\\lorenzc.et);rwb=Workbook.getWorkbook(is);Sheetrs=rwb.getSheet(0);//获取Sheet表中所包含的总列数intrsColumns=rs.getColumns();//获取Sheet表中所包含的总行数intrsRows=rs.getRows();for(intj=0;jrsColumns;j++){for(inti=2;irsRows;i++){Cellcell=rs.getCell(j,i);a[i]=Double.parseDouble(cell.getContents());try{System.out.println(a[i]);timeSeries.add(newMillisecond(),a[i]);Thread.sleep(100);}catch(InterruptedExceptione){}}}}catch(Exceptione){e.printStackTrace();}finally{rwb.close();}}//if(A.equals(12)){//try{//InputStreamis=newFileInputStream(D:\\lorenza.et);//rwb=Workbook.getWorkbook(is);//Sheetrs=rwb.getSheet(0);////获取Sheet表中所包含的总列数//intrsColumns=rs.getColumns();////获取Sheet表中所包含的总行数//intrsRows=rs.getRows();//for(intj=0;jrsColumns;j++){//for(inti=2;irsRows;i++){////Cellcell=rs.getCell(j,i);//a[i]=Double.parseDouble(cell.getContents());//try{//System.out.println(a[i]);//timeSeries.add(newMillisecond(),a[i]);//Thread.sleep(100);////}catch(InterruptedExceptione){//}//}//}//}catch(Exceptione){//e.printStackTrace();//}finally{//rwb.close();//}////}//}//publicstaticvoidmain(String[]args){////JFrameframe=newJFrame(TimeseriesChart);////Test9rtcp=newTest9(Timeseries,Chart,value);//newBorderLayout();//frame.getContentPane().add(rtcp,BorderLayout.CENTER);//frame.pack();//frame.setVisible(true);//(newThread(rtcp)).start();////frame.addWindowListener(newWindowAdapter(){//publicvoidwindowClosing(WindowEventwindowevent){//System.exit(0);//}//});//JButtonbtnNewButton=newJButton(Newbutton);//con.add(btnNewButton,BorderLayout.WEST);}}importjava.awt.BorderLayout;importjava.awt.EventQueue;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjavax.swing.JFileChooser;importjavax.swing.JFrame;imp
本文标题:JAVA时间动态时序图的代码
链接地址:https://www.777doc.com/doc-7845679 .html