饼图值未悬停显示

时间:2019-01-28 10:15:56

标签: java javafx pie-chart

我的MOUSE_MOVED和MOUSE_EXIT事件似乎不起作用。我在哪里弄错了?

   final Label captions = new Label();
        captions.setTextFill(Color.WHITE);
        captions.setStyle("-fx-font: 24 arial;");
        DropShadow shadow = new DropShadow();

  for (final PieChart.Data data : pieChart2.getData()) {    
            data.getNode().addEventHandler(MouseEvent.MOUSE_MOVED,
                    new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent e) {
                            captions.setTranslateX(e.getSceneX()+15);
                            captions.setTranslateY(e.getSceneY());
                           captions.setText(String.valueOf(data.getPieValue()) + "%");
                            captions.setVisible(true);


                        }
                    });

            data.getNode().addEventHandler(MouseEvent.MOUSE_EXITED,
                    new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent e) {

                            captions.setVisible(false);
                        }
                    });
        }

切片悬停时什么也没显示

0 个答案:

没有答案