returning plot X Y of mouse click position

Discussion about JFreeChart related to stockmarket charts.
Locked
JOhn Coleman
Posts: 3
Joined: Fri Mar 19, 2004 7:59 pm

returning plot X Y of mouse click position

Post by JOhn Coleman » Fri Mar 19, 2004 8:03 pm

On a candle chart I want to get the Y position (price off the Y axis, not Y coordinate) where the mouse is clicked on the chart.

Also can I get the candles high and lows back? Thinking laterally, if I get the X position (i.e. date), I could find the bar from looking in the array.

Anyone know how to acheive either of these. The API seems only to dicuss mouse events that return XY positions unrelated to the actual chart data.

John

aditya
Posts: 4
Joined: Thu Jun 17, 2004 10:02 am

Post by aditya » Thu Jun 17, 2004 10:08 am

Here is a snippet that does just that:


public void chartMouseClicked(ChartMouseEvent event)
{
int x = event.getTrigger().getX();
int y = event.getTrigger().getY();
XYItemEntity entity = (XYItemEntity) chartPanel.getEntityForPoint(x,y);
int item;
if(entity != null)
{
item = entity.getItem();
String closeStr = new Double(data.getClose(0,item)).toString();
String highStr = new Double(data.getHigh(0,item)).toString();
String lowStr = new Double(data.getLow(0,item)).toString();
String openStr = new Double(data.getOpen(0,item)).toString();
..... and so on .....
}
}

//in the above snippet 0 is hardcoded since I was using only one series.

Hope this helps.

Aditya

Locked