Axis / Scaling problem?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
samoht
Posts: 12
Joined: Wed Jun 18, 2008 12:25 pm
Location: Norway

Axis / Scaling problem?

Post by samoht » Thu Jun 19, 2008 1:42 pm

I have problem with getting the correct Y values when having mouseover a point on my chart.. This is what i have in my listener:

public void chartMouseMoved(ChartMouseEvent move) {

MouseEvent e = move.getTrigger();
int x = e.getX();
int y = e.getY();

Point2D p =frame.getChartPanel().translateScreenToJava2D(e.getPoint());
XYPlot xyplot = frame.getChartPanel().getChart().getXYPlot();

Rectangle2D dataArea = frame.getChartPanel().getChartRenderingInfo().getPlotInfo().getDataArea();

double xValue = xyplot.getDomainAxis().java2DToValue(p.getX(), dataArea, xyplot.getDomainAxisEdge());

double yValue = xyplot.getDomainAxis().java2DToValue(p.getY(), dataArea, xyplot.getRangeAxisEdge());

System.out.println( "X: " + xValue + " Y: " + yValue);

}

If I use the dataArea.getHeight() / dataArea.getWidth() i can observe that one of them is bigger than the other is this where my problem lies? Do i have to redraw the graph?

It returns the right x value since this is always the biggest of the two.
Im guessing it has something to do with scaling of the axis...? Could someone help me out here?

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Axis / Scaling problem?

Post by RichardWest » Thu Jun 19, 2008 5:15 pm

samoht wrote:Could someone help me out here?
You seem to be using the domain axis to compute yValue which could explain a lot of the scaling issues.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

samoht
Posts: 12
Joined: Wed Jun 18, 2008 12:25 pm
Location: Norway

Post by samoht » Fri Jun 20, 2008 7:16 am

ah :D iI'v seen over the code like 10 times and still I miss it, thanks :)

Locked