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
returning plot X Y of mouse click position
-
- Posts: 3
- Joined: Fri Mar 19, 2004 7:59 pm
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
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