Present node +LineChart + JavaFX -


i using linechart in javafx8 , able series plotted dynamically in graph , symbols plotted every input. problem want show symbol present node , not nodes added.

i tried:

linechart.setcreatesymbols(false); 

but not fulfill needs.it stopped creating symbols inputs.

can tell how show present symbol not added oness????

just keep track of node last data point added. when new point added, set visibility of previous "last point" false.

you can directly with

import java.util.random;  import javafx.application.application; import javafx.geometry.insets; import javafx.geometry.pos; import javafx.scene.node; import javafx.scene.scene; import javafx.scene.chart.linechart; import javafx.scene.chart.numberaxis; import javafx.scene.chart.xychart.data; import javafx.scene.chart.xychart.series; import javafx.scene.control.button; import javafx.scene.layout.borderpane; import javafx.stage.stage;  public class linechartshowsymbolforlastpointonly extends application {      private node lastpointadded ;      @override     public void start(stage primarystage) {         linechart<number, number> chart = new linechart<>(new numberaxis(), new numberaxis());         series<number, number> series = new series<>();         chart.getdata().add(series);         chart.setanimated(false);          button adddatapointbutton = new button("add data point");         random rng = new random();         adddatapointbutton.setonaction(e -> {             if (lastpointadded != null) {                 lastpointadded.setvisible(false);             }             data<number, number> data = new data<>(series.getdata().size(), rng.nextdouble());             series.getdata().add(data);             lastpointadded = data.getnode();         });          borderpane.setalignment(adddatapointbutton, pos.center);         borderpane.setmargin(adddatapointbutton, new insets(10));         borderpane root = new borderpane(chart, null, null, adddatapointbutton, null);          primarystage.setscene(new scene(root, 800, 600));         primarystage.show();     }      public static void main(string[] args) {         launch(args);     } } 

if want able factor code out more readily, might use objectproperty , register listener:

import java.util.random;  import javafx.application.application; import javafx.beans.property.objectproperty; import javafx.beans.property.simpleobjectproperty; import javafx.geometry.insets; import javafx.geometry.pos; import javafx.scene.node; import javafx.scene.scene; import javafx.scene.chart.linechart; import javafx.scene.chart.numberaxis; import javafx.scene.chart.xychart.data; import javafx.scene.chart.xychart.series; import javafx.scene.control.button; import javafx.scene.layout.borderpane; import javafx.stage.stage;  public class linechartshowsymbolforlastpointonly extends application {      @override     public void start(stage primarystage) {         linechart<number, number> chart = new linechart<>(new numberaxis(), new numberaxis());         series<number, number> series = new series<>();         chart.getdata().add(series);         chart.setanimated(false);           objectproperty<node> lastpointadded = new simpleobjectproperty<>();         lastpointadded.addlistener((obs, oldnode, newnode) -> {             if (oldnode != null) {                 oldnode.setvisible(false);             }         });          button adddatapointbutton = new button("add data point");         random rng = new random();         adddatapointbutton.setonaction(e -> {             data<number, number> data = new data<>(series.getdata().size(), rng.nextdouble());             series.getdata().add(data);             lastpointadded.set(data.getnode());         });          borderpane.setalignment(adddatapointbutton, pos.center);         borderpane.setmargin(adddatapointbutton, new insets(10));         borderpane root = new borderpane(chart, null, null, adddatapointbutton, null);          scene scene = new scene(root, 800, 600);         primarystage.setscene(scene);         primarystage.show();     }      public static void main(string[] args) {         launch(args);     } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -