有关于jfreechart的疑问 在动态的折线图里面的时间轴显示是系统的时间.现在我想把他改成从00:00:00开始的时间,应该怎么做?使用setMinimumDate?好像设置完之后动态图就不走了.还请您指明一下,先谢了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【tangwei168】截止到2008-07-15 14:51:30的历史汇总数据(不包括此帖):发帖的总数量:5 发帖的总分数:420 每贴平均分数:84 回帖的总数量:188 得分贴总数量:54 回帖的得分率:28% 结贴的总数量:3 结贴的总分数:300 无满意结贴数:0 无满意结贴分:0 未结的帖子数:2 未结的总分数:120 结贴的百分比:60.00 % 结分的百分比:71.43 % 无满意结贴率:0.00 % 无满意结分率:0.00 % 楼主加油 new date()显示的还不是系统时间?我是想让时间从00:00:00开始,而不是系统时间. Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY,0); cal.set(Calendar.MINUTE,0); cal.set(Calendar.SECOND,0); System.out.println(new SimpleDateFormat("HH:mm:ss").format(cal.getTime())); 晕...楼上的朋友是没有看仔细我的问题吗?这个我知道的啊.你把这个对象用上去试试?((DateAxis) valueaxis).setMinimumDate(canlendar.getTime());然后再total.addOrUpdate(s, d);第一,根本那个TimeSeries不会走.第二,如果直接用((DateAxis) valueaxis).setMinimumDate(new Date());数据在开始会显示,但走到后面也不会走.再说x轴格式还是以系统时间.有没有根本解决问题的办法啊!!!!!!!!!!!!!!!!!!!!!!!! 给你贴段代码,看是不是你要的。每隔一分钟x轴会左移一格。不知道你说的时间从00:00:00开始是什么目的?import java.awt.*;import java.awt.event.*;import java.text.*;import java.util.*;import javax.swing.*;import org.jfree.chart.*;import org.jfree.chart.axis.*;import org.jfree.chart.plot.*;import org.jfree.data.time.*;import org.jfree.data.xy.*;import org.jfree.ui.*;public class DynamicChart extends ApplicationFrame { private static final long serialVersionUID = -1L; private TimeSeries datas; JFreeChart jfreechart; public DynamicChart(String s) { super(s); XYDataset xydataset = createDataset(); jfreechart = createChart(xydataset); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartpanel); new DataGenerator(1000).start(); } private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Dynamic Chart Example", "Time", "Value", xydataset, false, true, false); XYPlot plot = (XYPlot) jfreechart.getPlot(); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoTickUnitSelection(false); yAxis.setPositiveArrowVisible(true); // 设置y轴的单位,最大值和最小值 NumberTickUnit ntu = new NumberTickUnit(50); yAxis.setTickUnit(ntu); yAxis.setLowerBound(0D); yAxis.setUpperBound(500); // 设置x轴的时间显示格式,显示范围,时间间隔,最大值和最小值 DateAxis xAxis = (DateAxis) plot.getDomainAxis(); DateFormat df = new SimpleDateFormat("HH:mm");// 显示格式 long t = new Date().getTime()/1000L/60L;//分钟 Date start = new Date(t*60000L); t += 5; Date end = new Date(t*60000L); xAxis.setRange(start, end);// 显示范围:start - end xAxis.setAutoTickUnitSelection(false); xAxis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 60));// 单位:60秒 xAxis.setPositiveArrowVisible(true); xAxis.setDateFormatOverride(df); return jfreechart; } private XYDataset createDataset() { this.datas = new TimeSeries("Per Minute Data", Second.class); TimeSeriesCollection collection = new TimeSeriesCollection(this.datas); return collection; } public JPanel createDemoPanel() { JFreeChart jfreechart = createChart(createDataset()); return new ChartPanel(jfreechart); } private void addDataObservation(double y) { Second s = new Second(); try { this.datas.add(s, y); } catch ( Exception e) { this.datas.update(s, y); } } private void setXAxixRange(){ XYPlot plot = (XYPlot) jfreechart.getPlot(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); long t = new Date().getTime()/1000L/60L - 3; Date start = new Date(t*60000L); t += 5; Date end = new Date(t*60000L); xAxis.setRange(start, end); } class DataGenerator extends javax.swing.Timer implements ActionListener { private static final long serialVersionUID = 1L; int count = 0; DataGenerator(int interval) { super(interval, null); addActionListener(this); } public void actionPerformed(ActionEvent event) { long d = new Random().nextInt(500) + 1; addDataObservation(d); if(count > 60) { setXAxixRange(); count = 0; } count++; } } public static void main(String args[]) { DynamicChart dynamicChart = new DynamicChart("Dynamic Chart Example"); dynamicChart.pack(); RefineryUtilities.centerFrameOnScreen(dynamicChart); dynamicChart.setVisible(true); }} 请教一个dos下补全快捷键 请各位好心的JAVA高手进来下. null异常? POI, 操作[.xls]文件, 怎么在指定位置,插入一个新行 sun java 上doc文档下载在哪 如何取小数点前两位,并四舍五入 像线程问题的问题,都来看看! 当单击关闭(X)右上角的,需要在方法里,执行数据库的关闭,应怎样实现啊 导出的excel文件如何设置复杂表头 关于Map替换得思路 請問Table從數據庫當中獲取資料出來之後,如何能點選某一列讓該列的資訊傳回到表頭顯示? java table的问题?为什么table的mouseclicked事件只能反应一次就没有反应了?
楼主【tangwei168】截止到2008-07-15 14:51:30的历史汇总数据(不包括此帖):
发帖的总数量:5 发帖的总分数:420 每贴平均分数:84
回帖的总数量:188 得分贴总数量:54 回帖的得分率:28%
结贴的总数量:3 结贴的总分数:300
无满意结贴数:0 无满意结贴分:0
未结的帖子数:2 未结的总分数:120
结贴的百分比:60.00 % 结分的百分比:71.43 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.SECOND,0);
System.out.println(new SimpleDateFormat("HH:mm:ss").format(cal.getTime()));
第二,如果直接用((DateAxis) valueaxis).setMinimumDate(new Date());
数据在开始会显示,但走到后面也不会走.再说x轴格式还是以系统时间.有没有根本解决问题的办法啊!!!!!!!!!!!!!!!!!!!!!!!!
每隔一分钟x轴会左移一格。
不知道你说的时间从00:00:00开始是什么目的?
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.swing.*;import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.data.time.*;
import org.jfree.data.xy.*;
import org.jfree.ui.*;public class DynamicChart extends ApplicationFrame { private static final long serialVersionUID = -1L;
private TimeSeries datas;
JFreeChart jfreechart; public DynamicChart(String s) {
super(s);
XYDataset xydataset = createDataset();
jfreechart = createChart(xydataset); ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
new DataGenerator(1000).start();
} private static JFreeChart createChart(XYDataset xydataset) {
JFreeChart jfreechart =
ChartFactory.createTimeSeriesChart("Dynamic Chart Example", "Time",
"Value", xydataset, false, true,
false);
XYPlot plot = (XYPlot) jfreechart.getPlot();
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setAutoTickUnitSelection(false);
yAxis.setPositiveArrowVisible(true);
// 设置y轴的单位,最大值和最小值
NumberTickUnit ntu = new NumberTickUnit(50);
yAxis.setTickUnit(ntu);
yAxis.setLowerBound(0D);
yAxis.setUpperBound(500);
// 设置x轴的时间显示格式,显示范围,时间间隔,最大值和最小值
DateAxis xAxis = (DateAxis) plot.getDomainAxis();
DateFormat df = new SimpleDateFormat("HH:mm");// 显示格式
long t = new Date().getTime()/1000L/60L;//分钟
Date start = new Date(t*60000L);
t += 5;
Date end = new Date(t*60000L);
xAxis.setRange(start, end);// 显示范围:start - end
xAxis.setAutoTickUnitSelection(false);
xAxis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 60));// 单位:60秒
xAxis.setPositiveArrowVisible(true);
xAxis.setDateFormatOverride(df);
return jfreechart;
} private XYDataset createDataset() {
this.datas = new TimeSeries("Per Minute Data", Second.class);
TimeSeriesCollection collection = new TimeSeriesCollection(this.datas);
return collection;
} public JPanel createDemoPanel() {
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
} private void addDataObservation(double y) {
Second s = new Second();
try {
this.datas.add(s, y);
} catch ( Exception e) {
this.datas.update(s, y);
}
} private void setXAxixRange(){
XYPlot plot = (XYPlot) jfreechart.getPlot();
DateAxis xAxis = (DateAxis) plot.getDomainAxis();
long t = new Date().getTime()/1000L/60L - 3;
Date start = new Date(t*60000L);
t += 5;
Date end = new Date(t*60000L);
xAxis.setRange(start, end);
}
class DataGenerator extends javax.swing.Timer implements ActionListener { private static final long serialVersionUID = 1L;
int count = 0;
DataGenerator(int interval) {
super(interval, null);
addActionListener(this);
} public void actionPerformed(ActionEvent event) {
long d = new Random().nextInt(500) + 1;
addDataObservation(d);
if(count > 60) {
setXAxixRange();
count = 0;
}
count++;
}
} public static void main(String args[]) {
DynamicChart dynamicChart = new DynamicChart("Dynamic Chart Example");
dynamicChart.pack();
RefineryUtilities.centerFrameOnScreen(dynamicChart);
dynamicChart.setVisible(true);
}
}