이 기사에서는 참조에 대한 JFreeChart 동적 라인 차트의 특정 코드를 공유합니다. 특정 내용은 다음과 같습니다
1 분마다 한 번씩 그리고 1 분 후에 다시 그리십시오.
필요한 JAR 패키지는 다음과 같습니다
공개 클래스 jfreezhexiantest {public static xyseries xycpuseries = new xyseries ( "CPU"); 공개 정적 int 수백 = 0; 공개 정적 jfreechart jfreechart = null; public jpanel getcpujfreechart () {jfreechart = chartfactory.creexylinechart (null, null, null, createataset1 (), 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.SETREGULARFONT (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- 축 Numberaxis numberaxis = (numberaxis) xyplot.getRangeAxis (); numberaxis.setLowerBound (0); NumberAxis.SetUpperBound (100); numberaxis.setTickUnit (새로운 번호 TickUnit (100d)); // 정수 값 만 숫자로 표시됩니다. // numberaxis.setautorangeincludeszero (true); numberaxis.setLowerMargin (0); // 데이터 축 아래 (왼쪽) margin numberaxis.setminortickmarksvisible (false); // 마킹 라인이 숫자를 표시하는지 여부는 numberaxis.setTickMarkInsIdElength (0); // 외부 진드기의 안쪽 길이 마크 numb // x-axis numberaxis의 설계 x = (numberaxis) xyplot.getDomainaxis (); x.setAutorange (true); // 데이터 축의 데이터 범위를 자동으로 설정 // 직접 수평 좌표 값을 설정 X.SetAutoTickUnitSelection (false); X.SetTickUnit (새 번호 TickUnit (60d)); // 최대 표시 값과 최소 디스플레이 값 X.SetLowerBound (0)를 설정합니다. X.SetUpperBound (60); // 데이터 축의 데이터 레이블 : 만 디스플레이 정수 레이블 x.setstandardTickUnits (numberaxis.createInteGertickUnits ()); x.setaxislinevisible (true); // x 축 세르시 라인이 x.settickmarksvisible (false)을 표시하는지 여부; // 마킹 라인이 RectingleInsets를 표시하는지 여부는 오프셋 = 새로운 사각형 사제 (0, 0, 0, 0); xyplot.setaxisOffset (Offset); // 축과 데이터 영역 사이의 간격 xyplot.setbackgroundalpha (0.0f); // 막대 차트의 배경색 제거 xyplot.setoutlinePaint (null); // torder // ChartPanel ChartPanel = new ChartPanel (jfreechart); // chartPanel.RestoreautodomainBounds (); // x 축소를 재설정합니다. 차트 패널 차트 패널 = 새로운 차트 패널 (jfreechart, true); Return ChartPanel; } / ** *이 메소드는 데이터 설계 * * @return * / public static xydataset createAtaset1 () {xyseriesCollection xyseriesCollection = 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)); // 제목 글꼴 XYCPUSERIES.ADD (I, FACTOR)를 설정합니다. try {ordle.currentthread (); Thread.sleep (1000); } catch (InterruptedException 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); // 창은 화면 프레임의 중앙에 있습니다. DynamicRun (); }}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.