Get Domain Axis Maximum Value after Zooming

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
miracatici
Posts: 2
Joined: Thu Jan 08, 2015 3:57 pm
antibot: No, of course not.

Get Domain Axis Maximum Value after Zooming

Post by miracatici » Thu Jan 08, 2015 4:23 pm

Hi everyone. It's my first question. I'm using JFreeChart 1.0.19 on Eclipse IDE on MaxOSX.

I would like to get X (Domain) Axis value when I press and release mouse point individually. It means that when I press the mouse get X value, drag, release and get new X value. However, when try this with mouse listener, I can get first pressed value easily but after creating zoom rectangle zoom action done first. So, because of that I can only get X value of mouse position on zoomed chart. My listener code is here. (My chart added to a panel)

Could I get maximum domain value of zoomed chart? I don't need to get value first and then zoom. If zooming must be first and if I can get maximum x axis value of zoomed chart, it's ok for me! :)

Thanks in advance.

Code: Select all

panel.addMouseListener(new MouseListener(){
			@Override
			public void mousePressed(MouseEvent arg0) {
				ChartMouseEvent event = new ChartMouseEvent(chart, arg0, null);
				xPrev = chart.getXYPlot().getDomainAxis().java2DToValue
						(event.getTrigger().getX(), 
								panel.getScreenDataArea(), 
								chart.getXYPlot().getDomainAxisEdge());				
			}
			@Override
			public void mouseReleased(MouseEvent arg0) {
				ChartMouseEvent event = new ChartMouseEvent(chart, arg0, null);			
				xCurr = chart.getXYPlot().getDomainAxis().java2DToValue
						(event.getTrigger().getX(), 
								panel.getScreenDataArea(), 
								chart.getXYPlot().getDomainAxisEdge());					
			}
			public void mouseClicked(MouseEvent arg0) {}
			public void mouseEntered(MouseEvent arg0) {}
			public void mouseExited(MouseEvent arg0) {}
	    });

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Get Domain Axis Maximum Value after Zooming

Post by david.gilbert » Thu Jan 08, 2015 6:28 pm

After the zoom, you can call the getRange() method on the domain (X) axis and it will give you the minimum and maximum x-values (likewise for the y-axis). You don't need to take the mouse coordinates and convert them to data values, since that is done internally by JFreeChart when setting the new axis ranges.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

miracatici
Posts: 2
Joined: Thu Jan 08, 2015 3:57 pm
antibot: No, of course not.

Re: Get Domain Axis Maximum Value after Zooming

Post by miracatici » Fri Jan 09, 2015 12:21 am

Thank you very much. That's exact solution that I want.

Locked