zoom in another window
zoom in another window
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?
Re: zoom in another window
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
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.
Re: zoom in another window
I have this code:
So, what i need to do now?
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);
}
}
Re: zoom in another window
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?
Re: zoom in another window
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.
TabedPane.getComponentAt(1), but this function returns me a null.
Re: zoom in another window
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.
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.