Plotting a Straight Line

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Mark Rosche

Plotting a Straight Line

Post by Mark Rosche » Thu Sep 14, 2000 10:26 am

How do I plot a straight line...my application extracts data from a database and plots the data to a chart on the fly; if the data extracted from the db is constant (i.e. 10 AM - $10, 11 AM - $10, 12 PM - $10) I do not see the data plotted. Any help on the subject would be helpful...

Cheers,
Mark Rosche

Erin

RE: Plotting a Straight Line

Post by Erin » Thu Sep 14, 2000 1:44 pm

This happens because of "divide by zero" in case of axisMin = axisMax.

public double translatedValue(Number dataValue, Rectangle2D plotArea) {
double value = dataValue.doubleValue();
double axisMin = minimumAxisValue.doubleValue();
double axisMax = maximumAxisValue.doubleValue();
double maxY = plotArea.getMaxY();
double minY = plotArea.getMinY();
--> return maxY - (((value - axisMin)/(axisMax - axisMin)) * (maxY - minY));
}

You can add the following codes (-->) to expand the range a little bit. (I suppose you turn the autoRange on)

public void autoAdjustRange() {

if (plot!=null) {
if (plot instanceof VerticalValuePlot) {
VerticalValuePlot vvp = (VerticalValuePlot)plot;
double upper = vvp.getMaximumVerticalDataValue().doubleValue();
double lower = vvp.getMinimumVerticalDataValue().doubleValue();
--> if (upper == lower) {
--> upper = upper * 1.1;
--> lower = lower * 0.9;
--> }
double range = upper-lower;
if (upper!=0.0) upper = upper+0.05*range;
if (lower!=0.0) lower = lower-0.05*range;
this.minimumAxisValue=new Double(lower);
this.maximumAxisValue=new Double(upper);
}
}

}

Hope this helps.

Mark Rosche

RE: Plotting a Straight Line

Post by Mark Rosche » Mon Sep 18, 2000 1:06 pm

Hi Erin,

Thanks for the tip...works great:):)

Cheers,
Mark

Post Reply