Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8125003

Pie chart section mouse selection problem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • fx2.1
    • javafx
    • None

      Sometimes when pie chart has its nodes assigned to mouse event,
      on which selected chart section is highlighted and some data is displayed,
      the section selected is not the same which user tended to select.
      It occurs when picked for selection section has size smaller then the other.
      Most frustrating thing is that this section could not be selected in any way.

      ...
      private DropShadow ds = new DropShadow();
      private double totalChartValue = /*total chart value here*/;
      ...
      for (PieChart.Data data : pieChart.getData()) {
            Node node = data.getNode();
            node.setOnMouseEntered(new OnMouseOverPopupEvent(data, totalChartValue));
      }
      ...
      protected class OnMouseOverPopupEvent implements EventHandler<MouseEvent> {
          private double totalChartValue;
          private PieChart.Data data;

          PieChartEvent(PieChart.Data data, double totalChartValue) {
            this.totalChartValue = totalChartValue;
            this.data = data;
          }

          public void handle(MouseEvent mouseEvent) {
             Node node = (Node) mouseEvent.getSource();
             node.setEffect(ds);
             node.setCursor(Cursor.HAND);

             double x = mouseEvent.getScreenX();
             double y = mouseEvent.getScreenY();

             DecimalFormat decimalFormat = new DecimalFormat("#.##");
             double percentage = data.getPieValue() * 100 / totalChartValue;
             String formattedData = String.valueOf(data.getPieValue()) + " of " + totalChartValue + "\n"
                + decimalFormat.format(percentage) + " %";
             Text chartValues = new Text(formattedData );

             HBox hbChartValues = new HBox();
             hbChartValues.getChildren().add(chartValues);

             popup = new Popup();
             popup.setAutoHide(true);
             popup.setX(x);
             popup.setY(y);
             popup.getContent().addAll(hbChartValues);
             popup.show(primaryStage);
          }
        }

            psomashe Parvathi Somashekar (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: