Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:40:08+00:00 2026-06-07T19:40:08+00:00

I would like to export (.txt or .cvs) data plotted on a graph by

  • 0

I would like to export (.txt or .cvs) data plotted on a graph by left mouse click, highlight it then right mouse click opens a pop-up then a file chooser dialog to save data

Here is a picture example

enter image description here

and here is a sample code

public class BaseXYChart extends Application {

@Override
public void start(Stage stage) {
   stage.setTitle("Linear plot");

   final CategoryAxis xAxis = new CategoryAxis();
   final NumberAxis yAxis = new NumberAxis(0, 22, 0.5);

   yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis){
        @Override
    public String toString(Number object){
        return String.format("%7.2f", object);
    }
});
final LineChart<String, Number>lineChart = new LineChart<String, Number>(xAxis, yAxis);

   lineChart.setCreateSymbols(false);
   lineChart.setAlternativeRowFillVisible(false);
   lineChart.setLegendVisible(false);

   XYChart.Series series1 = new XYChart.Series();

    series1.getData().add(new XYChart.Data("Jan", 1));
    series1.getData().add(new XYChart.Data("Feb", 1.5));
    series1.getData().add(new XYChart.Data("Mar", 2));
    series1.getData().add(new XYChart.Data("Apr", 2.5));
    series1.getData().add(new XYChart.Data("May", 3));
    series1.getData().add(new XYChart.Data("Jun", 4));
    series1.getData().add(new XYChart.Data("Jul", 6));
    series1.getData().add(new XYChart.Data("Aug", 9));
    series1.getData().add(new XYChart.Data("Sep", 12));
    series1.getData().add(new XYChart.Data("Oct", 15));
    series1.getData().add(new XYChart.Data("Nov", 20));
    series1.getData().add(new XYChart.Data("Dec", 22));

    BorderPane pane = new BorderPane();
    pane.setCenter(lineChart);          
    Scene scene = new Scene(pane, 800, 600);
    lineChart.getData().addAll(series1);

    stage.setScene(scene);
    stage.show();
}

public static void main(String[] args) {
    launch(args);
}   

}

My question is then how to do to select the line data plotted in order to then open a pop-up.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:40:10+00:00Added an answer on June 7, 2026 at 7:40 pm

    Check the modified code of yours below out.

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Cursor;
    import javafx.scene.Node;
    import javafx.scene.Scene;
    import javafx.scene.chart.CategoryAxis;
    import javafx.scene.chart.LineChart;
    import javafx.scene.chart.NumberAxis;
    import javafx.scene.chart.XYChart;
    import javafx.scene.control.ContextMenu;
    import javafx.scene.control.MenuItem;
    import javafx.scene.effect.DropShadow;
    import javafx.scene.input.MouseButton;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    
    public class BaseXYChart extends Application {
    
        private DropShadow ds = new DropShadow();
    
        private ContextMenu contextMenu;
    
        private XYChart.Series selectedSeries;
    
        @Override
        public void start(Stage stage) {
            stage.setTitle("Linear plot");
    
            final CategoryAxis xAxis = new CategoryAxis();
            final NumberAxis yAxis = new NumberAxis(0, 22, 0.5);
    
            yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
    
                @Override
                public String toString(Number object) {
                    return String.format("%7.2f", object);
                }
            });
            final LineChart<String, Number> lineChart = new LineChart<String, Number>(xAxis, yAxis);
    
            lineChart.setCreateSymbols(false);
            lineChart.setAlternativeRowFillVisible(false);
            lineChart.setLegendVisible(false);
    
            final XYChart.Series series1 = new XYChart.Series();
    
            series1.getData().add(new XYChart.Data("Jan", 1));
            series1.getData().add(new XYChart.Data("Feb", 1.5));
            series1.getData().add(new XYChart.Data("Mar", 2));
            series1.getData().add(new XYChart.Data("Apr", 2.5));
            series1.getData().add(new XYChart.Data("May", 3));
            series1.getData().add(new XYChart.Data("Jun", 4));
            series1.getData().add(new XYChart.Data("Jul", 6));
            series1.getData().add(new XYChart.Data("Aug", 9));
            series1.getData().add(new XYChart.Data("Sep", 12));
            series1.getData().add(new XYChart.Data("Oct", 15));
            series1.getData().add(new XYChart.Data("Nov", 20));
            series1.getData().add(new XYChart.Data("Dec", 22));
    
            BorderPane pane = new BorderPane();
            pane.setCenter(lineChart);
            Scene scene = new Scene(pane, 800, 600);
            lineChart.getData().addAll(series1);
    
            contextMenu = new ContextMenu();
            MenuItem menuItem = new MenuItem("Save data");
            contextMenu.getItems().add(menuItem);
            menuItem.setOnAction(new EventHandler<ActionEvent>() {
    
                @Override
                public void handle(ActionEvent arg0) {
                    if (selectedSeries != null) {
                        System.out.println("Save data of " + selectedSeries.getData());
                        // Saving logic here
                    }
                }
            });
    
            // for every series in linechart
            applyMouseEvents(series1);
    
            stage.setScene(scene);
            stage.show();
        }
    
        private void applyMouseEvents(final XYChart.Series series) {
    
            final Node node = series.getNode();
    
            node.setOnMouseEntered(new EventHandler<MouseEvent>() {
    
                @Override
                public void handle(MouseEvent arg0) {
                    node.setEffect(ds);
                    node.setCursor(Cursor.HAND);
                }
            });
    
            node.setOnMouseExited(new EventHandler<MouseEvent>() {
    
                @Override
                public void handle(MouseEvent arg0) {
                    node.setEffect(null);
                    node.setCursor(Cursor.DEFAULT);
                }
            });
    
            node.setOnMouseReleased(new EventHandler<MouseEvent>() {
    
                @Override
                public void handle(MouseEvent mouseEvent) {
                    if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) {
                        contextMenu.show(node, mouseEvent.getScreenX() + 1, mouseEvent.getScreenY() + 1);
                        // Set as selected
                        selectedSeries = series;
                        System.out.println("Selected Series data " + selectedSeries.getData());
                    }
                }
            });
        }
    
        public static void main(String[] args) {
            launch(args);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel table with some data that I would like to export
I would like to export part of a database full of data to an
I would like to export a table with image data-type column to a flat
I have Sql Server database and i would like to export the data as
I would like to export a subset of my Redis data on the slave
I would like to export some macros that I have defined and be able
I would like to export a Java Bean or ResultSet(JDBC) into a CSV file
I'm using IIS6 using powershell I would like to export a specific virtual directory
We built a iphone app and now we would like to export it to
I have a sictus prolog file (.pl-file) that I would like to export as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.