chaitu
chaitu

Reputation: 1206

How the xy line chart gets automatically updated/redrawn whenever a new data point is added to the existing dataset in jfreechart

I have a scenario where, the data (both x and y coordinates) comes dynamically. I have to start drawing the graph from the time when i receive the first point. So the graph should be automatically updated every time a new data point comes in.This should continue for a period of time (Note: here both x and y coordinates are double variables and time is not considered as variable at all. We don't know at what time data comes in). I have tried to redraw the total graph after adding a data point to the existing dataset. It worked successfully. But i noticed a flaw in it. I i have a dataset (say at particular time t) in the following order {(1,1)(2,3)(3,5)(4,7)(2.5,1)}. This plot should have a line from point (4,7) to (2.5,1). But the point (2.5,1) is connected from (2,3) and (3,5), which i don't want. So please suggest any way of automatically updating the graph whenever a new data point comes in.

Upvotes: 0

Views: 466

Answers (1)

GrahamA
GrahamA

Reputation: 5923

Assuming that you are using an XYSeries have you tried turning off the sorting

private static XYDataset createDataset() {
  XYSeries dataset = new XYSeries("A",false,true);
  dataset.add(1,1);
  dataset.add(2,3);
  dataset.add(3,5);
  dataset.add(4,7);
  dataset.add(2.5,1);
  XYSeriesCollection ds = new XYSeriesCollection();
  ds.addSeries(dataset);
  return ds;
} 

And you shold be able to create a chart like this:

enter image description here

Upvotes: 1

Related Questions