zoom in another window

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
antonioli
Posts: 12
Joined: Sat Apr 24, 2010 3:28 pm
antibot: No, of course not.

zoom in another window

Post by antonioli » Mon May 03, 2010 11:01 pm

Hi...I'm trying to open a zoomed chart in another window, but i can't get the point of the selection. I just need the x lower and the x upper. How i can get this points?

jsnel
Posts: 19
Joined: Thu Apr 19, 2007 12:00 pm

Re: zoom in another window

Post by jsnel » Tue May 04, 2010 1:58 pm

Maybe you could give us an example of how you are trying to implement this? Just a few lines of code can be helpful to see how far along you are.

Basically, when you zoom, at some point methods like zoomRangeAxis and zoomDomainAxis (don't pin me down on the exact names, I did not look it up) are called with a lower and upper value; two numbers between 0 and 1 indicating the begin and end part of the data range that was selected. This could then easily be converted pixels, if that is what you want, or a data value. Maybe this forum post will help you get started
Creator of Glotaran, a software program developed for global and target analysis of time-resolved spectroscopy and microscopy data. Big fan of JFreeChart.

antonioli
Posts: 12
Joined: Sat Apr 24, 2010 3:28 pm
antibot: No, of course not.

Re: zoom in another window

Post by antonioli » Thu May 06, 2010 5:30 pm

I have this code:

Code: Select all

public void GetZoom(Rectangle2D selection) {

          // get the origin of the zoom selection in the Java2D space used for
          // drawing the chart (that is, before any scaling to fit the panel)
          Point2D selectOrigin = chartPanel.translateScreenToJava2D(new Point(
                  (int) Math.ceil(selection.getX()),
                  (int) Math.ceil(selection.getY())));
          Rectangle2D scaledDataArea = chartPanel.getScreenDataArea(
                  (int) selection.getCenterX(), (int) selection.getCenterY());
          if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

              double hLower = (selection.getMinX() - scaledDataArea.getMinX())
                  / scaledDataArea.getWidth();
              double hUpper = (selection.getMaxX() - scaledDataArea.getMinX())
                  / scaledDataArea.getWidth();
              double vLower = (scaledDataArea.getMaxY() - selection.getMaxY())
                  / scaledDataArea.getHeight();
              double vUpper = (scaledDataArea.getMaxY() - selection.getMinY())
                  / scaledDataArea.getHeight();
ChartRenderingInfo info = chartPanel2.getChartRenderingInfo();
              PlotRenderingInfo plotInfo = info.getPlotInfo();
              Plot p = chartF2.getPlot();
              if (p instanceof Zoomable) {
                  Zoomable z = (Zoomable) p;
                  if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                      z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
                      z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
                  }
                  else {
                      z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
                      z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
                  }
              }
So, what i need to do now?

antonioli
Posts: 12
Joined: Sat Apr 24, 2010 3:28 pm
antibot: No, of course not.

Re: zoom in another window

Post by antonioli » Fri May 07, 2010 12:21 pm

i get it. I just do the clone() of the chart and i get it. But now the chart zoomed is smaller than the first, and i can put it with the same width and height. how i can the dimensions of the first chart or panel and put it in the second chart or panel?

antonioli
Posts: 12
Joined: Sat Apr 24, 2010 3:28 pm
antibot: No, of course not.

Re: zoom in another window

Post by antonioli » Mon May 10, 2010 9:49 pm

Hi..Now i have two tabs, the first with the original chart, and the second with a zoomed part of the chart. My problem how i can get the name or some identification of the chartPanel of a selected tab? I have tried:
TabedPane.getComponentAt(1), but this function returns me a null.

jsnel
Posts: 19
Joined: Thu Apr 19, 2007 12:00 pm

Re: zoom in another window

Post by jsnel » Tue May 11, 2010 10:40 am

Your question is a bit unclear:
Do you want to retrieve some information from tab 1 in order to create the chart in tab 2 (like for instance the Chart title). This you could do by simple calling getChart().getTitle().getText() for instance, and then you could even append the zoom range to the title for better identification.
Or do you want to do something based on what Chart exists in the currently selected tab - be it Tab 1, 2 or potentially Tab n. Because this goes way beyond the context of JFreeChart, you'll have to ask that question on a more general Java programming forum.
Creator of Glotaran, a software program developed for global and target analysis of time-resolved spectroscopy and microscopy data. Big fan of JFreeChart.

Locked