欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JFreeChart動態(tài)畫折線圖的方法

 更新時間:2018年06月19日 11:19:03   作者:聆聽夢飛揚  
這篇文章主要為大家詳細介紹了JFreeChart動態(tài)畫折線圖的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了JFreeChart動態(tài)畫折線圖的具體代碼,供大家參考,具體內(nèi)容如下

每隔一秒畫一次,一分鐘后重新畫

需要的jar包是:gnujaxp.jar,jcommon-1.0.16.jar,jfreechart-1.0.13.jar

public class JFreeZheXianTest{

 public static XYSeries xyCPUseries = new XYSeries("CPU");

 public static int hundroud = 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("黑體", Font.BOLD, 20));
 mChartTheme.setExtraLargeFont(new Font("宋體", Font.PLAIN, 15));
 mChartTheme.setRegularFont(new Font("宋體", 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(new NumberTickUnit(100d));
 // 只顯示整數(shù)值
 numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 // numberaxis.setAutoRangeIncludesZero(true);
 numberaxis.setLowerMargin(0); // 數(shù)據(jù)軸下(左)邊距 ­
 numberaxis.setMinorTickMarksVisible(false);// 標記線是否顯示
 numberaxis.setTickMarkInsideLength(0);// 外刻度線向內(nèi)長度
 numberaxis.setTickMarkOutsideLength(0);

 // X軸的設(shè)計
 NumberAxis x = (NumberAxis) xyplot.getDomainAxis();
 x.setAutoRange(true);// 自動設(shè)置數(shù)據(jù)軸數(shù)據(jù)范圍
 // 自己設(shè)置橫坐標的值
 x.setAutoTickUnitSelection(false);
 x.setTickUnit(new NumberTickUnit(60d));
 // 設(shè)置最大的顯示值和最小的顯示值
 x.setLowerBound(0);
 x.setUpperBound(60);
 // 數(shù)據(jù)軸的數(shù)據(jù)標簽:只顯示整數(shù)標簽
 x.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 x.setAxisLineVisible(true);// X軸豎線是否顯示
 x.setTickMarksVisible(false);// 標記線是否顯示

 RectangleInsets offset = new RectangleInsets(0, 0, 0, 0);
 xyplot.setAxisOffset(offset);// 坐標軸到數(shù)據(jù)區(qū)的間距
 xyplot.setBackgroundAlpha(0.0f);// 去掉柱狀圖的背景色
 xyplot.setOutlinePaint(null);// 去掉邊框

 // ChartPanel chartPanel = new ChartPanel(jfreechart);
 // chartPanel.restoreAutoDomainBounds();//重置X軸

 ChartPanel chartPanel = new ChartPanel(jfreechart, true);

 return chartPanel;
 }

 /**
 * 該方法是數(shù)據(jù)的設(shè)計
 * 
 * @return
 */
 public static XYDataset createDataset1() {
 XYSeriesCollection xyseriescollection = new XYSeriesCollection();
 xyseriescollection.addSeries(xyCPUseries);
 return xyseriescollection;
 }

 /**
 * 隨機生成的數(shù)據(jù)
 */
 public static void dynamicRun() {
 int i = 0;
 while (true) {

  double factor = Math.random()*100;

  hundroud = (int)factor;
  jfreechart.setTitle("CPU的大小是:  "+hundroud+"%");
  jfreechart.getTitle().setFont(new Font("微軟雅黑", 0, 16));//設(shè)置標題字體

  xyCPUseries.add(i, factor);

  try {
  Thread.currentThread();
  Thread.sleep(1000);
  } catch (InterruptedException e) {
  e.printStackTrace();
  }
  i++;
  if (i == 60){
  i=0;
  xyCPUseries.delete(0, 59);
  continue;
  }
 }
 }

 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();
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Mybatis 入門之MyBatis環(huán)境搭建(第一篇)

    Mybatis 入門之MyBatis環(huán)境搭建(第一篇)

    Mybatis的前身叫iBatis,本是apache的一個開源項目, 2010年這個項目由apache software foundation 遷移到了google code,并且改名為MyBatis。這篇文章主要介紹了Mybatis入門第一篇之MyBaits環(huán)境搭建,需要的朋友參考下
    2016-12-12
  • Java實現(xiàn)獲取某年某月第一天/最后一天的方法

    Java實現(xiàn)獲取某年某月第一天/最后一天的方法

    這篇文章主要介紹了Java實現(xiàn)獲取某年某月第一天/最后一天的方法,涉及java日期運算相關(guān)操作技巧,需要的朋友可以參考下
    2018-02-02
  • java中的AWT事件處理問題

    java中的AWT事件處理問題

    這篇文章主要介紹了java中的AWT事件處理問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • 如何使用SpringBoot進行優(yōu)雅的數(shù)據(jù)驗證

    如何使用SpringBoot進行優(yōu)雅的數(shù)據(jù)驗證

    這篇文章主要介紹了如何使用SpringBoot進行優(yōu)雅的數(shù)據(jù)驗證,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11
  • Springboot關(guān)于自定義stater的yml無法提示問題解決方案

    Springboot關(guān)于自定義stater的yml無法提示問題解決方案

    這篇文章主要介紹了Springboot關(guān)于自定義stater的yml無法提示問題及解決方案,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • 使用Springboot整合Apollo配置中心

    使用Springboot整合Apollo配置中心

    這篇文章主要介紹了使用Springboot整合Apollo配置中心的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 深入理解java動態(tài)代理機制

    深入理解java動態(tài)代理機制

    本篇文章主要介紹了深入理解java動態(tài)代理機制,詳細的介紹動態(tài)代理有哪些應(yīng)用場景,什么是動態(tài)代理,怎樣使用,它的局限性在什么地方?有興趣的可以了解一下。
    2017-02-02
  • JAVA?POI設(shè)置EXCEL單元格格式用法舉例

    JAVA?POI設(shè)置EXCEL單元格格式用法舉例

    這篇文章主要給大家介紹了關(guān)于JAVA?POI設(shè)置EXCEL單元格格式用法的相關(guān)資料,POI中可能會用到一些需要設(shè)置EXCEL單元格格式的操作,需要的朋友可以參考下
    2023-08-08
  • JAVA中的函數(shù)式接口Function和BiFunction詳解

    JAVA中的函數(shù)式接口Function和BiFunction詳解

    這篇文章主要介紹了JAVA中的函數(shù)式接口Function和BiFunction詳解,JDK的函數(shù)式接口都加上了@FunctionalInterface注解進行標識,但是無論是否加上該注解只要接口中只有一個抽象方法,都是函數(shù)式接口,需要的朋友可以參考下
    2024-01-01
  • Java縮略圖生成庫之Thumbnailator應(yīng)用說明

    Java縮略圖生成庫之Thumbnailator應(yīng)用說明

    Thumbnailator是一個為Java界面更流暢的縮略圖生成庫,從API提供現(xiàn)有的圖像文件和圖像對象的縮略圖中簡化了縮略過程,兩三行代碼就能夠從現(xiàn)有圖片生成縮略圖,使用起來非常方便,需要的朋友可以了解下
    2012-12-12

最新評論