- y = (int) (yScaleFactor * (value - minValue));
- g.fillRect(BORDER_WIDTH+x, height-BORDER_WIDTH - y, barWidth, y);
+ // Normal case is the minimum value greater than zero
+ if (minValue >= 0)
+ {
+ y = (int) (yScaleFactor * (value - minValue));
+ g.fillRect(BORDER_WIDTH+x, height-BORDER_WIDTH - y, barWidth, y);
+ }
+ else if (value >= 0.0) {
+ // Bar upwards from the zero line
+ y = height-BORDER_WIDTH - (int) (yScaleFactor * (value - minValue));
+ g.fillRect(BORDER_WIDTH+x, y, barWidth, zeroY - y);
+ }
+ else {
+ // Bar downwards from the zero line
+ int barHeight = (int) (yScaleFactor * value);
+ g.fillRect(BORDER_WIDTH+x, zeroY, barWidth, -barHeight);
+ }