I have an XYLineChart that gets populated with data which falls into several TimeSeries in its TimeSeriesCollection, as time progresses. When the program receives a new point of data, it adds it to the appropriate TimeSeries (if it exists), or creates a new TimeSeries to put it into, which is then put into the TimeSeriesCollection. After this, the chart is redrawn.
For the most part, this process works just fine. The only hitch is right after the generation of a new TimeSeries - during the time when it only contains one point of data. When the chart is redrawn after having added this single-point TimeSeries, the new point will not appear on the chart. I have a refresh function I use to redraw everything, and the syntax is very similar to the following:
Code: Select all
public void refresh() {
// the JFreeChart "chart", and TimeSeriesCollection "collect" are created and initialized outside this function's scope.
// Also defined are a DateAxis and NumberAxis for the chart, retrievable by calling getDa() and getNa(), respectively.
// Finally, also defined is a till value, retrievable by calling getTill().
scale();
XYLineAndShapeRenderer r = new XYLineAndShapeRenderer();
final int size = collect.getSeriesCount();
for (int i = 0; i < size; i++) {
r.setSeriesLinesVisible(i, false);
r.setSeriesShapesVisible(i, true);
// code to determine which color to make the series. Color is stored in the variable "color"
r.setSeriesPaint(i, color);
r.setSeriesShape(i, new Ellipse2D.Double(0, 0, 5, 5);
}
chart.getPlot().setRenderer(r);
}
private void scale() {
Date maxtime = null;
Date mintime = null;
double l = 0.0;
double u = 0.0;
// I have code here to find the current min and max times, and populate the above values.
final Date minTime = mintime; // minimum time for this plot
final Date maxTime = maxtime; // maximum time for this plot
final double lower = l; //minimum value for this plot
final double upper = u; //upper value for this plot
if (minTime != null && maxTime != null) {
getDa().setRange(minTime.getTime(), maxTime.getTime());
if (lower <= upper) {
getNa().setRange(lower, upper);
}
} else {
if (getDa().isAutoRange()) {
getDa().setFixedAutoRange(getTill());
}
if (lower <= upper) {
getNa().setRange(lower, upper);
getNa().setFixedAutoRange(upper - lower);
}
}
}
So how about it? What can I do to ensure that when I redraw my chart, any TimeSeries that contains only a single point will be shown on the chart? I thought having this line:
Code: Select all
r.setSeriesShapesVisible(i, true);