using null in a step plot doesnt seem to work

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mike

using null in a step plot doesnt seem to work

Post by Mike » Sat Jul 20, 2002 7:06 pm

I have been ploting a temperature sensor's readings against the time of the reading.

Unfortunatly the sensor is not perfect and sometimes returns an error reading, stored in a database as -3000000.

I obviously do not want this displayed on the graph as it will mess with the scale of the y-axis, and wont mean much. I tried to return a y value of null in this case but this just means the graph is not displayed.
Is there a way I can leave a break in the line at that point?

Thanks
Mike

David Gilbert

Re: using null in a step plot doesnt seem to work

Post by David Gilbert » Mon Jul 22, 2002 12:17 pm

It is intended that all chart types should handle null range values (to represent missing data). However, the XYStepRenderer class doesn't check for these at present. Here is a modified drawItem method for the XYStepRenderer class that should handle nulls:

public void drawItem(Graphics2D g2, Rectangle2D dataArea, ChartRenderingInfo info,
XYPlot plot, ValueAxis horizontalAxis, ValueAxis verticalAxis,
XYDataset data, int series, int item,
CrosshairInfo crosshairInfo) {

Paint seriesPaint = plot.getSeriesPaint(series);
Stroke seriesStroke = plot.getSeriesStroke(series);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);

// get the data point...
Number x1 = data.getXValue(series, item);
Number y1 = data.getYValue(series, item);
if (y1==null) return;

double transX1 = horizontalAxis.translateValueToJava2D(x1.doubleValue(), dataArea);
double transY1 = verticalAxis.translateValueToJava2D(y1.doubleValue(), dataArea);

if (item>0) {
// get the previous data point...
Number x0 = data.getXValue(series, item-1);
Number y0 = data.getYValue(series, item-1);
if (y0!=null) {
double transX0 = horizontalAxis.translateValueToJava2D(x0.doubleValue(), dataArea);
double transY0 = verticalAxis.translateValueToJava2D(y0.doubleValue(), dataArea);

if (transY0 == transY1) { //this represents the situation for drawing a
//horizontal bar.
line.setLine(transX0, transY0, transX1, transY1);
g2.draw(line);
}
else { //this handles the need to perform a 'step'.
line.setLine(transX0, transY0, transX1, transY0);
g2.draw(line);
line.setLine(transX1, transY0, transX1, transY1);
g2.draw(line);
}

}
}

// do we need to update the crosshair values?
if (horizontalAxis.isCrosshairLockedOnData()) {
if (verticalAxis.isCrosshairLockedOnData()) {
// both axes
crosshairInfo.updateCrosshairPoint(x1.doubleValue(), y1.doubleValue());
}
else {
// just the horizontal axis...
crosshairInfo.updateCrosshairX(x1.doubleValue());

}
}
else {
if (verticalAxis.isCrosshairLockedOnData()) {
// just the vertical axis...
crosshairInfo.updateCrosshairY(y1.doubleValue());
}
}

}

Regards,

DG.

Locked