DragPoint Events in Java

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
swappyk
Newbie
Newbie
Posts: 6
Joined: Mon Aug 01, 2016 12:00 am
Contact:

DragPoint Events in Java

Post by swappyk » Fri Sep 02, 2016 1:27 pm

Hi,

I am implementing a Dragpoint event for my chart in Java, and now I want to capture the values after the drag point event is done and save them to DB. I see the legend is being updated with the values but I am not able to capture the values. Can you suggest a way to capture the data after the Drag is complete

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: DragPoint Events in Java

Post by Yeray » Mon Sep 05, 2016 9:34 am

Hello,

You can use events as in the following SWT example:

Code: Select all

    static int draggingIndex = -1;
    static Series draggingSeries = null;
    static Point mousePos = null;
    
	private static void dragTest() {
		tChart1.getHeader().setVisible(false);
        tChart1.getAspect().setView3D(false);
        //tChart1.getLegend().setVisible(false);
        
        tChart1.getZoom().setActive(false);
        
        Points points1 = new Points(tChart1.getChart());
        points1.fillSampleValues(10);
        
        DragPoint dragPoints1 = new DragPoint(tChart1.getChart());
        
        tChart1.addMouseMoveListener(new MouseMoveListener() {
			
			@Override
			public void mouseMove(MouseEvent arg0) {
				mousePos = new Point(arg0.x, arg0.y);
			}
		});
        
        dragPoints1.addDragListener(new DragListener() {
			
			@Override
			public void dragMoving(ChangeEvent e) {
				if (draggingSeries == null) {
					draggingIndex = ((DragPoint)e.getSource()).getDragPoint();
					for (int t = 0; t < tChart1.getSeriesCount(); t++) {
						Series s = tChart1.getSeries(t);
						if (s.getActive()) {
							int clickedIndex = s.clicked(mousePos);
							if ((draggingIndex != -1) && (clickedIndex != -1) && (clickedIndex == draggingIndex)) {
								draggingSeries = s;
								break;
							}
						}
					}
				}
			}
			
			@Override
			public void dragFinished(ChangeEvent e) {
				if ((draggingSeries != null) && (draggingIndex != -1)) {
					System.out.println(draggingSeries.getYValues().getValue(draggingIndex));
				}
				
				draggingSeries = null;
				draggingIndex = -1;
			}
		});
	}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

swappyk
Newbie
Newbie
Posts: 6
Joined: Mon Aug 01, 2016 12:00 am
Contact:

Re: DragPoint Events in Java

Post by swappyk » Wed Sep 07, 2016 1:43 pm

Can we do the same using Swing components. My project is a swing project?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: DragPoint Events in Java

Post by Yeray » Thu Sep 08, 2016 9:48 am

Hello,

It's quite similar in Swing. I've improved the code a bit:

Code: Select all

	static int draggingIndex = -1;
    static Series draggingSeries = null;
    
    private static void dragTest() {
        tChart1.getHeader().setVisible(false);
          tChart1.getAspect().setView3D(false);
          //tChart1.getLegend().setVisible(false);
         
          tChart1.getZoom().setActive(false);
         
          Points points1 = new Points(tChart1.getChart());
          points1.fillSampleValues(10);
         
          DragPoint dragPoints1 = new DragPoint(tChart1.getChart());
         
          tChart1.addMouseListener(new MouseAdapter() {
			
			@Override
			public void mousePressed(MouseEvent e) {
				if (dragPoints1.getSeries() == null) {
	                for (int t = 0; t < tChart1.getSeriesCount(); t++) {
	                    Series s = tChart1.getSeries(t);
	                    if (s.getActive()) {
	                        draggingIndex = s.clicked(e.getX(), e.getY());
	                        if (draggingIndex != -1) {
	                            draggingSeries = s;
	                            break;
	                        }
	                    }
	                }
	            } else {
	                draggingIndex = dragPoints1.getSeries().clicked(e.getX(), e.getY());
	                if (draggingIndex != -1) {
	                    draggingSeries = dragPoints1.getSeries();
	                }
	            }
			}
		
		});
         
          dragPoints1.addDragListener(new DragAdapter() {
           
           @Override
           public void dragFinished(ChangeEvent e) {
              if ((draggingSeries != null) && (draggingIndex != -1)) {
                 System.out.println(draggingSeries.getYValues().getValue(draggingIndex));
              }
              
              draggingSeries = null;
              draggingIndex = -1;
           }
        });
     }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

swappyk
Newbie
Newbie
Posts: 6
Joined: Mon Aug 01, 2016 12:00 am
Contact:

Re: DragPoint Events in Java

Post by swappyk » Wed Oct 05, 2016 10:52 am

I have a chart with multiple Lines, Yet I want to enable just one of the lines as draggable. The other lines have to remain static.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: DragPoint Events in Java

Post by Yeray » Thu Oct 06, 2016 7:47 am

Hello,

Have you tried to do it with the code I posted here?
http://www.teechart.net/support/viewtop ... 396#p72396
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

swappyk
Newbie
Newbie
Posts: 6
Joined: Mon Aug 01, 2016 12:00 am
Contact:

Re: DragPoint Events in Java

Post by swappyk » Mon Oct 10, 2016 3:10 pm

Yes,

In that code I am able to move all the lines, here is what i am talking about.

I have a TChart with 4 lines, however I want to able to move only one of the lines using DragPoint Tool. The other 3 lines should not be moved. I tried to add series to DragPoint class constructor, but I am not able to get the chart to work how i want it to work.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: DragPoint Events in Java

Post by Yeray » Tue Oct 11, 2016 8:51 am

Hello,

Knowing the index of the series you want the dragging to be allowed (ie draggableSeriesIndex), you can change the mousePressed event to fit your needs. Ie:

Code: Select all

         @Override
         public void mousePressed(MouseEvent e) {
             Series s = tChart1.getSeries(draggableSeriesIndex);
             if (s.getActive()) {
                draggingIndex = s.clicked(e.getX(), e.getY());
                if (draggingIndex != -1) {
                   draggingSeries = s;

                   OldXPos = e.getX();
                   OldYPos = e.getY();

                   break;
                }
             }
         }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply