Scaling and scrolling issues

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

Auto-fit curve in Y direction while scrolling

Post by Fujiko » Tue Dec 07, 2004 10:42 pm

You can try to put this little algoritm in the stateChanged methods:

ValueAxis yAxis = hvp.getRangeAxis();
ValueAxis xAxis = hvp.getDomainAxis();
final Range xAxisRange = xAxis.getRange();

XYDataset dnb =hvp.getDataset();// get dataset
int nb2 =dnb.getItemCount(0); // get points number

Number [] vx = new Number[arbitrary dim];//should be
Number [] vy = new Number[arbitrary dim];//higher than pt number

for (int i=0; i<nb2; i++) { // recover pairs of the plot
vx=dnb.getXValue(0,i);
vy=dnb.getYValue(0,i);

int iflagk=0;// index of upper bound TBD
int iflagkk=0;//index of lower bound TBD

for(int i=0; i <nb2-1; i++) {

if(vx.doubleValue()<xAxisRange.getLowerBound() && vx[i+1].doubleValue()>xAxisRange.getLowerBound()){
iflagk=i;

}
if(vx.doubleValue()<xAxisRange.getUpperBound() && vx[i+1].doubleValue()>xAxisRange.getUpperBound()){
iflagkk=i;
}
}
//Search of the maximum on Y direction
double vmax=Math.max(vy[iflagk].doubleValue(),vy[iflagk+1].doubleValue());
for (int i=iflagk; i<iflagkk+1; i++) {
vmax=Math.max(vmax,vy.doubleValue());

}
//Search of the minimum on Y
double vmin=Math.min(vy[iflagk].doubleValue(),vy[iflagk+1].doubleValue());
for (int i=iflagk; i<iflagkk+1; i++) {
vmin=Math.min(vmin,vy.doubleValue());

}
yAxis.setLowerBound(vmin);// set the bounds
yAxis.setUpperBound(vmax);

Please tell me if it works for you

Regards

Locked