求动态曲线图解决思路 曲线图一秒读取一次数据并曲线随时间移动。就像任务管理器的CPU使用记录的曲线图一样的移动我想用定时器,但不知道如何解决问题。。请高手多多指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 从服务器读出数据后在表格中绘制点(或者线),表格自己定义坐标就行了,x和y,比如任务管理器里的CPU 使用,在1 :00这个时刻是50%,就绘制一个(0,50)的点就行了,一般都是在指定时间间隔内描绘一条线,你仔细看看任务管理器中的cpu使用记录就会发现,曲线都是一条条的线组成的。 给你粘个JFreeChart的例子,你看看import java.awt.*;import java.awt.event.*;import javax.swing.*;import org.jfree.chart.ChartPanel;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.DateAxis;import org.jfree.chart.axis.NumberAxis;import org.jfree.chart.plot.XYPlot;import org.jfree.chart.renderer.xy.XYItemRenderer;import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;import org.jfree.data.time.*;import org.jfree.ui.RectangleInsets;public class MemoryUsageDemo extends JPanel{ class DataGenerator extends Timer implements ActionListener { public void actionPerformed(ActionEvent actionevent) { long l = Runtime.getRuntime().freeMemory(); long l1 = Runtime.getRuntime().totalMemory(); addTotalObservation(l1); addFreeObservation(l); } DataGenerator(int i) { super(i, null); addActionListener(this); } } public MemoryUsageDemo(int i) { super(new BorderLayout()); total = new TimeSeries("Total Memory", org.jfree.data.time.Millisecond.class); total.setMaximumItemAge(i); free = new TimeSeries("Free Memory", org.jfree.data.time.Millisecond.class); free.setMaximumItemAge(i); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(total); timeseriescollection.addSeries(free); DateAxis dateaxis = new DateAxis("Time"); NumberAxis numberaxis = new NumberAxis("Memory"); dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateaxis.setLabelFont(new Font("SansSerif", 0, 14)); numberaxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesPaint(1, Color.green); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2)); xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2)); XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); dateaxis.setAutoRange(true); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); dateaxis.setTickLabelsVisible(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true); jfreechart.setBackgroundPaint(Color.white); ChartPanel chartpanel = new ChartPanel(jfreechart, true); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartpanel); } private void addTotalObservation(double d) { total.add(new Millisecond(), d); } private void addFreeObservation(double d) { free.add(new Millisecond(), d); } public static void main(String args[]) { JFrame jframe = new JFrame("Memory Usage Demo"); MemoryUsageDemo memoryusagedemo = new MemoryUsageDemo(30000); jframe.getContentPane().add(memoryusagedemo, "Center"); jframe.setBounds(200, 120, 600, 280); jframe.setVisible(true); (memoryusagedemo. new DataGenerator(100)).start(); jframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowevent) { System.exit(0); } }); } private TimeSeries total; private TimeSeries free;} 是Java C/S 的 曲线我已经绘制出来了,我主要是想问的曲线的动态流动问题 为什么编写的计算器不能运算? 有什么办法纠正直线端点的偏移 返回汉字的第一个字母 res.sendRedirect("/error.jsp");空指针异常 about XML 关于正则表达的几个简单问题。 既然抛弃了指针,那为什么还要让==去比较指针的逻辑概念引用? 既想当婊子,还想立牌坊! 请问java中的那个类库是用于把查询结果输出到打印机? 请教各位大侠:关于this的问题? IE自带的JVM支持什么版本的java? BIRT task 不能运行 JAVA正则取值的问题
import java.awt.event.*;
import javax.swing.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.*;
import org.jfree.ui.RectangleInsets;public class MemoryUsageDemo extends JPanel
{
class DataGenerator extends Timer
implements ActionListener
{ public void actionPerformed(ActionEvent actionevent)
{
long l = Runtime.getRuntime().freeMemory();
long l1 = Runtime.getRuntime().totalMemory();
addTotalObservation(l1);
addFreeObservation(l);
} DataGenerator(int i)
{
super(i, null);
addActionListener(this);
}
}
public MemoryUsageDemo(int i)
{
super(new BorderLayout());
total = new TimeSeries("Total Memory", org.jfree.data.time.Millisecond.class);
total.setMaximumItemAge(i);
free = new TimeSeries("Free Memory", org.jfree.data.time.Millisecond.class);
free.setMaximumItemAge(i);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
timeseriescollection.addSeries(total);
timeseriescollection.addSeries(free);
DateAxis dateaxis = new DateAxis("Time");
NumberAxis numberaxis = new NumberAxis("Memory");
dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
xylineandshaperenderer.setSeriesPaint(0, Color.red);
xylineandshaperenderer.setSeriesPaint(1, Color.green);
xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2));
xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2));
XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
dateaxis.setAutoRange(true);
dateaxis.setLowerMargin(0.0D);
dateaxis.setUpperMargin(0.0D);
dateaxis.setTickLabelsVisible(true);
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true);
jfreechart.setBackgroundPaint(Color.white);
ChartPanel chartpanel = new ChartPanel(jfreechart, true);
chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black)));
add(chartpanel);
} private void addTotalObservation(double d)
{
total.add(new Millisecond(), d);
} private void addFreeObservation(double d)
{
free.add(new Millisecond(), d);
} public static void main(String args[])
{
JFrame jframe = new JFrame("Memory Usage Demo");
MemoryUsageDemo memoryusagedemo = new MemoryUsageDemo(30000);
jframe.getContentPane().add(memoryusagedemo, "Center");
jframe.setBounds(200, 120, 600, 280);
jframe.setVisible(true);
(memoryusagedemo. new DataGenerator(100)).start();
jframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowevent)
{
System.exit(0);
} }
);
} private TimeSeries total;
private TimeSeries free;
}