简体   繁体   English

当数据连续到达时如何使用jfreechart绘制图形

[英]How to plot a graph using jfreechart when data is coming continously

I want to plot a line graph wherein data comes dynamically. 我想绘制一个折线图,其中数据是动态产生的。 Lets say for every second i have a new set of values that are to be plotted within the existing graph containing previous values. 可以说,我每秒都有一组新值,这些值将在包含先前值的现有图形中绘制。 Time series graph offers such mechanism, but it need to have time as one of the parameter. 时间序列图提供了这样的机制,但是它需要有时间作为参数之一。 But, time is not a variable for my case. 但是,时间对我来说不是可变的。 How to keep updating this line graph with continuous incoming data. 如何使用连续的传入数据不断更新此线图。

You could 你可以

  1. Pass an incremented value for each new data point. 为每个新数据点传递一个递增的值。 Alternatively you could take a look at source code of DynamicTimeSeriesCollection to see how they make it dynamic. 或者,您可以查看DynamicTimeSeriesCollection的源代码,以了解它们如何使其动态化。 Which leads to: 这导致:

  2. It seems that if you create your own data type that extends org.jfree.data.general.Series class then on any change you'd be able to call fireSeriesChanged which will trigger update of the graph. 看来,如果您创建扩展org.jfree.data.general.Series类的数据类型,则fireSeriesChanged任何更改时,您都可以调用fireSeriesChanged来触发图的更新。

  3. As I read library I see more options. 当我阅读图书馆时,我看到了更多选择。 Did you try XYSeries , it has method called add(), I checked the source it call to this method triggers notification of change listeners. 您是否尝试过XYSeries ,它有一个名为add()的方法,我检查了它调用此方法的源会触发更改侦听器的通知。 So using this class should be enough for your case. 因此,使用此类足以满足您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM