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
Plotting a Straight Line
RE: Plotting a Straight Line
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.
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.
RE: Plotting a Straight Line
Hi Erin,
Thanks for the tip...works great:):)
Cheers,
Mark
Thanks for the tip...works great:):)
Cheers,
Mark