0

I have BarChart

    private void fillChartOpinion2() {
    XYChart.Series<String, Integer> chartSeries = new XYChart.Series<>();
    chartSeries.setName("NFS");

    Calendar calendar = Calendar.getInstance();
    for(Opinion opinion : opinionList) {
        calendar.setTimeInMillis(opinion.getDateProperty().getTime());
        ObservableList<XYChart.Data<String,Integer>> observableData = FXCollections.observableArrayList();
        XYChart.Data<String,Integer> chartData =  new XYChart.Data<>(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)),opinion.getOpinionProperty());
        Tooltip tooltip = new Tooltip();
        tooltip.setText("test");
        observableData.add(chartData);
        chartSeries.setData(observableData);
        Tooltip.install(chartData.getNode(),tooltip);
    }
    opinionChart.getData().clear();

    opinionChart.getData().addAll(chartSeries);
}

it looks like:

enter image description here

but I can't set tooltip to each column of chart... my code doesn't work.

How to do it when mouse cursor in column area or click on column area?

Vitaly M.
  • 103
  • 3
  • I think someone asked this just the other day... try calling `Tooltip.install(...)` *after* `chartSeries.getData().add(....)`. – James_D Jan 26 '18 at 13:30
  • nope... it don't help... – Vitaly M. Jan 26 '18 at 14:52
  • As mentioned in the comments below the answer to the duplicate question, the node is not created until the data are added to the *chart*. So as well as installing the tooltip after adding the data to the series, you need to add the series to the chart before the for loop. (Else you are just adding data to a series that is not associated with a chart.) – James_D Jan 26 '18 at 15:15
  • So, I've edited my code. And execute Tooltip.install(chartData.getNode(),tooltip); after add to a series, but it's still doesn't work... – Vitaly M. Jan 26 '18 at 15:23
  • See the last comment... – James_D Jan 26 '18 at 15:23
  • thank you! I understand! I move ` opinionChart.getData().clear();` and `opinionChart.getData().addAll(chartSeries);` before `for {...}` – Vitaly M. Jan 26 '18 at 15:40

0 Answers0