Tooltips for datapoints in a scatter chart in javafx 2.2


I have created a scatter chart in javafx.It consists of five series of data.I added data from an Arraylist.I need to show a tooltip on every datapoint.To add tooltip it says that we need to create a node for every datapoint.How can we do that?

I tried creating node while adding data but i didnot succeed. I also tried accessing data from scatter chart and assigning it to a new series.even that didnot work.Can someone please help me retrieve details or datapoints from a scatter chart and create a node to each datapoint. Thanks in Advance

1/2/2013 6:38:50 AM

From the API doc of XYChart.Data.nodeProperty: (bold marking by me)

public final ObjectProperty nodeProperty

The node to display for this data item. You can either create your own node and set it on the data item before you add the item to the chart. Otherwise the chart will create a node for you that has the default representation for the chart type. This node will be set as soon as the data is added to the chart. You can then get it to add mouse listeners etc. Charts will do their best to position and size the node appropriately, for example on a Line or Scatter chart this node will be positioned centered on the data values position. For a bar chart this is positioned and resized as the bar for this data item.

It should probably be best to let the chart set its default Nodes and register Tooltips later. Like this:

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;

public class SO extends Application {
    public void start(Stage stage) throws Exception {
        NumberAxis xa = new NumberAxis(0, 10, 1);
        NumberAxis ya = new NumberAxis(0, 100, 10);
        final ScatterChart<Number,Number> chart = new ScatterChart<Number,Number>(xa,ya);

        XYChart.Series<Number,Number> series1 = new XYChart.Series<>();
        for (double x=0; x<10; x++) {
            XYChart.Data<Number, Number> d = new XYChart.Data<Number, Number>(x, x*x);

        Scene scene  = new Scene(chart, 400, 300);

        for (XYChart.Series<Number, Number> s : chart.getData()) {
            for (XYChart.Data<Number, Number> d : s.getData()) {
                Tooltip.install(d.getNode(), new Tooltip(
                        String.format("%2.1f ^ 2 = %2.1f", 

    public static void main(String[] args) {

Looks like this:

enter image description here

Nice article about scatter charts:

3/30/2013 2:11:35 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow