0

I need to zoom out from rangeAxis in jFreeChart, so I've used zoomRange for this purpose.

But I didn't understand what is lowerPercent and upperPercent?

I want to set the rangeAxis as shown below in the image. How can i do that?

I've tried this but don't know what should be the value of rangeAxis.zoomRange(0,?)

public class Profilee  {



    double last=0;
    ChartFrame frame1;

    JFreeChart chart;
    ChartUtilities cu=new ChartUtilitiesImpl();

    public void generateProfile(double[] pointValue,double[] distance){
        ArrayList pv=new ArrayList();
        ArrayList dist=new ArrayList();

        pv.add(pointValue);
        dist.add(distance);

        XYSeries series = new XYSeries("");
        for(int i=0;i<pointValue.length-1;i++){

              series.add(last,pointValue[i]);
              last=distance[i];
         }



      XYDataset xyDataset = new XYSeriesCollection(series);
      chart= ChartFactory.createXYAreaChart("Profile View Of Contour", "Distance", "Contour Value", xyDataset, PlotOrientation.VERTICAL, true, true, false);

      ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();

      //rangeAxis.setLowerBound(-3);
      rangeAxis.zoomRange(0,?);     //What should be Value over here?
      frame1=new ChartFrame("XYLine Chart",chart);

      frame1.setVisible(true);
      frame1.setSize(1300,700);
    }


    public static void main(String ar[]){
        Profilee pro=new Profilee();
        double[] pv={3,2,3,0,5,-2,10};
        double[] dist={1,4,8,12,14,20,24};
        pro.generateProfile(pv, dist);



    }

    private static class ChartUtilitiesImpl extends ChartUtilities {

        public ChartUtilitiesImpl() {
        }
    }
}

enter image description here

Parth Soni
  • 11,158
  • 4
  • 32
  • 54

1 Answers1

2

By default, ValueAxis automatically adjusts its range to accommodate the dataset. You can adopt an explicit range, such as shown in the image above, using one of the setRange() methods.

rangeAxis.setRange(-8, 12);
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • can i set/get the distance of between two numbers of `rangeAxis`? For ex. rangeAxis ranges from -4 to 4, so can i get the distance between any two numbers on `rangeAxis` suppose 2 and 3? – Parth Soni Apr 22 '12 at 03:02
  • Honestly, I try to avoid it; as suggested [here](http://stackoverflow.com/a/10156483/230513), a `ChartMouseListener` often obviates the need for model/view coordinate transformation. – trashgod Apr 22 '12 at 09:14
  • can't i find it directly without `ChartMouseListener`? – Parth Soni Apr 22 '12 at 10:33
  • Yes, but only by inverting the coordinate transformation. The real question is this: Why do you need to know? – trashgod Apr 22 '12 at 10:56
  • Then use `setRange(2, 3)` to make 2 near the bottom and 3 near the top. The chart will scale to fill the container. – trashgod Apr 22 '12 at 20:44
  • suppose the distance between 0 and 4 in the image shown above is 16 pixel then i want to set this as distance in between number's in my graph, that means numbers 0 to 4 in my graph should also have the distance of 16 pixel, and it should not be changed until i resize the image. This is what i want to do.. – Parth Soni Apr 23 '12 at 04:23
  • Do you mean you want to adjust the size of the enclosing container to make the axis 11 ticks * 16 pixels/tick tall? Why? – trashgod Apr 23 '12 at 07:10