#1044 StandardXYItemRenderer does not draw lines on missing items

General (896)

org.jfree.chart.renderer.xy.StandardXYItemRenderer.drawItem() attempts to draw a line between the current and previous data points. However, it only looks back 1 data point. This fails if there is no Y data for every X value in the dataset. In my case, I am graphing data from separate log files, where the timestamps (x values) may not line up because the logging processes started at different times.

Instead of looking back only 1 item, it should look back until if finds a valid value, if one exists. The following code (line 888 in 1.0.13):
// get the previous data point...
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);

should be changed to:
int n = 1;
double x0 = 0;
double y0 = 0;

// continue until both x0 and y0 are not NaN or there is no previous data
do {
x0 = dataset.getXValue(series, item - n);
y0 = dataset.getYValue(series, item - n);
while ((n <= item) && (Double.isNaN(x0) || Double.isNaN(y0)));

Note that if no valid valid exists, the later NaN check will catch it.

This fix could have performance implications, but they should be minimal for a normal, non-sparse dataset. Even in the sparse case, there will should be data within a few points of the current item. The main issues would be on a very large (thousands of data points?) datasets with very sparse data; I think this may be an uncommon case.


  • David Gilbert
    David Gilbert

    It works this way by design. If there is a null value in the dataset, then there is a missing value, and we break the line connecting points. Note that the XYDataset does not require that every series shares the same set of x-values, so if you don't have data for some points, you don't need to add anything. And then the line will be unbroken.

  • David Gilbert
    David Gilbert

    • status: open --> closed-rejected