我想实现一个持续实时数据的趋势图,其中x轴的时间格式为“HH:MM:SS”。现在我的要求是可调节尺度,如10分钟或15分钟等......还有我如何限制x轴上的时间值?
请帮帮我。 谢谢!
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.SeriesException;
import org.jfree.data.time.Second;
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;
public class TimeSeries_AWT extends ApplicationFrame
{
public TimeSeries_AWT( final String title )
{
super( title );
final XYDataset dataset = createDataset( );
final JFreeChart chart = createChart( dataset );
final ChartPanel chartPanel = new ChartPanel( chart );
chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 370 ) );
chartPanel.setMouseZoomable( true , false );
setContentPane( chartPanel );
}
private XYDataset createDataset( )
{
final TimeSeries series = new TimeSeries( "Random Data" );
Second current = new Second( );
double value = 100.0;
for (int i = 0; i < 4000; i++)
{
try
{
value = value + Math.random( ) - 0.5;
series.add(current, new Double( value ) );
current = ( Second ) current.next( );
}
catch(SeriesException e )
{
System.err.println("Error adding to series");
}
}
return new TimeSeriesCollection(series);
}
private JFreeChart createChart( final XYDataset dataset )
{
return ChartFactory.createTimeSeriesChart(
"Computing Test",
"Seconds",
"Value",
dataset,
false,
false,
false);
}
public static void main( final String[ ] args )
{
final String title = "Time Series Management";
final TimeSeries_AWT demo = new TimeSeries_AWT( title );
demo.pack( );
RefineryUtilities.positionFrameRandomly( demo );
demo.setVisible( true );
}
}
如果你看到输出,那么时间是不变的,只是静态而不是动态变化。如果时间动态更新,我希望在运行时动态调整比例或tickunits,例如在输出图中,比例时间为5分钟。但是我希望在运行时将其控制为10分钟,20分钟,40分钟等......
另一件事是在输出图中我们可以在x轴上看到14个值。当图表调整大小时,它会自动改变。但我想控制在x轴上看到的数量意味着我想要显示x轴上的某些特定x时间值。在启动应用程序时也应该可配置。