Drag Functionality

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

Drag Functionality

Post by swappyk » Mon Oct 03, 2016 5:54 pm

Hi,

I know TeeChart allows DragPoint functionality where we can move points, was wondering if we have functionality to move the entire series if a point is dragged, adjust the other data points once a data point is moved.

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

Re: Drag Functionality

Post by Yeray » Tue Oct 04, 2016 8:25 am

Hello,

You could do this manually using events instead of using the DragPoint tool. Ie:

Code: Select all

	private static void dragTest() {
		tChart1.getHeader().setVisible(false);
		tChart1.getAspect().setView3D(false);

		tChart1.getZoom().setAllow(false);

		Points points1 = new Points(tChart1.getChart());
		points1.fillSampleValues(10);

		tChart1.getAxes().getBottom().setMinMax(points1.getMinXValue(), points1.getMaxXValue());
		tChart1.getAxes().getLeft().setMinMax(points1.getMinYValue(), points1.getMaxYValue());

		tChart1.addMouseMotionListener(new MouseMotionAdapter() {

			@Override
			public void mouseMoved(MouseEvent e) {
				if (draggingSeries != null)
					tChart1.setCursor(Cursor.HAND);
				else {
					int tmpIndex = -1;

					for (int t = 0; t < tChart1.getSeriesCount(); t++) {
						Series s = tChart1.getSeries(t);
						if (s.getActive()) {
							tmpIndex = s.clicked(e.getX(), e.getY());
						}
					}

					if (tmpIndex > -1)
						tChart1.setCursor(Cursor.HAND);
					else
						tChart1.setCursor(Cursor.DEFAULT);
				}
			}

			@Override
			public void mouseDragged(MouseEvent e) {

				if ((draggingSeries != null) && (draggingIndex != -1)) {
					double diffX = draggingSeries.getHorizAxis().calcPosPoint(e.getX())
							- draggingSeries.getHorizAxis().calcPosPoint(OldXPos);
					double diffY = draggingSeries.getVertAxis().calcPosPoint(e.getY())
							- draggingSeries.getVertAxis().calcPosPoint(OldYPos);

					for (int i = 0; i < draggingSeries.getCount(); i++) {
						draggingSeries.getXValues().setValue(i, draggingSeries.getXValues().getValue(i) + diffX);
						draggingSeries.getYValues().setValue(i, draggingSeries.getYValues().getValue(i) + diffY);
					}

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

				tChart1.refreshControl();
			}
		});

		tChart1.addMouseListener(new MouseAdapter() {

			@Override
			public void mousePressed(MouseEvent e) {
				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;

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

							break;
						}
					}
				}
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				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

Post Reply