日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 折线动图_在java中使用jfree图表制作动态折线图

發布時間:2025/4/17 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 折线动图_在java中使用jfree图表制作动态折线图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

是的,你可以做到.幾天前我遇到了類似的問題.

DynamicLineAndTimeSeriesChart.java

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.Timer;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartPanel;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.ValueAxis;

import org.jfree.chart.plot.XYPlot;

import org.jfree.data.time.Millisecond;

import org.jfree.data.time.TimeSeries;

import org.jfree.data.time.TimeSeriesCollection;

import org.jfree.data.xy.XYDataset;

import org.jfree.ui.ApplicationFrame;

import org.jfree.ui.RefineryUtilities;

/**

* An example to show how we can create a dynamic chart.

*/

public class DynamicLineAndTimeSeriesChart extends ApplicationFrame implements ActionListener {

/** The time series data. */

private TimeSeries series;

/** The most recent value added. */

private double lastValue = 100.0;

/** Timer to refresh graph after every 1/4th of a second */

private Timer timer = new Timer(250, this);

/**

* Constructs a new dynamic chart application.

*

* @param title the frame title.

*/

public DynamicLineAndTimeSeriesChart(final String title) {

super(title);

this.series = new TimeSeries("Random Data", Millisecond.class);

final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);

final JFreeChart chart = createChart(dataset);

timer.setInitialDelay(1000);

//Sets background color of chart

chart.setBackgroundPaint(Color.LIGHT_GRAY);

//Created JPanel to show graph on screen

final JPanel content = new JPanel(new BorderLayout());

//Created Chartpanel for chart area

final ChartPanel chartPanel = new ChartPanel(chart);

//Added chartpanel to main panel

content.add(chartPanel);

//Sets the size of whole window (JPanel)

chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));

//Puts the whole content on a Frame

setContentPane(content);

timer.start();

}

/**

* Creates a sample chart.

*

* @param dataset the dataset.

*

* @return A sample chart.

*/

private JFreeChart createChart(final XYDataset dataset) {

final JFreeChart result = ChartFactory.createTimeSeriesChart(

"Dynamic Line And TimeSeries Chart",

"Time",

"Value",

dataset,

true,

true,

false

);

final XYPlot plot = result.getXYPlot();

plot.setBackgroundPaint(new Color(0xffffe0));

plot.setDomainGridlinesVisible(true);

plot.setDomainGridlinePaint(Color.lightGray);

plot.setRangeGridlinesVisible(true);

plot.setRangeGridlinePaint(Color.lightGray);

ValueAxis xaxis = plot.getDomainAxis();

xaxis.setAutoRange(true);

//Domain axis would show data of 60 seconds for a time

xaxis.setFixedAutoRange(60000.0); // 60 seconds

xaxis.setVerticalTickLabels(true);

ValueAxis yaxis = plot.getRangeAxis();

yaxis.setRange(0.0, 300.0);

return result;

}

/**

* Generates an random entry for a particular call made by time for every 1/4th of a second.

*

* @param e the action event.

*/

public void actionPerformed(final ActionEvent e) {

final double factor = 0.9 + 0.2*Math.random();

this.lastValue = this.lastValue * factor;

final Millisecond now = new Millisecond();

this.series.add(new Millisecond(), this.lastValue);

System.out.println("Current Time in Milliseconds = " + now.toString()+", Current Value : "+this.lastValue);

}

/**

* Starting point for the dynamic graph application.

*

* @param args ignored.

*/

public static void main(final String[] args) {

final DynamicLineAndTimeSeriesChart demo = new DynamicLineAndTimeSeriesChart("Dynamic Line And TimeSeries Chart");

demo.pack();

RefineryUtilities.centerFrameOnScreen(demo);

demo.setVisible(true);

}

}

還請點擊這里:

總結

以上是生活随笔為你收集整理的java 折线动图_在java中使用jfree图表制作动态折线图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。