JavaFX 8 How to dispose a Node object on a JavaFX Line chart

JavaFX 8 How to dispose a Node object on a JavaFX Line chart

By : peitsing
Date : November 16 2020, 06:23 AM
I hope this helps . I found a solution to my problem.
The approach is to check if the moaPlot.getXValue().equals(lowerBound) then remove it from the textSeries list.
code :
    textSeries.getData().removeIf(moa -> (moa.getXValue().before(lowerBound))); 
}, 0, 1, TimeUnit.SECONDS);

Share : facebook icon twitter icon
Retrieve String values from a CategoryAxis in a javaFX Line Chart -CategoryAxis JavaFx 2.2.3 bug in .getValueForDisplay(

Retrieve String values from a CategoryAxis in a javaFX Line Chart -CategoryAxis JavaFx 2.2.3 bug in .getValueForDisplay(

By : murad
Date : March 29 2020, 07:55 AM
I wish this helpful for you There are 2 issues.
1) You are using wrong coordinates. getValueForDisplay expects coordinates relative to chart drawing area, not to scene.
code :
private double xSceneShift(Node node) {
    return node.getParent() == null ? 0 : node.getBoundsInParent().getMinX() + xSceneShift(node.getParent());

private double ySceneShift(Node node) {
    return node.getParent() == null ? 0 : node.getBoundsInParent().getMinY() + ySceneShift(node.getParent());
Node chartPlotBackground = chart.lookup(".chart-plot-background");
final double shiftX = xSceneShift(chartPlotBackground);
final double shiftY = ySceneShift(chartPlotBackground);
public void handle(MouseEvent e) {
    double x = e.getSceneX() - shiftX;
    double y = e.getSceneY() - shiftY;

    xValue = xAxis.getValueForDisplay(x );
    yValue = yAxis.getValueForDisplay(y);

    System.out.println(" X value = "
                    + xValue + " \nY value: " + yValue);
How to drag a JavaFX node and detect a drop event outside the JavaFX Windows?

How to drag a JavaFX node and detect a drop event outside the JavaFX Windows?

By : Axe Sude
Date : March 29 2020, 07:55 AM
With these it helps You can listen for a mouse released event on the appropriate node (e.g. the tab's graphic). Check the screen coordinates using MouseEvent.getScreenX() and MouseEvent.getScreenY() and see if they lie outside the current window. If they do, create a new window, scene, and tab pane; remove the tab from the current tab pane and place it in the new one.
Here's a basic example with no frills (e.g. no user hints as to the fact that dragging is occuring), but it will give you the idea:
code :
import javafx.application.Application;
import javafx.collections.ListChangeListener.Change;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.Window;

public class DetachableTabExample extends Application {

    private int tabCount = 0 ;

    public void start(Stage primaryStage) {
        TabPane tabPane = new TabPane();
        Button newTabButton = new Button("New Tab");
        newTabButton.setOnAction(event -> {
            Tab tab = new Tab();
            Label tabLabel = new Label("Tab "+(++tabCount));
            tab.setContent(new TextArea());

            tabLabel.setOnMouseReleased(me -> {
                Point2D mouseLoc = new Point2D(me.getScreenX(), me.getScreenY());
                Window window = tabPane.getScene().getWindow();
                Rectangle2D windowBounds 
                    = new Rectangle2D(window.getX(), window.getY(),
                                      window.getWidth(), window.getHeight());
                if (! windowBounds.contains(mouseLoc)) {
                    Stage newStage = new Stage();
                    TabPane newTabPane = new TabPane();
                    Scene scene = new Scene(new BorderPane(newTabPane));


        BorderPane root = new BorderPane(tabPane, newTabButton, null, null, null);
        Scene scene = new Scene(root, 600, 400);

    public static void main(String[] args) {
How to combine scatter chart with line chart to show line of regression? JavaFX

How to combine scatter chart with line chart to show line of regression? JavaFX

By : Richard Wang
Date : March 29 2020, 07:55 AM
it helps some times While @Mailkov solution is fine, it has some drawbacks (overlapping legends, tooltips...).
Just for mixing an scattered chart with a line chart in the same chart there's a very simple way, with css.
code :
.default-color0.chart-series-line { -fx-stroke: transparent; }
.default-color1.chart-series-line { -fx-stroke: red; }

.default-color0.chart-line-symbol { 
    -fx-background-color: white, green; 
.default-color1.chart-line-symbol { 
    -fx-background-color: transparent, transparent; 

    -fx-background-color: green;
    -fx-background-color: red;
public void start(Stage stage) {
    final LineChart<Number,Number> sc = new LineChart<>(new NumberAxis(),new NumberAxis());

    XYChart.Series series1 = new XYChart.Series();
    series1.getData().add(new XYChart.Data(4.2, 193.2));
    series1.getData().add(new XYChart.Data(2.8, 33.6));
    series1.getData().add(new XYChart.Data(6.8, 23.6));

    XYChart.Series series2 = new XYChart.Series();
    series2.setName("Mutual funds");
    series2.getData().add(new XYChart.Data(5.2, 229.2));
    series2.getData().add(new XYChart.Data(2.4, 37.6));
    series2.getData().add(new XYChart.Data(6.4, 15.6));


    sc.getData().addAll(series1, series2);

    Scene scene  = new Scene(sc, 500, 400);
JavaFX Intellij error "Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.b

JavaFX Intellij error "Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.b

By : anonymous
Date : March 29 2020, 07:55 AM
this will help to ItachiUchiha for leading me to the answer.
Checking the SDK for my pc revealed that there was no SDK selected. I'm not sure how it was working before.
Setting tooltips on JavaFX line chart node

Setting tooltips on JavaFX line chart node

By : Boyan Yurukov
Date : March 29 2020, 07:55 AM
Hope this helps I'm trying to add tooltips to the different nodes on a JavaFX line chart. My chart has two different series; each series has multiple data points. Each data point relates to an object. I need to access the datapoint's associated object in order to add information to its tooltip. , Looking at your code, your problem is
code :
listeningSeries.getData().add(new XYChart.Data(Integer.toString(listeningQuestionCount), timeSpent));
new XYChart.Data(Integer.toString(listeningQuestionCount), timeSpent)
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;

 * @author blj0011
public class JavaFXApplication250 extends Application

    public void start(Stage stage)
        stage.setTitle("Line Chart Sample");
        //defining the axes
        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();
        xAxis.setLabel("Number of Month");
        //creating the chart
        final LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);

        lineChart.setTitle("Stock Monitoring, 2010");
        //defining a series
        XYChart.Series<Number, Number> series = new XYChart.Series();
        series.setName("My portfolio");
        //populating the series with data
        Random rand = new Random();

        Map<Integer, Integer> data = new TreeMap();
        //Create Chart data
        for (int i = 0; i < 3; i++) {
            data.put(rand.nextInt(51), rand.nextInt(51));
        Set set = data.entrySet();

        //When you create the data points for the series, go ahead and add any assoicated data to the data point.
        int counter = 1;
        Iterator i = set.iterator();
        while (i.hasNext()) {
            Map.Entry me = (Map.Entry) i.next();
            System.out.println(me.getKey() + " - " + me.getValue());
            XYChart.Data tempData = new XYChart.Data(me.getKey(), me.getValue());
            tempData.setExtraValue("I am data point " + counter++);
            series.getData().add(tempData);//Add data to series


        //loop through data and add tooltip
        for (Data<Number, Number> entry : series.getData()) {
            Tooltip t = new Tooltip(entry.getExtraValue().toString());
            Tooltip.install(entry.getNode(), t);

        Scene scene = new Scene(lineChart, 800, 600);


     * @param args the command line arguments
    public static void main(String[] args)

Related Posts Related Posts :
  • Multiple Consumers Spring Kafka
  • Bitbucket pipeline: environmental variables in build.gradle file not recognized
  • Java static enum method to return a default enum value
  • What is the complexity of empty for loop?
  • Group randomly List of Lists as N subsets with K elements in each
  • How to set texture on a shape drawn by glDrawArrays()?
  • How to make a jlabel resizable according to the window
  • Java Mathematical Expression Syntax
  • assigning values to characters in java
  • Method overriding and Inheritance in java
  • given a set of lists/groups with a series of number, find matching numbers
  • Connection to HID USB device (keyboard and mouse) in android
  • Inject HttpServletRequest in CDI SessionScoped bean
  • Pool game in java - ball collision algorithm
  • Focus ScrollView to selected position programmatically - Android
  • Is it hibernate bug?
  • Glib memory allocation error
  • Android Proguard - step by step
  • Setting the pivot point of a JPanel to its center
  • java check time is greater time
  • how to save a screenshot (matlab)
  • Anti-aliasing filled shapes in libgdx
  • Gwt custom text box having baloon popup
  • How to change date dynamically for each element in an Array
  • JPanel won't add the JLabel text?
  • how to access the .properties file in ant if it is in different location
  • Reduce application memory footprint
  • java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
  • What is the exact purpose of calling System.exit() in java
  • How to do you get output from Javascript into Java using ScriptEngine
  • Java replaceAll() method to escape special characters
  • Java (Removing a 'keyword' from the alphabet)
  • Format BigDecimal in Spring
  • iterating checkbox values stored in array using EL
  • Java - Jackcess API with .accde(MS Access) format
  • Alternative for some of Struts 1 methods in Struts 2
  • javax.crypto JDK source code, again
  • Spring Roo - Command 'service' not found
  • antlr4: ATN version 2 expected 3
  • Deploy GlassFish using Netbeans generate java.net.MalformedURLException: Bad URL path
  • why is wait() called for loop in Thread.join() of Java?
  • Java JAXB marshall into DOM Document
  • Why JDBI 3 @ColumnName annotation doesn't work?
  • Java SimpleDateformatter with 10 decimals after the seconds, cannot convert to Date
  • Getting array index out of bounds when splitting a string in android
  • Verify if csv file is updated successfully
  • Get the parameter names of an interface method
  • How to retrieve object state from serialized Java objects without class file(s)
  • How to move a programmed game for pc to android
  • Size of an object and a string in Java
  • PrimeFaces Datatable Right Click Select + Row Specific Context Menu
  • How to use OOP to branch from a point class into lines and triangles (Java)
  • What does 'String...' mean?
  • Add YouTube Data API to Android Studio
  • JComboBox in JTable not displaying options, only the correct number of blank options
  • JTable and removeAll behavior
  • Google App Engine: Can I programmatically find out if this is the default version?
  • How do you open a program by using ActionListener in Java?
  • Android SipManager: android.net.sip.SipException: SipService.createSession() returns null
  • Forcefully terminating a thread I didn't write in Java
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org