How to remove and add plotted data?

In my code below I would like to add two buttons and by clicking on a button("Remove") it will remove one by one plotted data,and plot it back by clicking on the button("Add") such as the examples:
Full data plotted by running the class
Now by a single click on a Remove button last data point disappear
another click and again last data point disappear, and so on
The inverse operation would be performed by clicking on "Add" button: each click will add back a data point
import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.EventHandler; 
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
public class XYMove extends Application {
BorderPane pane;
XYChart.Series series1 = new XYChart.Series();
SimpleDoubleProperty rectinitX = new SimpleDoubleProperty();
SimpleDoubleProperty rectX = new SimpleDoubleProperty();
SimpleDoubleProperty rectY = new SimpleDoubleProperty();
@Override
public void start(Stage stage) {
final NumberAxis xAxis = new NumberAxis(12, 20, 1);
double max = 12;
double min = 3;
max *= (1+((double)3/100));
min *= (1-((double)3/100));
final NumberAxis yAxis = new NumberAxis(min, max, 1);
xAxis.setAnimated(false);
yAxis.setAnimated(false);
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
    @Override
    public String toString(Number object) {
        return String.format("%2.0f", object);
final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
lineChart.setCreateSymbols(false);
lineChart.setAlternativeRowFillVisible(false);
lineChart.setAnimated(false);
lineChart.setLegendVisible(false);
series1.getData().add(new XYChart.Data(1, 3));
series1.getData().add(new XYChart.Data(2, 8));
series1.getData().add(new XYChart.Data(3, 6));
series1.getData().add(new XYChart.Data(4, 7));
series1.getData().add(new XYChart.Data(5, 5));
series1.getData().add(new XYChart.Data(6, 6));
series1.getData().add(new XYChart.Data(7, 4));
series1.getData().add(new XYChart.Data(8, 7));
series1.getData().add(new XYChart.Data(9, 6));
series1.getData().add(new XYChart.Data(10, 7));
series1.getData().add(new XYChart.Data(11, 6));
series1.getData().add(new XYChart.Data(12, 7));
series1.getData().add(new XYChart.Data(13, 6));
series1.getData().add(new XYChart.Data(14, 12));
series1.getData().add(new XYChart.Data(15, 10));
series1.getData().add(new XYChart.Data(16, 11));
series1.getData().add(new XYChart.Data(17, 9));
series1.getData().add(new XYChart.Data(18, 10));
pane = new BorderPane();
pane.setCenter(lineChart);
Scene scene = new Scene(pane, 800, 600);
lineChart.getData().addAll(series1);
stage.setScene(scene);        
scene.setOnMouseClicked(mouseHandler);
scene.setOnMouseDragged(mouseHandler);
scene.setOnMouseEntered(mouseHandler);
scene.setOnMouseExited(mouseHandler);
scene.setOnMouseMoved(mouseHandler);
scene.setOnMousePressed(mouseHandler);
scene.setOnMouseReleased(mouseHandler);
stage.show();
EventHandler<MouseEvent> mouseHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
    if (mouseEvent.getEventType() == MouseEvent.MOUSE_PRESSED) {            
        rectinitX.set(mouseEvent.getX());
    else if (mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED || mouseEvent.getEventType() == MouseEvent.MOUSE_MOVED) {
        LineChart<Number, Number> lineChart = (LineChart<Number, Number>) pane.getCenter();
        NumberAxis xAxis = (NumberAxis) lineChart.getXAxis();
        double Tgap = xAxis.getWidth()/(xAxis.getUpperBound() - xAxis.getLowerBound());
        double newXlower=xAxis.getLowerBound(), newXupper=xAxis.getUpperBound();            
        double Delta=0.3;
        if(mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED){
        if(rectinitX.get() < mouseEvent.getX()&& newXlower >= 0){   
            newXlower=xAxis.getLowerBound()-Delta;
            newXupper=xAxis.getUpperBound()-Delta;
    else if(rectinitX.get() > mouseEvent.getX()&& newXupper <= 22){   
            newXlower=xAxis.getLowerBound()+Delta;
            newXupper=xAxis.getUpperBound()+Delta;
        xAxis.setLowerBound( newXlower );
        xAxis.setUpperBound( newXupper );                       
        rectinitX.set(mouseEvent.getX());                                
    public static void main(String[] args) {
        launch(args);
}Thanks!

I would use an ObservableList (probably backed by a LinkedList) of XYChart.Data to store the collection of "deleted" data points. Create the buttons as usual; your "Remove" button's event handler should remove the last element of the series and add it to the first element of the deleted items data points. The "Add" button should remove the first element of the deleted data points and add it to the end of the series. You can bind the "disable" property of the remove and add button to Bindings.isEmpty(series1.getData()) and Bindings.isEmpty(deletedDataPoints), respectively.
Something like
ObservableList<XYChart.Data<Number, Number>> deletedDataPoints = FXCollections.observableList(new LinkedList<XYChart.Data<Number, Number>>());
removeButton.setOnAction(new EventHandler<ActionEvent>() {
  @Override
  public void handle(ActionEvent event) {
    deletedDataPoints.add(0, series1.getData().remove(series1.getData().size()-1));
addButton.setOnAction(new EventHandler<ActionEvent>() {
  @Override
  public void handle(ActionEvent event) {
    series1.getData().add(deletedDataPoints.remove(0));
removeButton.disableProperty().bind(Bindings.isEmpty(series1.getData()));
addButton.disableProperty().bind(Bindings.isEmpty(deletedDataPoints));The other approach would be to use a separate List for all the data points, and keep an integer variable storing the number of data points displayed. Your "remove" button would decrement the number displayed, and your "add" button would increment the number displayed. Both would also call
series1.getData().setAll(allDataPoints.sublist(0, numberOfDisplayedPoints));You might even be able to make the numberOfDisplayedPoints an IntegerProperty and bind the data property of the series to it in a nice way. This approach probably doesn't perform as well as the previous approach (using a stack of deleted points), because you are not directly giving the chart as much detailed information about what has changed.
Both approaches get problematic (in the sense that you need to carefully define your application logic, and then implement it) if the underlying data has the potential to change.

Similar Messages

  • How to remove and add the component to JFrame at runtime.

    Hi
    How to delete the JTabbedPane component from the Jframe at runtime and how to add the same component with different data at runtime.
    But the remaining components should not distrub.
    When i try to delete and add the component at runtime the remaing components are distrubed.
    when i minimize and maximize the screen, the components are adjusted. but i need a help on this without minimize and maximize the screen.

    Hi
    I am sending my code snippet, please look into this......i am doing the same even though i am not able to..................can u suggest anything seeing this code snippet.
    here one function called createtabpane (It creates the JTabbedpanes with the table information at runtime).
    private void getTimeSheetObj(String weekDate){
    //Object[][] rowObj=null;
    try {
    System.out.println("Inside the gettimesheet method try block");
    if(projTables!=null){
    for(int i=projTables.length-1; i>=0; i--){
    JTable jt = projTables;
    jTabbedPane_Main.remove(jt);
    System.out.println("Removing Table:"+i);
    jPanel_Tabbedpane.remove(jTabbedPane_Main);
    jTabbedPane_Main = new JTabbedPane();
    jTabbedPane_Main.revalidate();
    jPanel_Tabbedpane.revalidate();
    getContentPane().validate();
    getContentPane().repaint();
    jTabbedPane_Main.addChangeListener(new ChangeListener(){
    public void stateChanged(ChangeEvent ce){
    getTabbedPaneListenerValues();
    // this.setState(JFrame.ICONIFIED);
    // this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    res = GetTimesheetResponseDocument.Factory.parse(new File("C:\\Narayana.xml"));
    response = res.getGetTimesheetResponse();
    proDets=response.getProjectDetailsArray();
    numOfPro = proDets.length;
    String taskDayValues[] = new String[8];
    System.out.println(numOfPro);
    proArr=new Object[numOfPro];
    Object[][] taskValues=null;
    for(int p = 0;p<numOfPro;p++){
    System.out.println("Inside1");
    taskDet = proDets[p].getTaskDetailsArray();
    taskValues = new Object[taskDet.length][8];
    for(int t=0;t<taskDet.length;t++){
    System.out.println("Inside2");
    taskValues[t][0] = (taskDet[t].getTaskName());
    taskValues[t][1] = (taskDet[t].getDay1HH()+":"+taskDet[t].getDay1MM()).toString();
    taskValues[t][2] = (taskDet[t].getDay2HH()+":"+taskDet[t].getDay2MM()).toString();
    taskValues[t][3] = (taskDet[t].getDay3HH()+":"+taskDet[t].getDay3MM()).toString();
    taskValues[t][4] = (taskDet[t].getDay4HH()+":"+taskDet[t].getDay4MM()).toString();
    taskValues[t][5] = (taskDet[t].getDay5HH()+":"+taskDet[t].getDay5MM()).toString();
    taskValues[t][6] = (taskDet[t].getDay6HH()+":"+taskDet[t].getDay6MM()).toString();
    taskValues[t][7] = (taskDet[t].getDay7HH()+":"+taskDet[t].getDay7MM()).toString();
    System.out.println("After taskvalues");
    proArr[p]=taskValues;
    createTabPanes(jTabbedPane_Main, proArr);
    System.out.println("outside");
    jPanel_Tabbedpane.add(jTabbedPane_Main);
    jTabbedPane_Main.getAccessibleContext().setAccessibleName("Proj");
    getContentPane().add(jPanel_Tabbedpane);
    pack();
    }catch(XmlException xe) {
    System.out.println("Inside the XmlException block");
    System.out.println(""+xe.getMessage());
    } catch(IOException ioe) {
    System.out.println("Inside the IOException block");
    System.out.println(""+ioe.getMessage());
    /* JOptionPane.showMessageDialog(null,
    "Values Displayed in the below tables",
    "Alert!",JOptionPane.ERROR_MESSAGE); */
    System.out.println("Initial JFrame Bounds:"+this.getBounds());

  • HT203128 iTunes 12.1.050 - Rollback: Updated from 12.01, now I cant't change track numbers and add additional data fields. How can I roll back to the previous version? @Apple, I want a $100 gift card for the inconvenience.

    iTunes 12.1.050 - Rollback: Updated from 12.01, now I cant't change track numbers and add additional data fields. How can I roll back to the previous version? @Apple, I want a $100 gift card for the inconvenience.
    - it's all said in the title. I can't understand why the developers turn things bad ... risking loosing Apples valuable customers.
    More examples needed? (check out the communities and the reviews)
    - OSX: Maverick to Yosemite = not recommended (check it out > http://roaringapps.com/apps)
    - iPad: older versions as iPad2 should not upgrade to iOS7/8 (it's not supporting its hardware accordingly, it's designed for the latest hardware)
    - iTunes (it's possible to rollback to 10.7 - 11.4, but you need to breech OSX system security framework)
    - Pages (was a real alternative for many of us, each update reduced features and created incompatibility to older work files)
    The list could easily extend to ...

    You can offer Apple feedback here: http://www.apple.com/feedback/
    as for "
      "@Apple, I want a $100 gift card for the inconvenience"
    dream on.

  • How do I find out who is attached to my sharing of my account and remove and add someone? Is 5 devices the limit?

    Devices sharing is 5?
    Where do I go to remove and add a devic

    Hey 1980justme!
    I have an article for you that can help you address this question:
    iTunes Store: Authorize or deauthorize your Mac or PC
    http://support.apple.com/kb/ht1420
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • How are attribute and text master data tables linked in SAP R/3?

    Hello,
    how are attribute and text master data tables linked in SAP R/3?
    Most tables with attribute master data like T001 for company codes,
    have a text master data table T001T (add "T" to table name).
    When looking at the content of table T001 via transaction se11,
    the text are automatically joined.
    But for some tables there is no "T"-table (e.g. table TVBUR for sales offices
    has no text table TVBURT), but in se11 you get texts. There is an address
    link in TVBUR, but the Name1, etc. are empty.
    a) Where are the text stored?
    b) How does the system know of the link?
    Hope someone can help!
    Best regards
    Thomas

    Hi Thomas
    The master and text table are not linked by name, of course, if you see the text table, it has the same key fields of master table, only it has the field key spras and the field for description.
    The link beetween the tables is done by foreign key: if you check the text table TVKBT u need to see how the foreign key for field VKBUR is done:
    -> Foreing key with table TVBUR
    -> Foreing key field type -> KEY FIELD FOR A TEXT TABLE
    ->Cardinality-> 1-:CN
    It's very important the attribute sets for Foreing key field type, if it's KEY FIELD FOR A TEXT TABLE, it'll mean the table is a text table: i.e. that mean the master table is a check table for the text table, where the foreign key type is for text table.
    U can find out the text table of master table by SE11: GoTo->Text Table
    U can fined some information in table DD08L.
    Max

  • Java mapping for Remove and Add of  DOCTYPE Tag

    HI All,
    i have one issue while the Java mapping for Remove and Add of  DOCTYPE Tag   in Operation Mapping .
    it says that , while am testing in Configuration Test "  Problem while determining receivers using interface mapping: Error while determining root tag of XML"
    Receiver Determination...
    error in SXMB MOni
    " SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="RCVR_DETERMINATION">CX_RD_PLSRV</SAP:Code>
      <SAP:P1>Problem while determining receivers using interface mapping: Error while determining root tag of XML: '<!--' or '<![CDATA[' expected</SAP:P1>
    plz provide solutions
    Thanks in advance.

    Hi Mahesh,
    I understand, you are using extended Receiver Determination using Operational Mapping (which has Java Mapping). And, there is an error message u201CError while determining root tag of XMLu201D, when you are doing configuration test.
    Can you please test, the Operational Mapping (which has Java Mapping) separately in ESR, with payload which is coming now. It should produce a XML something like this [Link1|http://help.sap.com/saphelp_nwpi711/helpdata/en/48/ce53aea0d7154ee10000000a421937/frameset.htm]
    <Receivers>
    <Receiver>
      <Party agency="016" scheme="DUNS">123456789</Party>
      <Service>MyService</Service>
    </Receiver>
    <Receiver>
      <Party agency="http://sap.com/xi/XI" scheme="XIParty"></Party>
      <Service>ABC_200</Service>
    </Receiver>
    </Receivers>
    If it is not (I Think it will not), then there is some problem in Java Mapping coding. Please correct it. Last option, if your Java code is small in length; you may paste it here, so that we can have a look at the cause of issue.
    Regards,
    Raghu_Vamsee

  • How to read and write a data from extrenal file

    Hi..
    How to read and write a data from extrenal file using Pl/sql?
    Is it possible from Dyanamic Sql or any other way?
    Reagards
    Raju

    utl_file
    Re: How to Create text(dat) file.
    Message was edited by:
    jeneesh

  • How to Read and Write .XML datas   (HELP Plz...)

    hai everybody
    how to read and write xml datas... plz give clean and simple example..
    bcoz me want to produce such type of module...
    if any one help me .. thats the only way me laid in software ladder
    plz....
    thank u in advance

    thank u for giving idiot..
    but before posting i search in google also..
    but i cant get what me expect..
    thus i posted...
    then who is ................?
    sorry javacoder01
    // plz help me
    Message was edited by:
    drvijayy2k2

  • How to create and add table type to a DDIC Structure in sap 3.1H

    How to create and add table type to a DDIC Structure in sap 3.1H

    How to create and add table type to a DDIC Structure in sap 3.1H

  • How to remove and replace keyboard on HP Touchsmart Notebook 15-D020NR

    I spilled a drink on my keyboard and now I cannot get the Caps Lock to turn off and a number of keys do not work. I need the instructions on how to remove and replace this no frame keyboard. Thank you.    

    On your Support page- look for Maintenance and Service Guide under Manuals. http://support.hp.com/us-en/product/HP-15-d000-TouchSmart-Notebook-PC-series/6627588/model/6761859/manuals

  • How to remove and change the color of Java cup and border

    Hi to all,
    How to remove and change the color of Java cup and border.
    Thanks in advance
    khiz_eng

    This is just an Image. You would need to create your own image and call setIconImage(Image) on your JFrame.

  • How to modify and save the data in the table control

    how to modify and save the data in the table control

    hi priya,
    kindly go thru the code below.
    PROCESS BEFORE OUTPUT.
      MODULE status_9010.
      LOOP WITH CONTROL tab_control.
        MODULE move_data_to_table.
      ENDLOOP.
    PROCESS AFTER INPUT.
      MODULE user_cancel AT EXIT-COMMAND.
      LOOP WITH CONTROL tab_control.
        MODULE move_data_from_table.
      ENDLOOP.
    MODULE move_data_to_table OUTPUT.
    This is to move the data from the internal table to *the table control
    *zmpets_mode-modecode, zmpets_range-rangeid, *zmpets_servfacto-factor are field names of the table *control columns.
      READ TABLE int_factor INDEX tab_control-current_line.
      IF sy-subrc = 0.
        zmpets_mode-modecode = int_factor-modecode.
        zmpets_range-rangeid = int_factor-rangeid.
        zmpets_servfacto-factor = int_factor-factor.
      ENDIF.
    ENDMODULE.                 " move_data_to_table  OUTPUT
    **********************************************8888
    MODULE move_data_from_table INPUT.
    *To move the data from the table control to internal *table 'INT_FACTOR'.
      int_factor-chk = line.
      int_factor-modecode = zmpets_mode-modecode.
      int_factor-rangeid = zmpets_range-rangeid.
      int_factor-factor = zmpets_servfacto-factor.
       MODIFY int_factor INDEX tab_control-current_line.
        IF sy-subrc NE 0.
          APPEND int_factor.
          CLEAR int_factor.
        ENDIF.
    ENDMODULE.                 " move_data_from_table  INPUT
    if this helps , kindly award points.
    for any clarification just mail me.
    regards,
    Anversha.S
    [email protected]

  • How to store and retrieve blob data type in/from oracle database using JSP

    how to store and retrieve blob data type in/from oracle database using JSP and not using servlet
    thanks

    JSP? Why?
    start here: [http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html]

  • Satellite A30-921: How to remove and replace the memory?

    hi, can anyone help me how to remove and replace the memory of sat A30-921. and also, please give a detailed instruction.
    thank you in advance.

    Hi
    There is no much to explain. At the bottom side in the middle there is placed memory cover (fixed with two screws). Remove the cover and you will see 2 slots there. I dont know how much memory has you there but as Stefan said you can use max 2 GB of RAM (2x PC2700 1024MB - PA3313U-1M1G). How to remove memory modules you can see on http://www.hardwaresecrets.com/article/189/5
    Bye

  • I want to change my apple id primary e-mail from a .msn address to a .gmail address. The problem is that currently my .gmail address is my cover address and I cannot figure out how to remove and replace my gmail recovery address.

    I want to change my apple id primary e-mail from a .msn address to a .gmail address. The problem is that currently my .gmail address is my recovery address; I cannot figure out how to remove and replace my gmail recovery address with a new e-mail address.  I want to do this because I no longer use my .msn address.

    You should be able to change your rescue address by going to My Apple ID, signing in to manage your ID, then selecting the the Password and Security section, and answering the two security questions.  If you have trouble with this, contact the Apple account security team for your country to verify your identity and ask for assistance: Apple ID: Contacting Apple for help with Apple ID account security.  If your country isn't listed, contact iTunes store support by filling out this form: https://www.apple.com/emea/support/itunes/contact.html.

Maybe you are looking for