Results 1 to 4 of 4
  1. #1
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    272
    Rep Power
    7

    Default Event on piechart issue

    Hi,

    I am using JavaFX to build a piechart.
    I have done that and I want to add an event, so that whenever one puts their mouse on a variable in the chart, the percentage is displayed.

    I used this tutorial: https://docs.oracle.com/javafx/2/charts/pie-chart.htm

    The label should become visible when the mouse enters, but it does not. I only see the console print.

    This is the code

    Java FX Code:
    public class MainPanelController implements Initializable {
    
        @FXML
        private Button viewComments;
    
        @FXML
        private TextArea inputArea;
    
        @FXML
        private Button addText;
    
        @FXML
        private Button analyse;
    
        @FXML
        private PieChart pieChart;
        
        public void initialize(URL rul, ResourceBundle rb) {
        	  ObservableList<PieChart.Data> pieChartData =
                      FXCollections.observableArrayList(
                      new PieChart.Data("Positive", 20),
                      new PieChart.Data("Negative", 30),
                      new PieChart.Data("Neutral", 50));
        	pieChart.setData(pieChartData);
        	pieChart.setLegendSide(Side.BOTTOM);
        	// 
        	final Label caption = new Label("");
        	caption.setTextFill(Color.BLACK);
        	//caption.setStyle("-fx-font: 24 arial;");
        	pieChart.getData().stream()
        					  .forEach(data -> {
        						  data.getNode().addEventHandler(MouseEvent.MOUSE_ENTERED,
    				    	        event -> {
    				    	                caption.setTranslateX(event.getSceneX());
    				    	                caption.setTranslateY(event.getSceneY());
    				    	                caption.setText(data.getPieValue() + "%");
    				    	                caption.setVisible(true);				    	              
    				    	                System.out.println(data.getPieValue());         
    				    	              });
        					  });
      }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Event on piechart issue

    Quote Originally Posted by superhaNds View Post
    I am using JavaFX
    And we have a separate section for JavaFX.

    Thread moved from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Event on piechart issue

    1. Is the Label added to a Layout?
    2. Re-read the API for Node#translateX/Y(...). They may not be the scene coordinates.
    The node's final translation will be computed as layoutX + translateX, where layoutX establishes the node's stable position and translateX optionally makes dynamic adjustments to that position.
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    272
    Rep Power
    7

    Default Re: Event on piechart issue

    The label is not. This seems to be the problem.

    THe chart is the center of a borderpane; I added the label to the left and it it is displayed now, but in very weird positions. Maybe I have to change the layout

Similar Threads

  1. methods needed for drawing a piechart
    By fultonwilcox in forum New To Java
    Replies: 1
    Last Post: 09-14-2012, 07:51 PM
  2. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  3. Problem using a list with piechart
    By dennisbf in forum Networking
    Replies: 14
    Last Post: 09-22-2011, 01:54 AM
  4. piechart not being drawn on a panel
    By dataprofiling in forum Java 2D
    Replies: 1
    Last Post: 03-27-2010, 11:33 AM
  5. checking for an event during an event
    By infinity in forum AWT / Swing
    Replies: 22
    Last Post: 04-09-2009, 01:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •