この記事では、参照用のJFreechartダイナミックラインチャートの特定のコードを共有しています。特定のコンテンツは次のとおりです
毎秒1回描き、1分後にもう一度描く
必要なJARパッケージは、gnujaxp.jar、jcommon-1.0.16.jar、jfreechart-1.0.13.jarです
パブリッククラスjfreezhexiantest {public static xyseries xycpuseries = new Xyseries( "cpu"); public static int数百= 0; public static jfreechart jfreechart = null; public jpanel getcpujfreechart(){jfreechart = chartfactory.createxylinechart(null、null、null、createdataset1()、plotorientation.vertical、false、true、false); StandardChartTheme MCHARTTHEME = new StandardChartTheme( "cn"); mcharttheme.setLargeFont(new Font( "Bold"、font.bold、20)); MCHARTTHEME.SETEXTRALARGEFONT(new Font( "Zongyi"、font.plain、15)); mChartTheme.set RegularFont(new Font( "Zongyi"、font.plain、15)); ChartFactory.setchArtTheme(MCHARTTHEME); jfreechart.setborderpaint(new Color(0,204,205)); jfreechart.setborderVisible(true); xyplot xyplot =(xyplot)jfreechart.getplot(); // y-axis numberaxis numberaxis =(numberaxis)xyplot.getrangeaxis(); numberaxis.setlowerbound(0); numberaxis.setupperbound(100); numberaxis.settickunit(new NumberTickunit(100D)); //整数値のみが表示されますnumberaxis.setStandardTickunits(numberAxis.createintegertickunits()); // numberaxis.setautorangeincludeszero(true); numberaxis.setlowermargin(0); //データ軸の下(左)マージン数字numberaxis.setminortickmarksvisible(false); //マーキングラインがnumberaxis.settickmarkinsidelength(0)を表示するかどうか。 //外側のダニの内向きの長さマーク数字numberaxis.settickmarkoutsidelength(0); // x軸の設計数字x =(numberaxis)xyplot.getdomainaxis(); x.setautorange(true); //データ軸のデータ範囲を自動的に設定しますX.SetticKunit(New NumberTickunit(60d)); //最大表示値と最小表示値x.setlowerbound(0)を設定します。 x.setupperbound(60); //データ軸のデータラベル:整数ラベルX.setStandardTickunits(numberaxis.createintegertickunits())のみを表示します。 x.setaxislinevisible(true); // x軸の垂直線がx.settickmarksvisible(false)を表示するかどうか。 //マーキングラインがrectangleInsetsを表示するかどうかオフセット=新しいrectangleInsets(0、0、0、0); xyplot.setaxisoffset(offset); //軸とデータ領域の間隔xyplot.setbackgroundalpha(0.0f); //バーチャートの背景色を削除xyplot.setoutlinepaint(null); // chartpanel.restoreautodomainbounds(); // x軸Chartpanel chartpanel = new Chartpanel(jfreechart、true);チャートパネルを返します。 } / ** *この方法は、データの設計 * * @return * / public static xydataset createdataset1(){xyseriescollection xyseriescolection = new XyseriesCollection(); xyseriescollection.addseries(xycpuseries); xyseriesCollectionを返します。 } / ***ランダム生成データ* / public static void dynamicrun(){int i = 0; while(true){double factor = math.random()*100;数百=(int)係数; jfreechart.settitle( "cpuのサイズは"+hundroud+"%"); jfreechart.getTitle()。setFont(new Font( "Microsoft Yahei"、0、16)); try {thread.currentthread(); thread.sleep(1000); } catch(arturnedexception e){e.printstacktrace(); } i ++; if(i == 60){i = 0; xycpuseries.delete(0、59);続く; }}} public static void main(string [] args){jfreezhexiantest jz = new jfreezhexiantest(); jframe frame = new JFrame(); frame.setsize(700、500); frame.getContentPane()。add(jz.getcpujfreechart()、borderlayout.center); frame.setVisible(true); frame.setlocationRelativeto(null); //ウィンドウは画面の中央にありますframe.setDefaultCloseoperation(windowconstants.exit_on_close); dynamicrun(); }}上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。