Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hover popup on LineChart

893805Oct 11 2011 — edited Oct 12 2011
I am building a line chart graph and what to create a small modal/popup/tooltip to display the exact data points for the graph point that they are mousing over.

It looks like I would need to do this by attaching an event handler to the XYChart.Data<x,y> object that is added. But I can't find any information on how to attach the event handler that will work.

I originally tried it this way

List<XYChart.Data> data = new ArrayList<XYChart.Data>();
for (int i = 0; i < 12; i++) {
XYChart.Data<String, BigDecimal> dataPoint = new XYChart.Data<>(i + "", BigDecimal.valueOf(new Random().nextDouble() * 10000));

dataPoint.getNode().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {

public void handle(MouseEvent event) {
System.out.println(event.getSource().toString());

}
});
data.add(dataPoint);

}


But that threw error as the getNode() method returned null. I am sure that I am doing this is a somewhat backwards way, but I can't find a better example. The JavaFX site says that a chart example (including hovers was in the sample code) but I can't find it if it's there.


Can someone point out to me what I need to do here?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2011
Added on Oct 11 2011
2 comments
1,485 views