I want to set points in my application with the mouse. I use JFreeChart and use the ChartPanel mouse listener. It looks like this:
panel.addChartMouseListener(new ThisMouseListener());
and my mouse listener ThisMouseListener () (it's not finished yet):
class ThisMouseListener implements ChartMouseListener{
@Override
public void chartMouseClicked(ChartMouseEvent event) {
int x = event.getTrigger().getX();
int y = event.getTrigger().getY();
System.out.println("X :" + x + " Y : " + y);
ChartEntity entity = event.getEntity();
if(entity != null && (entity instanceof XYItemEntity)){
XYItemEntity item = (XYItemEntity)entity;
}
new JOptionPane().showMessageDialog(null, "Hello", "Mouse Clicked event", JOptionPane.OK_OPTION);
}
@Override
public void chartMouseMoved(ChartMouseEvent arg0) {
}
}
but this mouse listener returns me my panel coordinates, and I want to get the coordinates from my chart. Maybe I should use a listener with another object? Or can I convert the coordinates using some method?
source
share